org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration

Here are the examples of the java api class org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration taken from open source projects.

1. ClusterTestBase#setupDiscoveryClusterConnection()

Project: activemq-artemis
File: ClusterTestBase.java
protected void setupDiscoveryClusterConnection(final String name, final int node, final String discoveryGroupName, final String address, final MessageLoadBalancingType messageLoadBalancingType, final int maxHops, final boolean netty) {
    ActiveMQServer server = servers[node];
    if (server == null) {
        throw new IllegalStateException("No server at node " + node);
    }
    TransportConfiguration connectorConfig = createTransportConfiguration(netty, false, generateParams(node, netty));
    server.getConfiguration().getConnectorConfigurations().put(name, connectorConfig);
    Configuration config = server.getConfiguration();
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName(name).setAddress(address).setConnectorName(name).setRetryInterval(100).setDuplicateDetection(true).setMessageLoadBalancingType(messageLoadBalancingType).setMaxHops(maxHops).setConfirmationWindowSize(1024).setDiscoveryGroupName(discoveryGroupName);
    List<ClusterConnectionConfiguration> clusterConfs = config.getClusterConfigurations();
    clusterConfs.add(clusterConf);
}

2. ClusterTestBase#setupClusterConnection()

Project: activemq-artemis
File: ClusterTestBase.java
protected void setupClusterConnection(final String name, final String uri, int server) throws Exception {
    ActiveMQServer serverFrom = servers[server];
    if (serverFrom == null) {
        throw new IllegalStateException("No server at node " + server);
    }
    ClusterConnectionConfiguration configuration = new ClusterConnectionConfiguration(new URI(uri)).setName(name);
    serverFrom.getConfiguration().addClusterConfiguration(configuration);
}

3. ClusterConnectionStaticSchema#internalNewObject()

Project: activemq-artemis
File: ClusterConnectionStaticSchema.java
@Override
protected ClusterConnectionConfiguration internalNewObject(URI uri, Map<String, String> query, String param) throws Exception {
    ClusterConnectionConfiguration configuration = new ClusterConnectionConfiguration();
    populateObject(uri, configuration);
    return configuration;
}

4. ClusterManager#deploy()

Project: activemq-artemis
File: ClusterManager.java
public synchronized void deploy() throws Exception {
    if (state == State.STOPPED) {
        state = State.DEPLOYED;
    } else {
        throw new IllegalStateException();
    }
    for (BroadcastGroupConfiguration config : configuration.getBroadcastGroupConfigurations()) {
        deployBroadcastGroup(config);
    }
    for (ClusterConnectionConfiguration config : configuration.getClusterConfigurations()) {
        deployClusterConnection(config);
    }
    /*
      * only start if we are actually in a cluster
      * */
    if (clusterConnections.size() > 0) {
        clusterController.start();
    }
}

5. ClusterControl#announceReplicatingBackupToLive()

Project: activemq-artemis
File: ClusterControl.java
/**
    * XXX HORNETQ-720
    *
    * @param attemptingFailBack if {@code true} then this server wants to trigger a fail-back when
    *                           up-to-date, that is it wants to take over the role of 'live' from the current 'live'
    *                           server.
    * @throws ActiveMQException
    */
public void announceReplicatingBackupToLive(final boolean attemptingFailBack, String replicationClusterName) throws ActiveMQException {
    ClusterConnectionConfiguration config = ConfigurationUtils.getReplicationClusterConfiguration(server.getConfiguration(), replicationClusterName);
    if (config == null) {
        ActiveMQServerLogger.LOGGER.announceBackupNoClusterConnections();
        throw new ActiveMQException("lacking cluster connection");
    }
    TransportConfiguration connector = server.getConfiguration().getConnectorConfigurations().get(config.getConnectorName());
    if (connector == null) {
        ActiveMQServerLogger.LOGGER.announceBackupNoConnector(config.getConnectorName());
        throw new ActiveMQException("lacking cluster connection");
    }
    clusterChannel.send(new BackupRegistrationMessage(connector, clusterUser, clusterPassword, attemptingFailBack));
}

6. BackupManager#start()

