This commit is contained in:
crusader
2018-04-23 19:37:40 +09:00
commit 82719958f9
10 changed files with 406 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
package com.loafle.overflow.container;
/**
* Container
*/
public class Container {
public static final String CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS";
}

View File

@@ -0,0 +1,76 @@
package com.loafle.overflow.container.service;
import java.util.Map;
import javax.annotation.Resource;
import com.loafle.overflow.container.Container;
import com.loafle.overflow.crawler.Crawler;
import com.loafle.overflow.module.core.exception.OverflowException;
import com.loafle.overflow.module.core.interfaces.Service;
import com.loafle.overflow.module.sensorconfig.model.SensorConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
* CrawlerService
*/
@org.springframework.stereotype.Service("CrawlerService")
public class CrawlerService implements Service {
private static final Logger logger = LoggerFactory.getLogger(CrawlerService.class);
@Autowired
private SensorConfigService sensorConfigService;
@Resource(name=Container.CONTAINER_CRAWLERS)
private Map<String, Crawler> crawlers;
@Override
public void initService() throws Exception {
if (null == this.crawlers) {
throw new Exception("Crawlers is not set");
}
}
@Override
public void startService() throws Exception {
}
@Override
public void stopService() {
}
@Override
public void destroyService() {
}
public void Auth(String crawlerName, Map<String, Object> authInfoMap) throws OverflowException {
Crawler crawler = this.crawlers.get(crawlerName);
if (null == crawler) {
throw new OverflowException(String.format("There is no crawler[%s]", crawlerName), null);
}
crawler.auth(authInfoMap);
}
public Map<String, String> Get(String sensorConfigID) throws OverflowException {
SensorConfig sensorConfig = this.sensorConfigService.getSensorConfig(sensorConfigID);
if (null == sensorConfig) {
throw new OverflowException(String.format("There is no sensor config for id[%s]", sensorConfigID), null);
}
String crawlerName = sensorConfig.getCrawler().getName();
Crawler crawler = this.crawlers.get(crawlerName);
if (null == crawler) {
throw new OverflowException(String.format("There is no crawler[%s] for id[%s]", crawlerName, sensorConfigID), null);
}
return crawler.get(sensorConfig);
}
}

View File

@@ -0,0 +1,35 @@
package com.loafle.overflow.container.service;
import com.loafle.overflow.module.core.exception.OverflowException;
import com.loafle.overflow.module.core.interfaces.Service;
/**
* ProbeService
*/
@org.springframework.stereotype.Service("ProbeService")
public class ProbeService implements Service {
@Override
public void initService() throws Exception {
}
@Override
public void startService() throws Exception {
}
@Override
public void stopService() {
}
@Override
public void destroyService() {
}
public void send(String method, Object... params) throws OverflowException {
}
}

View File

@@ -0,0 +1,98 @@
package com.loafle.overflow.container.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.loafle.overflow.module.core.exception.OverflowException;
import com.loafle.overflow.module.core.interfaces.Service;
import com.loafle.overflow.module.sensorconfig.model.SensorConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* SensorConfigService
*/
@org.springframework.stereotype.Service("SensorConfigService")
public class SensorConfigService implements Service {
private static final Logger logger = LoggerFactory.getLogger(SensorConfigService.class);
private Map<String, SensorConfig> sensorConfigs;
@Override
public void initService() throws Exception {
this.sensorConfigs = new HashMap<>();
}
@Override
public void startService() throws Exception {
}
@Override
public void stopService() {
}
@Override
public void destroyService() {
}
SensorConfig getSensorConfig(String configID) {
return this.sensorConfigs.get(configID);
}
public void InitConfig(List<SensorConfig> sensorConfigs) throws OverflowException {
if (null == sensorConfigs || 0 == sensorConfigs.size()) {
return;
}
for (SensorConfig sensorConfig : sensorConfigs) {
this.sensorConfigs.put(sensorConfig.getConfigID(), sensorConfig);
}
logger.debug("Sensor configs[%d] were added", sensorConfigs.size());
}
public void AddConfig(SensorConfig sensorConfig) throws OverflowException {
if (null == sensorConfig) {
throw new OverflowException("Sensor config is not valid", null);
}
String configID = sensorConfig.getConfigID();
if (this.sensorConfigs.containsKey(configID)) {
throw new OverflowException(String.format("Sensor config[%s] is exist already", configID), null);
}
this.sensorConfigs.put(configID, sensorConfig);
logger.debug("Sensor config[%s] was added", configID);
}
public void UddConfig(SensorConfig sensorConfig) throws OverflowException {
if (null == sensorConfig) {
throw new OverflowException("Sensor config is not valid", null);
}
String configID = sensorConfig.getConfigID();
if (!this.sensorConfigs.containsKey(configID)) {
throw new OverflowException(String.format("Sensor config[%s] is not exist", configID), null);
}
this.sensorConfigs.remove(configID);
this.sensorConfigs.put(configID, sensorConfig);
logger.debug("Sensor config[%s] was updated", configID);
}
public void RddConfig(String configID) throws OverflowException {
if (!this.sensorConfigs.containsKey(configID)) {
throw new OverflowException(String.format("Sensor config[%s] is not exist", configID), null);
}
this.sensorConfigs.remove(configID);
logger.debug("Sensor config[%s] was removed", configID);
}
}

0
src/main/resources/_ Normal file
View File