@Override public final SimpleString readNodeId() throws ActiveMQIllegalStateException, IOException { ByteBuffer id = ByteBuffer.allocateDirect(16); int read = channel.read(id, 3); if (read != 16) { throw new ActiveMQIllegalStateException("live server did not write id to file"); } byte[] bytes = new byte[16]; id.position(0); id.get(bytes); setUUID(new UUID(UUID.TYPE_TIME_BASED, bytes)); return getNodeId(); }
logger.debug("awaiting live node..."); do { byte state = getState(); while (state == FileLockNodeManager.NOT_STARTED || state == FIRST_TIME_START) { logger.debug("awaiting live node startup state='" + state + "'"); Thread.sleep(2000); state = getState(); liveLock = lock(FileLockNodeManager.LIVE_LOCK_POS); if (interrupted) { interrupted = false; throw new InterruptedException("Lock was interrupted"); state = getState(); if (state == FileLockNodeManager.PAUSED) { liveLock.release();
FileLockNodeManager fileLock = new FileLockNodeManager(messagesDirectory, false); fileLock.start(); printBanner(out, "Server's ID=" + fileLock.getNodeId().toString()); fileLock.stop(); } catch (Exception e) { e.printStackTrace();
@Override protected NodeManager createNodeManager(final File directory, boolean replicatingBackup) { if (replicatingBackup) { return new FileLockNodeManager(directory, replicatingBackup, getConfiguration().getJournalLockAcquisitionTimeout()); } else { if (backup) { return nodeManagerBackup; } else { return nodeManagerLive; } } }
public void doTestLock(final FileLockNodeManager lockManager1, final FileLockNodeManager lockManager2) throws Exception { lockManager1.start(); lockManager2.start(); lockManager1.startLiveNode(); Thread t = new Thread() { @Override public void run() { try { lockManager2.startLiveNode(); } catch (Exception e) { e.printStackTrace(); } } }; t.start(); assertTrue(lockManager1.isLiveLocked()); Thread.sleep(500); assertFalse(lockManager2.isLiveLocked()); lockManager1.crashLiveServer(); t.join(); assertFalse(lockManager1.isLiveLocked()); assertTrue(lockManager2.isLiveLocked()); lockManager2.crashLiveServer(); lockManager1.stop(); lockManager2.stop(); }
public static void main(String[] args) throws Exception { int[] work1 = new int[args.length]; for (int i = 0; i < args.length; i++) { work1[i] = Integer.parseInt(args[i]); } NodeManagerAction nodeManagerAction = new NodeManagerAction(work1); FileLockNodeManager nodeManager = new FileLockNodeManager(new File("."), false); nodeManager.start(); try { nodeManagerAction.performWork(nodeManager); } catch (Exception e) { e.printStackTrace(); System.exit(9); } System.out.println("work performed"); }
@Override public boolean isAwaitingFailback() throws Exception { return getState() == FileLockNodeManager.FAILINGBACK; }
FileLockNodeManager fileLock = new FileLockNodeManager(messagesDirectory, false); fileLock.start(); printBanner(out, "Server's ID=" + fileLock.getNodeId().toString()); fileLock.stop(); } catch (Exception e) { e.printStackTrace();
@Test public void testNIOLock() throws Exception { doTestLock(new FileLockNodeManager(getTestDirfile(), false), new FileLockNodeManager(getTestDirfile(), false)); }
@Override public void awaitLiveStatus() throws Exception { while (getState() != LIVE) { Thread.sleep(2000); } }
protected NodeManager createNodeManager(final File directory, boolean replicatingBackup) { NodeManager manager; if (!configuration.isPersistenceEnabled()) { manager = new InVMNodeManager(replicatingBackup); } else if (configuration.getStoreConfiguration() != null && configuration.getStoreConfiguration().getStoreType() == StoreConfiguration.StoreType.DATABASE) { final HAPolicyConfiguration.TYPE haType = configuration.getHAPolicyConfiguration() == null ? null : configuration.getHAPolicyConfiguration().getType(); if (haType == HAPolicyConfiguration.TYPE.SHARED_STORE_MASTER || haType == HAPolicyConfiguration.TYPE.SHARED_STORE_SLAVE) { if (replicatingBackup) { throw new IllegalArgumentException("replicatingBackup is not supported yet while using JDBC persistence"); } final DatabaseStorageConfiguration dbConf = (DatabaseStorageConfiguration) configuration.getStoreConfiguration(); manager = JdbcNodeManager.with(dbConf, scheduledPool, executorFactory, shutdownOnCriticalIO); } else if (haType == null || haType == HAPolicyConfiguration.TYPE.LIVE_ONLY) { if (logger.isDebugEnabled()) { logger.debug("Detected no Shared Store HA options on JDBC store"); } //LIVE_ONLY should be the default HA option when HA isn't configured manager = new FileLockNodeManager(directory, replicatingBackup, configuration.getJournalLockAcquisitionTimeout()); } else { throw new IllegalArgumentException("JDBC persistence allows only Shared Store HA options"); } } else { manager = new FileLockNodeManager(directory, replicatingBackup, configuration.getJournalLockAcquisitionTimeout()); } return manager; }
@Test public void testId() throws Exception { NodeManager nodeManager = new FileLockNodeManager(new File(getTemporaryDir()), false); nodeManager.start(); UUID id1 = nodeManager.getUUID(); nodeManager.stop(); nodeManager.start(); ActiveMQTestBase.assertEqualsByteArrays(id1.asBytes(), nodeManager.getUUID().asBytes()); nodeManager.stop(); }