Project: activemq-artemis
File: BackupManager.java
/*
   * Start the backup manager if not already started. This entails deploying a backup connector based on a cluster
   * configuration, informing the cluster manager so that it can add it to its topology and announce itself to the cluster.
   * */
@Override
public synchronized void start() throws Exception {
    if (started)
        return;
    //deploy the backup connectors using the cluster configuration
    for (ClusterConnectionConfiguration config : configuration.getClusterConfigurations()) {
        deployBackupConnector(config);
    }
    //as we wait for replication to start and be notififed by the replication manager.
    for (BackupConnector conn : backupConnectors) {
        conn.start();
        if (server.getHAPolicy().isBackup() && server.getHAPolicy().isSharedStore()) {
            conn.informTopology();
            conn.announceBackup();
        }
    }
    started = true;
}

7. IsolatedTopologyTest#createServer2()

Project: activemq-artemis
File: IsolatedTopologyTest.java
private ActiveMQServer createServer2() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.CLUSTER_CONNECTION, "cc1");
    params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "3");
    TransportConfiguration acceptor1VM1 = new TransportConfiguration(ActiveMQTestBase.INVM_ACCEPTOR_FACTORY, params, "acceptor-cc1");
    params = new HashMap<>();
    params.put(TransportConstants.CLUSTER_CONNECTION, "cc2");
    params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "4");
    TransportConfiguration acceptor2VM1 = new TransportConfiguration(ActiveMQTestBase.INVM_ACCEPTOR_FACTORY, params, "acceptor-cc2");
    List<String> connectTo = new ArrayList<>();
    connectTo.add("other-cc1");
    ClusterConnectionConfiguration server1CC1 = new ClusterConnectionConfiguration().setName("cc1").setAddress("jms").setConnectorName("local-cc1").setRetryInterval(250).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(connectTo);
    List<String> connectTo2 = new ArrayList<>();
    connectTo2.add("other-cc2");
    ClusterConnectionConfiguration server1CC2 = new ClusterConnectionConfiguration().setName("cc2").setAddress("jms").setConnectorName("local-cc2").setRetryInterval(250).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(connectTo2);
    // Server2 with two acceptors, each acceptor on a different cluster connection
    // talking to a different connector.
    // i.e. two cluster connections isolated on the same node
    Configuration config1 = createBasicConfig(2).addAcceptorConfiguration(acceptor1VM1).addAcceptorConfiguration(acceptor2VM1).addConnectorConfiguration("local-cc1", createInVMTransportConnectorConfig(3, "local-cc1")).addConnectorConfiguration("local-cc2", createInVMTransportConnectorConfig(4, "local-cc2")).addConnectorConfiguration("other-cc1", createInVMTransportConnectorConfig(1, "other-cc1")).addConnectorConfiguration("other-cc2", createInVMTransportConnectorConfig(2, "other-cc2")).addClusterConfiguration(server1CC1).addClusterConfiguration(server1CC2);
    return createServer(false, config1);
}

8. IsolatedTopologyTest#createServer1()

Project: activemq-artemis
File: IsolatedTopologyTest.java
private ActiveMQServer createServer1() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.CLUSTER_CONNECTION, "cc1");
    params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1");
    TransportConfiguration acceptor1VM1 = new TransportConfiguration(ActiveMQTestBase.INVM_ACCEPTOR_FACTORY, params, "acceptor-cc1");
    params = new HashMap<>();
    params.put(TransportConstants.CLUSTER_CONNECTION, "cc2");
    params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "2");
    TransportConfiguration acceptor2VM1 = new TransportConfiguration(ActiveMQTestBase.INVM_ACCEPTOR_FACTORY, params, "acceptor-cc2");
    List<String> connectTo = new ArrayList<>();
    connectTo.add("other-cc1");
    ClusterConnectionConfiguration server1CC1 = new ClusterConnectionConfiguration().setName("cc1").setAddress("jms").setConnectorName("local-cc1").setRetryInterval(250).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(connectTo);
    ArrayList<String> connectTo2 = new ArrayList<>();
    connectTo2.add("other-cc2");
    ClusterConnectionConfiguration server1CC2 = new ClusterConnectionConfiguration().setName("cc2").setAddress("jms").setConnectorName("local-cc2").setRetryInterval(250).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(connectTo2);
    // Server1 with two acceptors, each acceptor on a different cluster connection
    // talking to a different connector.
    // i.e. two cluster connections isolated on the same node
    Configuration config1 = createBasicConfig(1).addConnectorConfiguration("local-cc1", createInVMTransportConnectorConfig(1, "local-cc1")).addConnectorConfiguration("local-cc2", createInVMTransportConnectorConfig(2, "local-cc2")).addConnectorConfiguration("other-cc1", createInVMTransportConnectorConfig(3, "other-cc1")).addConnectorConfiguration("other-cc2", createInVMTransportConnectorConfig(4, "other-cc2")).addAcceptorConfiguration(acceptor1VM1).addAcceptorConfiguration(acceptor2VM1).addClusterConfiguration(server1CC1).addClusterConfiguration(server1CC2);
    return createServer(false, config1);
}

