Search in sources :

Example 11 with ActiveMQIllegalStateException

use of org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException 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)

Example 12 with ActiveMQIllegalStateException

use of org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException in project activemq-artemis by apache.

the class FileLockNodeManager method readNodeId.

@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();
}
Also used : ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) UUID(org.apache.activemq.artemis.utils.UUID) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ActiveMQAlreadyReplicatingException (org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)2 ActiveMQDisconnectedException (org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 MessageHandler (org.apache.activemq.artemis.api.core.client.MessageHandler)2 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)2 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)2 Test (org.junit.Test)2 ObjectStreamException (java.io.ObjectStreamException)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1