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