9. SpawnedServerSupport#setupClusterConn()

Project: activemq-artemis
File: SpawnedServerSupport.java
protected static final ClusterConnectionConfiguration setupClusterConn(String connectorName, String... connectors) {
    List<String> connectorList = new LinkedList<>();
    for (String conn : connectors) {
        connectorList.add(conn);
    }
    ClusterConnectionConfiguration ccc = new ClusterConnectionConfiguration().setName("cluster1").setAddress("jms").setConnectorName(connectorName).setRetryInterval(10).setDuplicateDetection(false).setMessageLoadBalancingType(MessageLoadBalancingType.STRICT).setConfirmationWindowSize(1).setStaticConnectors(connectorList);
    return ccc;
}

10. MultiServerTestBase#setupBackupServer()

Project: activemq-artemis
File: MultiServerTestBase.java
protected ActiveMQServer setupBackupServer(final int node, final int liveNode, final NodeManager nodeManager) throws Exception {
    TransportConfiguration serverConfigAcceptor = createTransportConfiguration(useNetty(), true, generateParams(node, useNetty()));
    TransportConfiguration thisConnector = createTransportConfiguration(useNetty(), false, generateParams(node, useNetty()));
    Configuration configuration = createBasicConfig(useSharedStorage() ? liveNode : node).clearAcceptorConfigurations().addAcceptorConfiguration(serverConfigAcceptor).addConnectorConfiguration("thisConnector", thisConnector).setHAPolicyConfiguration(useSharedStorage() ? new SharedStoreSlavePolicyConfiguration() : new ReplicaPolicyConfiguration());
    List<String> targetServersOnConnection = new ArrayList<>();
    for (int targetNode = 0; targetNode < getNumberOfServers(); targetNode++) {
        //         if (targetNode == node)
        //         {
        //            // moving on from itself
        //            continue;
        //         }
        String targetConnectorName = "targetConnector-" + targetNode;
        TransportConfiguration targetServer = createTransportConfiguration(useNetty(), false, generateParams(targetNode, useNetty()));
        configuration.addConnectorConfiguration(targetConnectorName, targetServer);
        targetServersOnConnection.add(targetConnectorName);
    }
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName("localCluster" + node).setAddress("cluster-queues").setConnectorName("thisConnector").setRetryInterval(100).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(targetServersOnConnection);
    configuration.getClusterConfigurations().add(clusterConf);
    ActiveMQServer server;
    if (useSharedStorage()) {
        server = createInVMFailoverServer(true, configuration, nodeManager, liveNode);
    } else {
        server = addServer(ActiveMQServers.newActiveMQServer(configuration, useRealFiles()));
    }
    server.setIdentity(this.getClass().getSimpleName() + "/Backup(" + node + " of live " + liveNode + ")");
    return server;
}

11. MultiServerTestBase#setupLiveServer()

