public synchronized void start() { if (isRun) { return; } if (null == scheduledExecutor || scheduledExecutor.isTerminated()) { scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); } localConfigInfoProcessor.start(this.diamondConfigure.getFilePath() + "/" + DATA_DIR); serverAddressProcessor = new ServerAddressProcessor(this.diamondConfigure, this.scheduledExecutor); serverAddressProcessor.start(); this.snapshotConfigInfoProcessor = new SnapshotConfigInfoProcessor(this.diamondConfigure.getFilePath() + "/" + SNAPSHOT_DIR); randomDomainNamePos(); initHttpClient(); isRun = true; if (log.isInfoEnabled()) { log.info("Current using domains:" + this.diamondConfigure.getDomainNameList()); } if (MockServer.isTestMode()) { bFirstCheck = false; } else { this.diamondConfigure.setPollingIntervalTime(Constants.POLLING_INTERVAL_TIME); } rotateCheckConfigInfo(); addShutdownHook(); }
public synchronized void close() { if (!isRun) { return; } log.warn("Close DiamondSubscriber begin."); localConfigInfoProcessor.stop(); serverAddressProcessor.stop(); isRun = false; // because of rotateCheckConfigInfo recursive call, so must use shutdownNow, shutdown can't do // close scheduledExecutor.shutdownNow(); cache.clear(); log.warn("Close DiamondSubscriber end."); }