private byte getState() throws Exception { byte result; logger.debug("getting state..."); ByteBuffer bb = ByteBuffer.allocateDirect(1); int read; FileLock lock = null; try { lock = lock(STATE_LOCK_POS); read = channel.read(bb, 0); if (read <= 0) { result = FileLockNodeManager.NOT_STARTED; } else { result = bb.get(0); } } finally { if (lock != null) { lock.release(); } } logger.debug("state: " + result); return result; }
/** * @param status * @throws IOException */ private void writeFileLockStatus(byte status) throws Exception { if (replicatedBackup && channel == null) return; logger.debug("writing status: " + status); ByteBuffer bb = ByteBuffer.allocateDirect(1); bb.put(status); bb.position(0); if (!channel.isOpen()) { setUpServerLockFile(); } FileLock lock = null; try { lock = lock(STATE_LOCK_POS); channel.write(bb, 0); channel.force(true); } finally { if (lock != null) { lock.release(); } } }
liveLock = lock(FileLockNodeManager.LIVE_LOCK_POS); if (interrupted) { interrupted = false;
@Override public ActivateCallback startLiveNode() throws Exception { setFailingBack(); String timeoutMessage = lockAcquisitionTimeout == -1 ? "indefinitely" : lockAcquisitionTimeout + " milliseconds"; ActiveMQServerLogger.LOGGER.waitingToObtainLiveLock(timeoutMessage); liveLock = lock(FileLockNodeManager.LIVE_LOCK_POS); ActiveMQServerLogger.LOGGER.obtainedLiveLock(); return new ActivateCallback() { @Override public void activationComplete() { try { setLive(); } catch (Exception e) { ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e); } } }; }
@Override public void startBackup() throws Exception { assert !replicatedBackup; // should not be called if this is a replicating backup ActiveMQServerLogger.LOGGER.waitingToBecomeBackup(); backupLock = lock(FileLockNodeManager.BACKUP_LOCK_POS); ActiveMQServerLogger.LOGGER.gotBackupLock(); if (getUUID() == null) readNodeId(); }