Project: activemq-artemis
File: MultiServerTestBase.java
protected Pair<ActiveMQServer, NodeManager> setupLiveServer(final int node, final boolean realFiles, final boolean sharedStorage) throws Exception {
    NodeManager nodeManager = null;
    TransportConfiguration serverConfigAcceptor = createTransportConfiguration(useNetty(), true, generateParams(node, useNetty()));
    TransportConfiguration thisConnector = createTransportConfiguration(useNetty(), false, generateParams(node, useNetty()));
    if (sharedStorage) {
        nodeManager = new InVMNodeManager(false);
    }
    Configuration configuration = createBasicConfig(node).setJournalMaxIO_AIO(1000).setThreadPoolMaxSize(10).clearAcceptorConfigurations().addAcceptorConfiguration(serverConfigAcceptor).addConnectorConfiguration("thisConnector", thisConnector).setHAPolicyConfiguration(sharedStorage ? new SharedStoreMasterPolicyConfiguration() : new ReplicatedPolicyConfiguration());
    List<String> targetServersOnConnection = new ArrayList<>();
    for (int targetNode = 0; targetNode < getNumberOfServers(); targetNode++) {
        if (targetNode == node) {
            continue;
        }
        String targetConnectorName = "target-" + targetNode;
        TransportConfiguration targetServer = createTransportConfiguration(useNetty(), false, generateParams(targetNode, useNetty()));
        configuration.getConnectorConfigurations().put(targetConnectorName, targetServer);
        targetServersOnConnection.add(targetConnectorName);
        // The connector towards a backup.. just to have a reference so bridges can connect to backups on their configs
        String backupConnectorName = "backup-" + targetNode;
        TransportConfiguration backupConnector = createTransportConfiguration(useNetty(), false, generateParams(targetNode + getNumberOfServers(), useNetty()));
        configuration.getConnectorConfigurations().put(backupConnectorName, backupConnector);
    }
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName("localCluster" + node).setAddress("cluster-queues").setConnectorName("thisConnector").setRetryInterval(100).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(targetServersOnConnection);
    configuration.getClusterConfigurations().add(clusterConf);
    ActiveMQServer server;
    if (sharedStorage) {
        server = createInVMFailoverServer(realFiles, configuration, nodeManager, node);
    } else {
        server = createServer(realFiles, configuration);
    }
    server.setIdentity(this.getClass().getSimpleName() + "/Live(" + node + ")");
    addServer(server);
    return new Pair<>(server, nodeManager);
}

12. ClusterTestBase#setupClusterConnectionWithBackups()

Project: activemq-artemis
File: ClusterTestBase.java
protected void setupClusterConnectionWithBackups(final String name, final String address, final MessageLoadBalancingType messageLoadBalancingType, final int maxHops, final boolean netty, final int nodeFrom, final int[] nodesTo) {
    ActiveMQServer serverFrom = servers[nodeFrom];
    if (serverFrom == null) {
        throw new IllegalStateException("No server at node " + nodeFrom);
    }
    TransportConfiguration connectorFrom = createTransportConfiguration(netty, false, generateParams(nodeFrom, netty));
    serverFrom.getConfiguration().getConnectorConfigurations().put(name, connectorFrom);
    List<String> pairs = new ArrayList<>();
    for (int element : nodesTo) {
        TransportConfiguration serverTotc = createTransportConfiguration(netty, false, generateParams(element, netty));
        serverFrom.getConfiguration().getConnectorConfigurations().put(serverTotc.getName(), serverTotc);
        pairs.add(serverTotc.getName());
    }
    Configuration config = serverFrom.getConfiguration();
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName(name).setAddress(address).setConnectorName(name).setRetryInterval(250).setMessageLoadBalancingType(messageLoadBalancingType).setMaxHops(maxHops).setConfirmationWindowSize(1024).setStaticConnectors(pairs);
    config.getClusterConfigurations().add(clusterConf);
}

13. ClusterTestBase#setupClusterConnection()

