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;
}
}
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();
}
Aggregations