Search in sources :

Example 1 with HeartBeatServerLifeKeeper

use of com.creditease.agent.feature.hbagent.HeartBeatServerLifeKeeper 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");
    }
}
Also used : HeartBeatServerListenWorker(com.creditease.agent.feature.hbagent.HeartBeatServerListenWorker) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Random(java.util.Random) CacheManager(com.creditease.uav.cache.api.CacheManager) HeartBeatQueryListenWorker(com.creditease.agent.feature.hbagent.HeartBeatQueryListenWorker) HeartBeatServerLifeKeeper(com.creditease.agent.feature.hbagent.HeartBeatServerLifeKeeper) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

HeartBeatQueryListenWorker (com.creditease.agent.feature.hbagent.HeartBeatQueryListenWorker)1 HeartBeatServerLifeKeeper (com.creditease.agent.feature.hbagent.HeartBeatServerLifeKeeper)1 HeartBeatServerListenWorker (com.creditease.agent.feature.hbagent.HeartBeatServerListenWorker)1 CacheManager (com.creditease.uav.cache.api.CacheManager)1 Random (java.util.Random)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1