Project: activemq-artemis
File: ClusterTestBase.java
protected void setupClusterConnection(final String name, final String address, final MessageLoadBalancingType messageLoadBalancingType, final int maxHops, final int reconnectAttempts, final long retryInterval, final boolean netty, final int nodeFrom, final int... nodesTo) {
    ActiveMQServer serverFrom = servers[nodeFrom];
    if (serverFrom == null) {
        throw new IllegalStateException("No server at node " + nodeFrom);
    }
    TransportConfiguration connectorFrom = createTransportConfiguration(netty, false, generateParams(nodeFrom, netty));
    serverFrom.getConfiguration().getConnectorConfigurations().put(connectorFrom.getName(), connectorFrom);
    List<String> pairs = new ArrayList<>();
    for (int element : nodesTo) {
        TransportConfiguration serverTotc = createTransportConfiguration(netty, false, generateParams(element, netty));
        serverFrom.getConfiguration().getConnectorConfigurations().put(serverTotc.getName(), serverTotc);
        pairs.add(serverTotc.getName());
    }
    Configuration config = serverFrom.getConfiguration();
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName(name).setAddress(address).setConnectorName(connectorFrom.getName()).setRetryInterval(retryInterval).setReconnectAttempts(reconnectAttempts).setCallTimeout(100).setCallFailoverTimeout(100).setMessageLoadBalancingType(messageLoadBalancingType).setMaxHops(maxHops).setConfirmationWindowSize(1024).setStaticConnectors(pairs);
    config.getClusterConfigurations().add(clusterConf);
}

14. ClusterTestBase#setupClusterConnection()

Project: activemq-artemis
File: ClusterTestBase.java
protected void setupClusterConnection(final String name, final String address, final MessageLoadBalancingType messageLoadBalancingType, final int maxHops, final boolean netty, final int nodeFrom, final int... nodesTo) {
    ActiveMQServer serverFrom = servers[nodeFrom];
    if (serverFrom == null) {
        throw new IllegalStateException("No server at node " + nodeFrom);
    }
    TransportConfiguration connectorFrom = createTransportConfiguration(netty, false, generateParams(nodeFrom, netty));
    serverFrom.getConfiguration().getConnectorConfigurations().put(connectorFrom.getName(), connectorFrom);
    List<String> pairs = new ArrayList<>();
    for (int element : nodesTo) {
        TransportConfiguration serverTotc = createTransportConfiguration(netty, false, generateParams(element, netty));
        serverFrom.getConfiguration().getConnectorConfigurations().put(serverTotc.getName(), serverTotc);
        pairs.add(serverTotc.getName());
    }
    Configuration config = serverFrom.getConfiguration();
    ClusterConnectionConfiguration clusterConf = createClusterConfig(name, address, messageLoadBalancingType, maxHops, connectorFrom, pairs);
    config.getClusterConfigurations().add(clusterConf);
}

15. ClusterTestBase#setupClusterConnection()

Project: activemq-artemis
File: ClusterTestBase.java
protected void setupClusterConnection(final String name, final int nodeFrom, final int nodeTo, final String address, final MessageLoadBalancingType messageLoadBalancingType, final int maxHops, final int reconnectAttempts, final long retryInterval, final boolean netty, final boolean allowDirectConnectionsOnly) {
    ActiveMQServer serverFrom = servers[nodeFrom];
    if (serverFrom == null) {
        throw new IllegalStateException("No server at node " + nodeFrom);
    }
    TransportConfiguration connectorFrom = createTransportConfiguration(netty, false, generateParams(nodeFrom, netty));
    serverFrom.getConfiguration().getConnectorConfigurations().put(name, connectorFrom);
    List<String> pairs = null;
    if (nodeTo != -1) {
        TransportConfiguration serverTotc = createTransportConfiguration(netty, false, generateParams(nodeTo, netty));
        serverFrom.getConfiguration().getConnectorConfigurations().put(serverTotc.getName(), serverTotc);
        pairs = new ArrayList<>();
        pairs.add(serverTotc.getName());
    }
    Configuration config = serverFrom.getConfiguration();
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName(name).setAddress(address).setConnectorName(name).setReconnectAttempts(reconnectAttempts).setRetryInterval(retryInterval).setMessageLoadBalancingType(messageLoadBalancingType).setMaxHops(maxHops).setConfirmationWindowSize(1024).setStaticConnectors(pairs).setAllowDirectConnectionsOnly(allowDirectConnectionsOnly);
    config.getClusterConfigurations().add(clusterConf);
}

16. ClusterTestBase#setupClusterConnection()

