@Override public void startBackup() throws Exception { LOGGER.debug("ENTER startBackup"); try { ActiveMQServerLogger.LOGGER.waitingToBecomeBackup(); lock(scheduledBackupLock.lock()); scheduledBackupLock.start(); ActiveMQServerLogger.LOGGER.gotBackupLock(); if (getUUID() == null) readNodeId(); } finally { LOGGER.debug("EXIT startBackup"); } }
@Override public ActivateCallback startLiveNode() throws Exception { LOGGER.debug("ENTER startLiveNode"); try { setFailingBack(); final String timeoutMessage = lockAcquisitionTimeoutMillis == -1 ? "indefinitely" : lockAcquisitionTimeoutMillis + " milliseconds"; ActiveMQServerLogger.LOGGER.waitingToObtainLiveLock(timeoutMessage); lock(this.scheduledLiveLock.lock()); this.scheduledLiveLock.start(); ActiveMQServerLogger.LOGGER.obtainedLiveLock(); return new ActivateCallback() { @Override public void activationComplete() { LOGGER.debug("ENTER activationComplete"); try { //state can be written only if the live renew task is running setLive(); } catch (Exception e) { ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e); } finally { LOGGER.debug("EXIT activationComplete"); } } }; } finally { LOGGER.debug("EXIT startLiveNode"); } }
/** * Lock live node and check for a live state, taking care to renew it (if needed) or releasing it otherwise */ private boolean lockLiveAndCheckLiveState() throws Exception { lock(this.scheduledLiveLock.lock()); final long acquiredOn = System.nanoTime(); boolean liveWhileLocked = false; //check if the state is live final SharedStateManager.State stateWhileLocked; try { stateWhileLocked = readSharedState(); } catch (Throwable t) { LOGGER.error("error while holding the live node lock and tried to read the shared state", t); this.scheduledLiveLock.lock().release(); throw t; } if (stateWhileLocked == SharedStateManager.State.LIVE) { renewLiveLockIfNeeded(acquiredOn); liveWhileLocked = true; } else { LOGGER.debugf("state is %s while holding the live lock: releasing live lock", stateWhileLocked); //state is not live: can (try to) release the lock this.scheduledLiveLock.lock().release(); } return liveWhileLocked; }