in alpha/alpha-spec-saga-db/src/main/java/org/apache/servicecomb/pack/alpha/spec/saga/db/cluster/ClusterLockService.java [98:132]
public void init() {
eventBus.register(this);
/**
* Try to lock every second
* TODO We need to check if the master check interval time check is OK
* */
masterCheckTimer = new Timer("masterCheckTimer");
masterCheckTimer.schedule(new TimerTask(){
@Override
public void run() {
if (applicationReady && portReady) {
locker = lockProvider.lock(getMasterLock());
if (locker.isPresent()) {
if (!locked) {
locked = true;
nodeStatus.setTypeEnum(NodeStatus.TypeEnum.MASTER);
LOG.info("Master Node");
}
//Keep locked
} else {
if (locked || !lockExecuted) {
locked = false;
nodeStatus.setTypeEnum(NodeStatus.TypeEnum.SLAVE);
LOG.info("Slave Node");
}
}
lockExecuted = true;
}
}
},0, 1000);
LOG.info("Initialize cluster mode");
}