Project: activemq-artemis
File: ClusterTestBase.java
protected void setupClusterConnection(final String name, final int nodeFrom, final int nodeTo, final String address, final MessageLoadBalancingType messageLoadBalancingType, final int maxHops, final boolean netty, final boolean allowDirectConnectionsOnly) {
    ActiveMQServer serverFrom = servers[nodeFrom];
    if (serverFrom == null) {
        throw new IllegalStateException("No server at node " + nodeFrom);
    }
    TransportConfiguration connectorFrom = createTransportConfiguration(netty, false, generateParams(nodeFrom, netty));
    serverFrom.getConfiguration().getConnectorConfigurations().put(name, connectorFrom);
    List<String> pairs = null;
    if (nodeTo != -1) {
        TransportConfiguration serverTotc = createTransportConfiguration(netty, false, generateParams(nodeTo, netty));
        serverFrom.getConfiguration().getConnectorConfigurations().put(serverTotc.getName(), serverTotc);
        pairs = new ArrayList<>();
        pairs.add(serverTotc.getName());
    }
    Configuration config = serverFrom.getConfiguration();
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName(name).setAddress(address).setConnectorName(name).setRetryInterval(100).setMessageLoadBalancingType(messageLoadBalancingType).setMaxHops(maxHops).setConfirmationWindowSize(1024).setStaticConnectors(pairs).setAllowDirectConnectionsOnly(allowDirectConnectionsOnly);
    config.getClusterConfigurations().add(clusterConf);
}

17. ClusterConnectionConfigurationTest#testClusterConnectionMulticast()

Project: activemq-artemis
File: ClusterConnectionConfigurationTest.java
@Test
public void testClusterConnectionMulticast() throws Exception {
    ClusterConnectionConfigurationParser parser = new ClusterConnectionConfigurationParser();
    ClusterConnectionConfiguration configuration = parser.newObject(new URI("multicast://myGroup?minLargeMessageSize=132"), null);
    Assert.assertEquals("myGroup", configuration.getDiscoveryGroupName());
    Assert.assertEquals(132, configuration.getMinLargeMessageSize());
}

18. ClusterConnectionConfigurationTest#testClusterConnectionStaticOnConstrcutor()

Project: activemq-artemis
File: ClusterConnectionConfigurationTest.java
@Test
public void testClusterConnectionStaticOnConstrcutor() throws Exception {
    ClusterConnectionConfiguration configuration = new ClusterConnectionConfiguration(new URI("static:(tcp://localhost:6556,tcp://localhost:6557)?minLargeMessageSize=132"));
    Assert.assertEquals(132, configuration.getMinLargeMessageSize());
    Assert.assertEquals("tcp://localhost:6556", configuration.getCompositeMembers().getComponents()[0].toString());
    Assert.assertEquals("tcp://localhost:6557", configuration.getCompositeMembers().getComponents()[1].toString());
}

19. ClusterConnectionConfigurationTest#testClusterConnectionStatic2()

Project: activemq-artemis
File: ClusterConnectionConfigurationTest.java
@Test
public void testClusterConnectionStatic2() throws Exception {
    ClusterConnectionConfigurationParser parser = new ClusterConnectionConfigurationParser();
    ClusterConnectionConfiguration configuration = parser.newObject(new URI("static://(tcp://localhost:6556,tcp://localhost:6557)?minLargeMessageSize=132;messageLoadBalancingType=OFF"), null);
    Assert.assertEquals(132, configuration.getMinLargeMessageSize());
    Assert.assertEquals(2, configuration.getCompositeMembers().getComponents().length);
    Assert.assertEquals("tcp://localhost:6556", configuration.getCompositeMembers().getComponents()[0].toString());
    Assert.assertEquals("tcp://localhost:6557", configuration.getCompositeMembers().getComponents()[1].toString());
}

20. ClusterConnectionConfigurationTest#testClusterConnectionStatic()

Project: activemq-artemis
File: ClusterConnectionConfigurationTest.java
@Test
public void testClusterConnectionStatic() throws Exception {
    ClusterConnectionConfigurationParser parser = new ClusterConnectionConfigurationParser();
    ClusterConnectionConfiguration configuration = parser.newObject(new URI("static:(tcp://localhost:6556,tcp://localhost:6557)?minLargeMessageSize=132;s&messageLoadBalancingType=OFF"), null);
    Assert.assertEquals(MessageLoadBalancingType.OFF, configuration.getMessageLoadBalancingType());
    Assert.assertEquals(132, configuration.getMinLargeMessageSize());
    Assert.assertEquals("tcp://localhost:6556", configuration.getCompositeMembers().getComponents()[0].toString());
    Assert.assertEquals("tcp://localhost:6557", configuration.getCompositeMembers().getComponents()[1].toString());
}

