org.apache.activemq.artemis.core.server.cluster.ClusterManager

Here are the examples of the java api class org.apache.activemq.artemis.core.server.cluster.ClusterManager taken from open source projects.

1. ActiveMQTestBase#crashAndWaitForFailure()

View license
public static void crashAndWaitForFailure(ActiveMQServer server, ClientSession... sessions) throws Exception {
    CountDownLatch latch = new CountDownLatch(sessions.length);
    for (ClientSession session : sessions) {
        CountDownSessionFailureListener listener = new CountDownSessionFailureListener(latch, session);
        session.addFailureListener(listener);
    }
    ClusterManager clusterManager = server.getClusterManager();
    clusterManager.flushExecutor();
    clusterManager.clear();
    Assert.assertTrue("server should be running!", server.isStarted());
    server.stop(true);
    if (sessions.length > 0) {
        // Wait to be informed of failure
        boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
        Assert.assertTrue("Failed to stop the server! Latch count is " + latch.getCount() + " out of " + sessions.length, ok);
    }
}

2. SameProcessActiveMQServer#crash()

View license
@Override
public CountDownLatch crash(boolean waitFailure, ClientSession... sessions) throws Exception {
    CountDownLatch latch = new CountDownLatch(sessions.length);
    CountDownSessionFailureListener[] listeners = new CountDownSessionFailureListener[sessions.length];
    for (int i = 0; i < sessions.length; i++) {
        listeners[i] = new CountDownSessionFailureListener(latch, sessions[i]);
        sessions[i].addFailureListener(listeners[i]);
    }
    ClusterManager clusterManager = server.getClusterManager();
    clusterManager.flushExecutor();
    clusterManager.clear();
    Assert.assertTrue("server should be running!", server.isStarted());
    server.stop(true);
    if (waitFailure) {
        // Wait to be informed of failure
        boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
        Assert.assertTrue("Failed to stop the server! Latch count is " + latch.getCount() + " out of " + sessions.length, ok);
    }
    return latch;
}

3. ClusterTestBase#clusterDescription()

View license
protected String clusterDescription(ActiveMQServer server) {
    String br = "-------------------------\n";
    String out = br;
    out += "ActiveMQ Artemis server " + server + "\n";
    ClusterManager clusterManager = server.getClusterManager();
    if (clusterManager == null) {
        out += "N/A";
    } else {
        for (ClusterConnection cc : clusterManager.getClusterConnections()) {
            out += cc.describe() + "\n";
            out += cc.getTopology().describe();
        }
    }
    out += "\n\nfull topology:";
    return out + br;
}

4. JMSUtil#crash()

Project: activemq-artemis
Source File: JMSUtil.java
View license
public static void crash(ActiveMQServer server, ClientSession... sessions) throws Exception {
    final CountDownLatch latch = new CountDownLatch(sessions.length);
    class MyListener implements SessionFailureListener {

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver) {
            latch.countDown();
        }

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed(me, failedOver);
        }

        @Override
        public void beforeReconnect(ActiveMQException exception) {
            System.out.println("MyListener.beforeReconnect");
        }
    }
    for (ClientSession session : sessions) {
        session.addFailureListener(new MyListener());
    }
    ClusterManager clusterManager = server.getClusterManager();
    clusterManager.clear();
    server.stop(true);
    // Wait to be informed of failure
    boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(ok);
}

5. ActiveMQServerImpl#initialisePart1()

View license
/**
    * Starts everything apart from RemotingService and loading the data.
    * <p>
    * After optional intermediary steps, Part 1 is meant to be followed by part 2
    * {@link #initialisePart2(boolean)}.
    *
    * @param scalingDown
    */
