private SharedStateManager.State readSharedState() { final SharedStateManager.State state = this.sharedStateManager.readState(); LOGGER.debugf("readSharedState state = %s", state); return state; }
private void writeSharedState(SharedStateManager.State state) { LOGGER.debugf("writeSharedState state = %s", state); this.sharedStateManager.writeState(state); }
private JdbcNodeManager(Supplier<? extends SharedStateManager> sharedStateManagerFactory, long lockRenewPeriodMillis, long lockAcquisitionTimeoutMillis, ScheduledExecutorService scheduledExecutorService, ExecutorFactory executorFactory, IOCriticalErrorListener ioCriticalErrorListener) { super(false, null); this.lockAcquisitionTimeoutMillis = lockAcquisitionTimeoutMillis; this.pauser = LeaseLock.Pauser.sleep(Math.min(lockRenewPeriodMillis, MAX_PAUSE_MILLIS), TimeUnit.MILLISECONDS); this.sharedStateManagerFactory = sharedStateManagerFactory; this.scheduledLiveLockFactory = () -> ScheduledLeaseLock.of( scheduledExecutorService, executorFactory != null ? executorFactory.getExecutor() : null, "live", this.sharedStateManager.liveLock(), lockRenewPeriodMillis, ioCriticalErrorListener); this.scheduledBackupLockFactory = () -> ScheduledLeaseLock.of( scheduledExecutorService, executorFactory != null ? executorFactory.getExecutor() : null, "backup", this.sharedStateManager.backupLock(), lockRenewPeriodMillis, ioCriticalErrorListener); this.ioCriticalErrorListener = ioCriticalErrorListener; this.sharedStateManager = null; this.scheduledLiveLock = null; this.scheduledBackupLock = null; }
@Override public SimpleString readNodeId() { final UUID nodeId = this.sharedStateManager.readNodeId(); LOGGER.debugf("readNodeId nodeId = %s", nodeId); setUUID(nodeId); return getNodeId(); }
@Override public void start() throws Exception { try { synchronized (this) { if (isStarted()) { return; } this.sharedStateManager = sharedStateManagerFactory.get(); LOGGER.debug("setup sharedStateManager on start"); final UUID nodeId = sharedStateManager.setup(UUIDGenerator.getInstance()::generateUUID); setUUID(nodeId); this.scheduledLiveLock = scheduledLiveLockFactory.get(); this.scheduledBackupLock = scheduledBackupLockFactory.get(); super.start(); } } catch (IllegalStateException e) { this.sharedStateManager = null; this.scheduledLiveLock = null; this.scheduledBackupLock = null; if (this.ioCriticalErrorListener != null) { this.ioCriticalErrorListener.onIOException(e, "Failed to setup the JdbcNodeManager", null); } throw e; } }
@Override public synchronized void stop() throws Exception { if (isStarted()) { try { this.scheduledLiveLock.stop(); this.scheduledBackupLock.stop(); } finally { super.stop(); this.sharedStateManager.close(); this.sharedStateManager = null; this.scheduledLiveLock = null; this.scheduledBackupLock = null; } } }