use of org.apache.activemq.artemis.api.core.client.TopologyMember in project activemq-artemis by apache.
the class ServerLocatorImpl method notifyNodeUp.
@Override
public void notifyNodeUp(long uniqueEventID, final String nodeID, final String backupGroupName, final String scaleDownGroupName, final Pair<TransportConfiguration, TransportConfiguration> connectorPair, final boolean last) {
if (logger.isTraceEnabled()) {
logger.trace("NodeUp " + this + "::nodeID=" + nodeID + ", connectorPair=" + connectorPair, new Exception("trace"));
}
TopologyMemberImpl member = new TopologyMemberImpl(nodeID, backupGroupName, scaleDownGroupName, connectorPair.getA(), connectorPair.getB());
topology.updateMember(uniqueEventID, nodeID, member);
TopologyMember actMember = topology.getMember(nodeID);
if (actMember != null && actMember.getLive() != null && actMember.getBackup() != null) {
HashSet<ClientSessionFactory> clonedFactories = new HashSet<>();
synchronized (factories) {
clonedFactories.addAll(factories);
}
for (ClientSessionFactory factory : clonedFactories) {
((ClientSessionFactoryInternal) factory).setBackupConnector(actMember.getLive(), actMember.getBackup());
}
}
updateArraysAndPairs(uniqueEventID);
if (last) {
receivedTopology = true;
}
}
use of org.apache.activemq.artemis.api.core.client.TopologyMember in project activemq-artemis by apache.
the class BridgeImpl method reconnectOnOriginalNode.
protected ClientSessionFactoryInternal reconnectOnOriginalNode() throws Exception {
String targetNodeIdUse = targetNodeID;
TopologyMember nodeUse = targetNode;
if (targetNodeIdUse != null && nodeUse != null) {
// live and backup
TransportConfiguration[] configs = new TransportConfiguration[2];
int numberOfConfigs = 0;
if (nodeUse.getLive() != null) {
configs[numberOfConfigs++] = nodeUse.getLive();
}
if (nodeUse.getBackup() != null) {
configs[numberOfConfigs++] = nodeUse.getBackup();
}
if (numberOfConfigs > 0) {
// It will bounce between all the available configs
int nodeTry = (retryCount - 1) % numberOfConfigs;
return (ClientSessionFactoryInternal) serverLocator.createSessionFactory(configs[nodeTry]);
}
}
return null;
}
use of org.apache.activemq.artemis.api.core.client.TopologyMember in project activemq-artemis by apache.
the class ClusterConnectionImpl method onConnection.
@Override
public void onConnection(ClientSessionFactoryInternal sf) {
TopologyMember localMember = getLocalMember();
if (localMember != null) {
ClusterControl clusterControl = manager.getClusterController().connectToNodeInCluster(sf);
try {
clusterControl.authorize();
clusterControl.sendNodeAnnounce(localMember.getUniqueEventID(), manager.getNodeId(), manager.getBackupGroupName(), manager.getScaleDownGroupName(), false, localMember.getLive(), localMember.getBackup());
} catch (ActiveMQException e) {
ActiveMQServerLogger.LOGGER.clusterControlAuthfailure();
}
} else {
ActiveMQServerLogger.LOGGER.noLocalMemborOnClusterConnection(this);
}
// TODO: shouldn't we send the current time here? and change the current topology?
// sf.sendNodeAnnounce(System.currentTimeMillis(),
// manager.getNodeId(),
// false,
// localMember.getConnector().a,
// localMember.getConnector().b);
}
use of org.apache.activemq.artemis.api.core.client.TopologyMember in project activemq-artemis by apache.
the class ClusterConnectionImpl method activate.
private synchronized void activate() throws Exception {
if (!started) {
return;
}
if (logger.isDebugEnabled()) {
logger.debug("Activating cluster connection nodeID=" + nodeManager.getNodeId() + " for server=" + this.server);
}
liveNotifier = new LiveNotifier();
liveNotifier.updateAsLive();
liveNotifier.schedule();
serverLocator = clusterConnector.createServerLocator();
if (serverLocator != null) {
if (!useDuplicateDetection) {
logger.debug("DuplicateDetection is disabled, sending clustered messages blocked");
}
final TopologyMember currentMember = topology.getMember(manager.getNodeId());
if (currentMember == null) {
// sanity check only
throw new IllegalStateException("InternalError! The ClusterConnection doesn't know about its own node = " + this);
}
serverLocator.setNodeID(nodeManager.getNodeId().toString());
serverLocator.setIdentity("(main-ClusterConnection::" + server.toString() + ")");
serverLocator.setReconnectAttempts(0);
serverLocator.setClusterConnection(true);
serverLocator.setClusterTransportConfiguration(connector);
serverLocator.setInitialConnectAttempts(-1);
serverLocator.setClientFailureCheckPeriod(clientFailureCheckPeriod);
serverLocator.setConnectionTTL(connectionTTL);
serverLocator.setConfirmationWindowSize(confirmationWindowSize);
// if not using duplicate detection, we will send blocked
serverLocator.setBlockOnDurableSend(!useDuplicateDetection);
serverLocator.setBlockOnNonDurableSend(!useDuplicateDetection);
serverLocator.setCallTimeout(callTimeout);
serverLocator.setCallFailoverTimeout(callFailoverTimeout);
serverLocator.setProducerWindowSize(producerWindowSize);
if (retryInterval > 0) {
this.serverLocator.setRetryInterval(retryInterval);
}
serverLocator.setAfterConnectionInternalListener(this);
serverLocator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(serverLocator));
serverLocator.start(server.getExecutorFactory().getExecutor());
}
if (managementService != null) {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(new SimpleString("name"), name);
Notification notification = new Notification(nodeManager.getNodeId().toString(), CoreNotificationType.CLUSTER_CONNECTION_STARTED, props);
logger.debug("sending notification: " + notification);
managementService.sendNotification(notification);
}
// we add as a listener after we have sent the cluster start notif as the listener may start sending notifs before
addClusterTopologyListener(this);
}
use of org.apache.activemq.artemis.api.core.client.TopologyMember in project activemq-artemis by apache.
the class ColocatedHAManager method activateReplicatedBackup.
/**
* activate a backup server replicating from a specified node.
*
* decline and the requesting server can cast a re vote
*
* @param nodeID the id of the node to replicate from
* @return true if the server was created and started
* @throws Exception
*/
private synchronized boolean activateReplicatedBackup(SimpleString nodeID) throws Exception {
Configuration configuration = server.getConfiguration().copy();
ActiveMQServer backup = server.createBackupServer(configuration);
try {
TopologyMember member = server.getClusterManager().getDefaultConnection(null).getTopology().getMember(nodeID.toString());
int portOffset = haPolicy.getBackupPortOffset() * (backupServers.size() + 1);
String name = "colocated_backup_" + backupServers.size() + 1;
// make sure we don't restart as we are colocated
haPolicy.getBackupPolicy().setRestartBackup(false);
// set the backup policy
backup.setHAPolicy(haPolicy.getBackupPolicy());
updateReplicatedConfiguration(configuration, name, portOffset, haPolicy.getExcludedConnectors(), haPolicy.getBackupPolicy().getScaleDownPolicy() == null);
backup.addActivationParam(ActivationParams.REPLICATION_ENDPOINT, member);
backupServers.put(configuration.getName(), backup);
backup.start();
} catch (Exception e) {
backup.stop();
ActiveMQServerLogger.LOGGER.activateReplicatedBackupFailed(e);
return false;
}
ActiveMQServerLogger.LOGGER.activatingReplica(nodeID);
return true;
}
Aggregations