synchronized boolean initialisePart1(boolean scalingDown) throws Exception {
    if (state == SERVER_STATE.STOPPED)
        return false;
    // Create the pools - we have two pools - one for non scheduled - and another for scheduled
    initializeExecutorServices();
    if (configuration.getJournalType() == JournalType.ASYNCIO) {
        if (!AIOSequentialFileFactory.isSupported()) {
            ActiveMQServerLogger.LOGGER.switchingNIO();
            configuration.setJournalType(JournalType.NIO);
        } else if (!AIOSequentialFileFactory.isSupported(configuration.getJournalLocation())) {
            ActiveMQServerLogger.LOGGER.switchingNIOonPath(configuration.getJournalLocation().getAbsolutePath());
            configuration.setJournalType(JournalType.NIO);
        }
    }
    managementService = new ManagementServiceImpl(mbeanServer, configuration);
    if (configuration.getMemoryMeasureInterval() != -1) {
        memoryManager = new MemoryManager(configuration.getMemoryWarningThreshold(), configuration.getMemoryMeasureInterval());
        memoryManager.start();
    }
    // Create the hard-wired components
    callPreActiveCallbacks();
    // startReplication();
    storageManager = createStorageManager();
    if (configuration.getClusterConfigurations().size() > 0 && ActiveMQDefaultConfiguration.getDefaultClusterUser().equals(configuration.getClusterUser()) && ActiveMQDefaultConfiguration.getDefaultClusterPassword().equals(configuration.getClusterPassword())) {
        ActiveMQServerLogger.LOGGER.clusterSecurityRisk();
    }
    securityStore = new SecurityStoreImpl(securityRepository, securityManager, configuration.getSecurityInvalidationInterval(), configuration.isSecurityEnabled(), configuration.getClusterUser(), configuration.getClusterPassword(), managementService);
    queueFactory = new QueueFactoryImpl(executorFactory, scheduledPool, addressSettingsRepository, storageManager);
    pagingManager = createPagingManager();
    resourceManager = new ResourceManagerImpl((int) (configuration.getTransactionTimeout() / 1000), configuration.getTransactionTimeoutScanPeriod(), scheduledPool);
    postOffice = new PostOfficeImpl(this, storageManager, pagingManager, queueFactory, managementService, configuration.getMessageExpiryScanPeriod(), configuration.getMessageExpiryThreadPriority(), configuration.isWildcardRoutingEnabled(), configuration.getIDCacheSize(), configuration.isPersistIDCache(), addressSettingsRepository);
    // This can't be created until node id is set
    clusterManager = new ClusterManager(executorFactory, this, postOffice, scheduledPool, managementService, configuration, nodeManager, haPolicy.isBackup());
    backupManager = new BackupManager(this, executorFactory, scheduledPool, nodeManager, configuration, clusterManager);
    clusterManager.deploy();
    remotingService = new RemotingServiceImpl(clusterManager, configuration, this, managementService, scheduledPool, protocolManagerFactories, executorFactory.getExecutor(), serviceRegistry);
    messagingServerControl = managementService.registerServer(postOffice, securityStore, storageManager, configuration, addressSettingsRepository, securityRepository, resourceManager, remotingService, this, queueFactory, scheduledPool, pagingManager, haPolicy.isBackup());
    if (!scalingDown) {
        deployAddressSettingsFromConfiguration();
    }
    storageManager.start();
    postOffice.start();
    pagingManager.start();
    managementService.start();
    resourceManager.start();
    deploySecurityFromConfiguration();
    deployGroupingHandlerConfiguration(configuration.getGroupingHandlerConfiguration());
    return true;
}

6. TopologyClusterTestBase#waitForClusterConnections()

View license
protected void waitForClusterConnections(final int node, final int expected) throws Exception {
    ActiveMQServer server = servers[node];
    if (server == null) {
        throw new IllegalArgumentException("No server at " + node);
    }
    ClusterManager clusterManager = server.getClusterManager();
    long start = System.currentTimeMillis();
    int nodesCount;
    do {
        nodesCount = 0;
        for (ClusterConnection clusterConn : clusterManager.getClusterConnections()) {
            Map<String, String> nodes = clusterConn.getNodes();
            for (String id : nodes.keySet()) {
                if (clusterConn.isNodeActive(id)) {
                    nodesCount++;
                }
            }
        }
        if (nodesCount == expected) {
            return;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < ActiveMQTestBase.WAIT_TIMEOUT);
    log.error(clusterDescription(servers[node]));
    Assert.assertEquals("Timed out waiting for cluster connections for server " + node, expected, nodesCount);
}