use of com.creditease.agent.feature.hbagent.HeartBeatServerListenWorker in project uavstack by uavorg.
the class HeartBeatServerAgent method start.
@Override
public void start() {
// init cache manager
String cacheServerAddress = this.getConfigManager().getFeatureConfiguration(this.feature, "store.addr");
int minConcurrent = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.min"));
int maxConcurrent = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.max"));
int queueSize = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.bqsize"));
String password = this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.pwd");
CacheManager cm = CacheManagerFactory.build(cacheServerAddress, minConcurrent, maxConcurrent, queueSize, password);
this.getConfigManager().registerComponent(this.feature, "HBCacheManager", cm);
// start HeartBeatServerListenWorker
hbServerListenWorker = new HeartBeatServerListenWorker("HeartBeatServerListenWorker", this.feature, "hbhandlers");
int port = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.port"));
int backlog = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.backlog"));
int core = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.core"));
int max = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.max"));
int bqsize = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.bqsize"));
@SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
hbServerListenWorker.start(exe, port, backlog);
if (log.isTraceEnable()) {
log.info(this, "HeartBeatServerListenWorker started");
}
// start HeartBeatQueryListenWorker
hbqueryListenWorker = new HeartBeatQueryListenWorker("HeartBeatQueryListenWorker", this.feature, "hbqueryhandlers");
int qport = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.qport"));
@SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor qexe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
hbqueryListenWorker.start(qexe, qport, backlog);
if (log.isTraceEnable()) {
log.info(this, "HeartBeatQueryListenWorker started");
}
// start HeartBeatServerLifeKeeper
boolean isStartLifeKeeper = Boolean.parseBoolean(this.getConfigManager().getFeatureConfiguration(this.feature, "lifekeeper.enable"));
if (!isStartLifeKeeper) {
return;
}
HeartBeatServerLifeKeeper hbserverLifeKeepWorker = new HeartBeatServerLifeKeeper("HeartBeatServerLifeKeeper", this.feature);
long interval = Long.parseLong(this.getConfigManager().getFeatureConfiguration(this.feature, "lifekeeper.interval"));
long randomDely = new Random().nextInt(3) + 3;
this.getTimerWorkManager().scheduleWorkInPeriod("HeartBeatServerLifeKeeper", hbserverLifeKeepWorker, randomDely * 1000, interval);
if (log.isTraceEnable()) {
log.info(this, "HeartBeatServerLifeKeeper started");
}
}
Aggregations