Search in sources :

Example 16 with TopologyMemberImpl

use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.

the class JMSUtil method waitForFailoverTopology.

public static void waitForFailoverTopology(final int timeToWait, final ActiveMQServer backupServer, final ActiveMQServer... liveServers) throws Exception {
    long start = System.currentTimeMillis();
    final int waitMillis = 2000;
    final int sleepTime = 50;
    int nWaits = 0;
    while ((backupServer.getClusterManager() == null || backupServer.getClusterManager().getClusterConnections().size() != 1) && nWaits++ < waitMillis / sleepTime) {
        Thread.sleep(sleepTime);
    }
    Set<ClusterConnection> ccs = backupServer.getClusterManager().getClusterConnections();
    if (ccs.size() != 1) {
        throw new IllegalStateException("You need a single cluster connection on this version of waitForTopology on ServiceTestBase");
    }
    boolean exists = false;
    for (ActiveMQServer liveServer : liveServers) {
        ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
        Topology topology = clusterConnection.getTopology();
        TransportConfiguration nodeConnector = liveServer.getClusterManager().getClusterConnections().iterator().next().getConnector();
        do {
            Collection<TopologyMemberImpl> members = topology.getMembers();
            for (TopologyMemberImpl member : members) {
                if (member.getConnector().getA() != null && member.getConnector().getA().equals(nodeConnector)) {
                    exists = true;
                    break;
                }
            }
            if (exists) {
                break;
            }
            Thread.sleep(10);
        } while (System.currentTimeMillis() - start < timeToWait);
        if (!exists) {
            String msg = "Timed out waiting for cluster topology of " + backupServer + " (received " + topology.getMembers().size() + ") topology = " + topology + ")";
            throw new Exception(msg);
        }
    }
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Topology(org.apache.activemq.artemis.core.client.impl.Topology) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)

Aggregations

TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)16 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)9 Topology (org.apache.activemq.artemis.core.client.impl.Topology)9 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)4 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 ClusterConnectionImpl (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ClusterManager (org.apache.activemq.artemis.core.server.cluster.ClusterManager)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 SQLException (java.sql.SQLException)1 JMSException (javax.jms.JMSException)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 XAException (javax.transaction.xa.XAException)1