Search in sources :

Example 16 with ServerLocatorInternal

use of org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal in project activemq-artemis by apache.

the class SharedNothingLiveActivation method isNodeIdUsed.

/**
 * Determines whether there is another server already running with this server's nodeID.
 * <p>
 * This can happen in case of a successful fail-over followed by the live's restart
 * (attempting a fail-back).
 *
 * @throws Exception
 */
private boolean isNodeIdUsed() throws Exception {
    if (activeMQServer.getConfiguration().getClusterConfigurations().isEmpty())
        return false;
    SimpleString nodeId0;
    try {
        nodeId0 = activeMQServer.getNodeManager().readNodeId();
    } catch (ActiveMQIllegalStateException e) {
        nodeId0 = null;
    }
    ClusterConnectionConfiguration config = ConfigurationUtils.getReplicationClusterConfiguration(activeMQServer.getConfiguration(), replicatedPolicy.getClusterName());
    NodeIdListener listener = new NodeIdListener(nodeId0, activeMQServer.getConfiguration().getClusterUser(), activeMQServer.getConfiguration().getClusterPassword());
    try (ServerLocatorInternal locator = getLocator(config)) {
        locator.addClusterTopologyListener(listener);
        locator.setReconnectAttempts(0);
        try (ClientSessionFactoryInternal factory = locator.connectNoWarnings()) {
            // Just try connecting
            listener.latch.await(5, TimeUnit.SECONDS);
        } catch (Exception notConnected) {
            return false;
        }
        return listener.isNodePresent;
    }
}
Also used : ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQDisconnectedException(org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)

Aggregations

ServerLocatorInternal (org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)16 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)6 Test (org.junit.Test)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ClusterConnectionConfiguration (org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 ActiveMQAlreadyReplicatingException (org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)1 ActiveMQDisconnectedException (org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ServerLocatorImpl (org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl)1 Topology (org.apache.activemq.artemis.core.client.impl.Topology)1 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)1