21. ActiveMQTestBase#basicClusterConnectionConfig()

Project: activemq-artemis
File: ActiveMQTestBase.java
protected static final ClusterConnectionConfiguration basicClusterConnectionConfig(String connectorName, String... connectors) {
    ArrayList<String> connectors0 = new ArrayList<>();
    for (String c : connectors) {
        connectors0.add(c);
    }
    ClusterConnectionConfiguration clusterConnectionConfiguration = new ClusterConnectionConfiguration().setName("cluster1").setAddress("jms").setConnectorName(connectorName).setRetryInterval(1000).setDuplicateDetection(false).setMaxHops(1).setConfirmationWindowSize(1).setMessageLoadBalancingType(MessageLoadBalancingType.STRICT).setStaticConnectors(connectors0);
    return clusterConnectionConfiguration;
}

22. SharedNothingLiveActivation#isNodeIdUsed()

Project: activemq-artemis
File: SharedNothingLiveActivation.java
/**
    * 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);
    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;
    }
}

23. FileConfigurationParser#parseClusterConnectionConfiguration()

Project: activemq-artemis
File: FileConfigurationParser.java
private void parseClusterConnectionConfiguration(final Element e, final Configuration mainConfig) throws Exception {
    String name = e.getAttribute("name");
    String address = getString(e, "address", null, Validators.NOT_NULL_OR_EMPTY);
    String connectorName = getString(e, "connector-ref", null, Validators.NOT_NULL_OR_EMPTY);
    boolean duplicateDetection = getBoolean(e, "use-duplicate-detection", ActiveMQDefaultConfiguration.isDefaultClusterDuplicateDetection());
    MessageLoadBalancingType messageLoadBalancingType;
    if (parameterExists(e, "forward-when-no-consumers")) {
        boolean forwardWhenNoConsumers = getBoolean(e, "forward-when-no-consumers", ActiveMQDefaultConfiguration.isDefaultClusterForwardWhenNoConsumers());
        if (forwardWhenNoConsumers) {
            messageLoadBalancingType = MessageLoadBalancingType.STRICT;
        } else {
            messageLoadBalancingType = MessageLoadBalancingType.ON_DEMAND;
        }
    } else {
        messageLoadBalancingType = Enum.valueOf(MessageLoadBalancingType.class, getString(e, "message-load-balancing", ActiveMQDefaultConfiguration.getDefaultClusterMessageLoadBalancingType(), Validators.MESSAGE_LOAD_BALANCING_TYPE));
    }
    int maxHops = getInteger(e, "max-hops", ActiveMQDefaultConfiguration.getDefaultClusterMaxHops(), Validators.GE_ZERO);
    long clientFailureCheckPeriod = getLong(e, "check-period", ActiveMQDefaultConfiguration.getDefaultClusterFailureCheckPeriod(), Validators.GT_ZERO);
    long connectionTTL = getLong(e, "connection-ttl", ActiveMQDefaultConfiguration.getDefaultClusterConnectionTtl(), Validators.GT_ZERO);
    long retryInterval = getLong(e, "retry-interval", ActiveMQDefaultConfiguration.getDefaultClusterRetryInterval(), Validators.GT_ZERO);
    long callTimeout = getLong(e, "call-timeout", ActiveMQClient.DEFAULT_CALL_TIMEOUT, Validators.GT_ZERO);
    long callFailoverTimeout = getLong(e, "call-failover-timeout", ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, Validators.MINUS_ONE_OR_GT_ZERO);
    double retryIntervalMultiplier = getDouble(e, "retry-interval-multiplier", ActiveMQDefaultConfiguration.getDefaultClusterRetryIntervalMultiplier(), Validators.GT_ZERO);
    int minLargeMessageSize = getInteger(e, "min-large-message-size", ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, Validators.GT_ZERO);
    long maxRetryInterval = getLong(e, "max-retry-interval", ActiveMQDefaultConfiguration.getDefaultClusterMaxRetryInterval(), Validators.GT_ZERO);
    int initialConnectAttempts = getInteger(e, "initial-connect-attempts", ActiveMQDefaultConfiguration.getDefaultClusterInitialConnectAttempts(), Validators.MINUS_ONE_OR_GE_ZERO);
    int reconnectAttempts = getInteger(e, "reconnect-attempts", ActiveMQDefaultConfiguration.getDefaultClusterReconnectAttempts(), Validators.MINUS_ONE_OR_GE_ZERO);
    int confirmationWindowSize = getInteger(e, "confirmation-window-size", ActiveMQDefaultConfiguration.getDefaultClusterConfirmationWindowSize(), Validators.GT_ZERO);
    int producerWindowSize = getInteger(e, "producer-window-size", ActiveMQDefaultConfiguration.getDefaultBridgeProducerWindowSize(), Validators.MINUS_ONE_OR_GT_ZERO);
    long clusterNotificationInterval = getLong(e, "notification-interval", ActiveMQDefaultConfiguration.getDefaultClusterNotificationInterval(), Validators.GT_ZERO);
    int clusterNotificationAttempts = getInteger(e, "notification-attempts", ActiveMQDefaultConfiguration.getDefaultClusterNotificationAttempts(), Validators.GT_ZERO);
    String scaleDownConnector = e.getAttribute("scale-down-connector");
    String discoveryGroupName = null;
    List<String> staticConnectorNames = new ArrayList<>();
    boolean allowDirectConnectionsOnly = false;
    NodeList children = e.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
        Node child = children.item(j);
        if (child.getNodeName().equals("discovery-group-ref")) {
            discoveryGroupName = child.getAttributes().getNamedItem("discovery-group-name").getNodeValue();
        } else if (child.getNodeName().equals("static-connectors")) {
            Node attr = child.getAttributes().getNamedItem("allow-direct-connections-only");
            if (attr != null) {
                allowDirectConnectionsOnly = "true".equalsIgnoreCase(attr.getNodeValue()) || allowDirectConnectionsOnly;
            }
            getStaticConnectors(staticConnectorNames, child);
        }
    }
    ClusterConnectionConfiguration config = new ClusterConnectionConfiguration().setName(name).setAddress(address).setConnectorName(connectorName).setMinLargeMessageSize(minLargeMessageSize).setClientFailureCheckPeriod(clientFailureCheckPeriod).setConnectionTTL(connectionTTL).setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryIntervalMultiplier).setMaxRetryInterval(maxRetryInterval).setInitialConnectAttempts(initialConnectAttempts).setReconnectAttempts(reconnectAttempts).setCallTimeout(callTimeout).setCallFailoverTimeout(callFailoverTimeout).setDuplicateDetection(duplicateDetection).setMessageLoadBalancingType(messageLoadBalancingType).setMaxHops(maxHops).setConfirmationWindowSize(confirmationWindowSize).setProducerindowSize(producerWindowSize).setAllowDirectConnectionsOnly(allowDirectConnectionsOnly).setClusterNotificationInterval(clusterNotificationInterval).setClusterNotificationAttempts(clusterNotificationAttempts);
    if (discoveryGroupName == null) {
        config.setStaticConnectors(staticConnectorNames);
    } else {
        config.setDiscoveryGroupName(discoveryGroupName);
    }
    mainConfig.getClusterConfigurations().add(config);
}

24. FileConfigurationParser#parseClusterConnectionConfigurationURI()

Project: activemq-artemis
File: FileConfigurationParser.java
private void parseClusterConnectionConfigurationURI(final Element e, final Configuration mainConfig) throws Exception {
    String name = e.getAttribute("name");
    String uri = e.getAttribute("address");
    ClusterConnectionConfiguration config = mainConfig.addClusterConfiguration(name, uri);
    System.out.println("Adding cluster connection :: " + config);
}

25. ConfigurationImpl#addClusterConfiguration()

Project: activemq-artemis
File: ConfigurationImpl.java
@Override
public ClusterConnectionConfiguration addClusterConfiguration(String name, String uri) throws Exception {
    ClusterConnectionConfiguration newConfig = new ClusterConnectionConfiguration(new URI(uri)).setName(name);
    clusterConfigurations.add(newConfig);
    return newConfig;
}