Search in sources :

Example 1 with TopologyMember

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;
    }
}
Also used : TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ObjectStreamException(java.io.ObjectStreamException) HashSet(java.util.HashSet)

Example 2 with TopologyMember

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;
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember)

Example 3 with TopologyMember

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);
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember) ClusterControl(org.apache.activemq.artemis.core.server.cluster.ClusterControl)

Example 4 with TopologyMember

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);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 5 with TopologyMember

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;
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

TopologyMember (org.apache.activemq.artemis.api.core.client.TopologyMember)9 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ClusterTopologyListener (org.apache.activemq.artemis.api.core.client.ClusterTopologyListener)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 File (java.io.File)1 ObjectStreamException (java.io.ObjectStreamException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Executor (java.util.concurrent.Executor)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1 Pair (org.apache.activemq.artemis.api.core.Pair)1