use of com.alipay.sofa.jraft.rhea.util.concurrent.DiscardOldPolicyWithReport in project sofa-jraft by sofastack.
the class HeartbeatSender method init.
@Override
public synchronized boolean init(final HeartbeatOptions opts) {
if (this.started) {
LOG.info("[HeartbeatSender] already started.");
return true;
}
this.statsCollector = new StatsCollector(this.storeEngine);
this.instructionProcessor = new InstructionProcessor(this.storeEngine);
this.heartbeatTimer = new HashedWheelTimer(new NamedThreadFactory("heartbeat-timer", true), 50, TimeUnit.MILLISECONDS, 4096);
this.heartbeatRpcTimeoutMillis = opts.getHeartbeatRpcTimeoutMillis();
if (this.heartbeatRpcTimeoutMillis <= 0) {
throw new IllegalArgumentException("Heartbeat rpc timeout millis must > 0, " + this.heartbeatRpcTimeoutMillis);
}
final String name = "rheakv-heartbeat-callback";
this.heartbeatRpcCallbackExecutor = //
ThreadPoolUtil.newBuilder().poolName(//
name).enableMetric(//
true).coreThreads(//
4).maximumThreads(//
4).keepAliveSeconds(//
120L).workQueue(//
new ArrayBlockingQueue<>(1024)).threadFactory(//
new NamedThreadFactory(name, true)).rejectedHandler(//
new DiscardOldPolicyWithReport(name)).build();
final long storeHeartbeatIntervalSeconds = opts.getStoreHeartbeatIntervalSeconds();
final long regionHeartbeatIntervalSeconds = opts.getRegionHeartbeatIntervalSeconds();
if (storeHeartbeatIntervalSeconds <= 0) {
throw new IllegalArgumentException("Store heartbeat interval seconds must > 0, " + storeHeartbeatIntervalSeconds);
}
if (regionHeartbeatIntervalSeconds <= 0) {
throw new IllegalArgumentException("Region heartbeat interval seconds must > 0, " + regionHeartbeatIntervalSeconds);
}
final long now = System.currentTimeMillis();
final StoreHeartbeatTask storeHeartbeatTask = new StoreHeartbeatTask(storeHeartbeatIntervalSeconds, now, false);
final RegionHeartbeatTask regionHeartbeatTask = new RegionHeartbeatTask(regionHeartbeatIntervalSeconds, now, false);
this.heartbeatTimer.newTimeout(storeHeartbeatTask, storeHeartbeatTask.getNextDelay(), TimeUnit.SECONDS);
this.heartbeatTimer.newTimeout(regionHeartbeatTask, regionHeartbeatTask.getNextDelay(), TimeUnit.SECONDS);
LOG.info("[HeartbeatSender] start successfully, options: {}.", opts);
return this.started = true;
}
Aggregations