Search in sources :

Example 1 with ServerChangeListener

use of com.bonree.brfs.rebalance.task.listener.ServerChangeListener in project BRFS by zhangnianli.

the class TaskDispatcher method start.

public void start() throws Exception {
    LOG.info("begin leaderLath server!");
    leaderLath.start();
    LOG.info("changeMonitorPath:" + changesPath);
    treeCache.addListener(changesPath, new ServerChangeListener(this));
    LOG.info("tasksPath:" + tasksPath);
    treeCache.addListener(tasksPath, new TaskStatusListener(this));
    singleServer.execute(new Runnable() {

        @Override
        public void run() {
            try {
                dealChangeSDetail();
            } catch (InterruptedException e) {
                LOG.error("consumer queue error!!", e);
                e.printStackTrace();
            }
        }
    });
    scheduleExecutor.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            try {
                if (leaderLath.hasLeadership()) {
                    if (isLoad.get()) {
                        LOG.info("auditTask timer cacheSummaryCache:" + cacheSummaryCache);
                        for (Entry<Integer, List<ChangeSummary>> entry : cacheSummaryCache.entrySet()) {
                            StorageRegion sn = snManager.findStorageRegionById(entry.getKey());
                            // 因为sn可能会被删除
                            if (sn != null) {
                                syncAuditTask(entry.getKey(), entry.getValue());
                            }
                        }
                    } else {
                        LOG.info("load once cache!");
                        loadCache();
                        isLoad.set(true);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, 3000, 3000, TimeUnit.MILLISECONDS);
}
Also used : Entry(java.util.Map.Entry) ServerChangeListener(com.bonree.brfs.rebalance.task.listener.ServerChangeListener) TaskStatusListener(com.bonree.brfs.rebalance.task.listener.TaskStatusListener) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) IOException(java.io.IOException)

Aggregations

StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)1 ServerChangeListener (com.bonree.brfs.rebalance.task.listener.ServerChangeListener)1 TaskStatusListener (com.bonree.brfs.rebalance.task.listener.TaskStatusListener)1 IOException (java.io.IOException)1 Entry (java.util.Map.Entry)1