org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal

Here are the examples of the java api class org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal taken from open source projects.

1. ServerLocatorConnectTest#testMultipleConnectorSingleServerNoConnectAttemptReconnect()

Project: activemq-artemis
File: ServerLocatorConnectTest.java
@Test
public void testMultipleConnectorSingleServerNoConnectAttemptReconnect() throws Exception {
    ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(5, isNetty())));
    locator.setReconnectAttempts(-1);
    CountDownLatch countDownLatch = new CountDownLatch(1);
    Connector target = new Connector(locator, countDownLatch);
    Thread t = new Thread(target);
    t.start();
    //let them get started
    Thread.sleep(500);
    locator.close();
    assertTrue(countDownLatch.await(5, TimeUnit.SECONDS));
    assertNull(target.csf);
}

2. ServerLocatorConnectTest#testMultipleConnectorSingleServerNoConnect()

Project: activemq-artemis
File: ServerLocatorConnectTest.java
@Test
public void testMultipleConnectorSingleServerNoConnect() throws Exception {
    ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(5, isNetty())));
    ClientSessionFactoryInternal csf = null;
    try {
        csf = locator.connect();
    } catch (ActiveMQNotConnectedException nce) {
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQException);
        fail("Invalid Exception type:" + ((ActiveMQException) e).getType());
    }
    assertNull(csf);
    locator.close();
}

3. SharedNothingLiveActivation#getLocator()

Project: activemq-artemis
File: SharedNothingLiveActivation.java
private ServerLocatorInternal getLocator(ClusterConnectionConfiguration config) throws ActiveMQException {
    ServerLocatorInternal locator;
    if (config.getDiscoveryGroupName() != null) {
        DiscoveryGroupConfiguration dg = activeMQServer.getConfiguration().getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
        if (dg == null) {
            throw ActiveMQMessageBundle.BUNDLE.noDiscoveryGroupFound(dg);
        }
        locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(dg);
    } else {
        TransportConfiguration[] tcConfigs = config.getStaticConnectors() != null ? connectorNameListToArray(config.getStaticConnectors()) : null;
        locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(tcConfigs);
    }
    return locator;
}

4. ClusterConnectionImpl#createNewRecord()

Project: activemq-artemis
File: ClusterConnectionImpl.java
private void createNewRecord(final long eventUID, final String targetNodeID, final TransportConfiguration connector, final SimpleString queueName, final Queue queue, final boolean start) throws Exception {
    String nodeId;
    synchronized (this) {
        if (!started) {
            return;
        }
        if (serverLocator == null) {
            return;
        }
        nodeId = serverLocator.getNodeID();
    }
    final ServerLocatorInternal targetLocator = new ServerLocatorImpl(topology, true, connector);
    targetLocator.setReconnectAttempts(0);
    targetLocator.setInitialConnectAttempts(0);
    targetLocator.setClientFailureCheckPeriod(clientFailureCheckPeriod);
    targetLocator.setConnectionTTL(connectionTTL);
    targetLocator.setInitialConnectAttempts(0);
    targetLocator.setConfirmationWindowSize(confirmationWindowSize);
    targetLocator.setBlockOnDurableSend(!useDuplicateDetection);
    targetLocator.setBlockOnNonDurableSend(!useDuplicateDetection);
    targetLocator.setRetryInterval(retryInterval);
    targetLocator.setMaxRetryInterval(maxRetryInterval);
    targetLocator.setRetryIntervalMultiplier(retryIntervalMultiplier);
    targetLocator.setMinLargeMessageSize(minLargeMessageSize);
    // No producer flow control on the bridges, as we don't want to lock the queues
    targetLocator.setProducerWindowSize(-1);
    targetLocator.setAfterConnectionInternalListener(this);
    serverLocator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(serverLocator));
    targetLocator.setNodeID(nodeId);
    targetLocator.setClusterTransportConfiguration(serverLocator.getClusterTransportConfiguration());
    if (retryInterval > 0) {
        targetLocator.setRetryInterval(retryInterval);
    }
    targetLocator.disableFinalizeCheck();
    targetLocator.addIncomingInterceptor(new IncomingInterceptorLookingForExceptionMessage(manager, executorFactory.getExecutor()));
    MessageFlowRecordImpl record = new MessageFlowRecordImpl(targetLocator, eventUID, targetNodeID, connector, queueName, queue);
    ClusterConnectionBridge bridge = new ClusterConnectionBridge(this, manager, targetLocator, serverLocator, initialConnectAttempts, reconnectAttempts, retryInterval, retryIntervalMultiplier, maxRetryInterval, nodeManager.getUUID(), record.getEventUID(), record.getTargetNodeID(), record.getQueueName(), record.getQueue(), executorFactory.getExecutor(), null, null, scheduledExecutor, null, useDuplicateDetection, clusterUser, clusterPassword, server.getStorageManager(), managementService.getManagementAddress(), managementService.getManagementNotificationAddress(), record, record.getConnector());
    targetLocator.setIdentity("(Cluster-connection-bridge::" + bridge.toString() + "::" + this.toString() + ")");
    if (logger.isDebugEnabled()) {
        logger.debug("creating record between " + this.connector + " and " + connector + bridge);
    }
    record.setBridge(bridge);
    records.put(targetNodeID, record);
    if (start) {
        bridge.start();
    }
}

5. ClusterManager#deployBridge()

Project: activemq-artemis
File: ClusterManager.java
public synchronized void deployBridge(final BridgeConfiguration config) throws Exception {
    if (config.getName() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNotUnique();
        return;
    }
    if (config.getQueueName() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNoQueue(config.getName());
        return;
    }
    if (config.getForwardingAddress() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName());
    }
    if (bridges.containsKey(config.getName())) {
        ActiveMQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName());
        return;
    }
    Transformer transformer = server.getServiceRegistry().getBridgeTransformer(config.getName(), config.getTransformerClassName());
    Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName()));
    if (binding == null) {
        ActiveMQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName());
        return;
    }
    Queue queue = (Queue) binding.getBindable();
    ServerLocatorInternal serverLocator;
    if (config.getDiscoveryGroupName() != null) {
        DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
        if (discoveryGroupConfiguration == null) {
            ActiveMQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName());
            return;
        }
        if (config.isHA()) {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
        } else {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
        }
    } else {
        TransportConfiguration[] tcConfigs = configuration.getTransportConfigurations(config.getStaticConnectors());
        if (tcConfigs == null) {
            ActiveMQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName());
            return;
        }
        if (config.isHA()) {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(tcConfigs);
        } else {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(tcConfigs);
        }
    }
    serverLocator.setIdentity("Bridge " + config.getName());
    serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());
    // We are going to manually retry on the bridge in case of failure
    serverLocator.setReconnectAttempts(0);
    serverLocator.setInitialConnectAttempts(0);
    serverLocator.setRetryInterval(config.getRetryInterval());
    serverLocator.setMaxRetryInterval(config.getMaxRetryInterval());
    serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
    serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
    serverLocator.setConnectionTTL(config.getConnectionTTL());
    serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize());
    serverLocator.setProducerWindowSize(config.getProducerWindowSize());
    // This will be set to 30s unless it's changed from embedded / testing
    // there is no reason to exception the config for this timeout
    // since the Bridge is supposed to be non-blocking and fast
    // We may expose this if we find a good use case
    serverLocator.setCallTimeout(config.getCallTimeout());
    serverLocator.addIncomingInterceptor(new IncomingInterceptorLookingForExceptionMessage(this, executor));
    if (!config.isUseDuplicateDetection()) {
        logger.debug("Bridge " + config.getName() + " is configured to not use duplicate detecion, it will send messages synchronously");
    }
    clusterLocators.add(serverLocator);
    Bridge bridge = new BridgeImpl(serverLocator, config.getInitialConnectAttempts(), config.getReconnectAttempts(), config.getReconnectAttemptsOnSameNode(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), nodeManager.getUUID(), new SimpleString(config.getName()), queue, executorFactory.getExecutor(), FilterImpl.createFilter(config.getFilterString()), SimpleString.toSimpleString(config.getForwardingAddress()), scheduledExecutor, transformer, config.isUseDuplicateDetection(), config.getUser(), config.getPassword(), server.getStorageManager());
    bridges.put(config.getName(), bridge);
    managementService.registerBridge(bridge, config);
    bridge.start();
}

6. ServerLocatorConnectTest#testMultipleConnectorSingleServerConnectReconnect()

Project: activemq-artemis
File: ServerLocatorConnectTest.java
@Test
public void testMultipleConnectorSingleServerConnectReconnect() throws Exception {
    ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())));
    locator.setReconnectAttempts(-1);
    ClientSessionFactoryInternal csf = locator.connect();
    assertNotNull(csf);
    assertEquals(csf.numConnections(), 1);
    locator.close();
}

7. ServerLocatorConnectTest#testMultipleConnectorSingleServerConnect()

Project: activemq-artemis
File: ServerLocatorConnectTest.java
@Test
public void testMultipleConnectorSingleServerConnect() throws Exception {
    ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())));
    ClientSessionFactoryInternal csf = locator.connect();
    assertNotNull(csf);
    assertEquals(csf.numConnections(), 1);
    locator.close();
}

8. ServerLocatorConnectTest#testSingleConnectorSingleServerConnect()

Project: activemq-artemis
File: ServerLocatorConnectTest.java
@Test
public void testSingleConnectorSingleServerConnect() throws Exception {
    ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty())));
    ClientSessionFactoryInternal csf = locator.connect();
    assertNotNull(csf);
    assertEquals(csf.numConnections(), 1);
    locator.close();
}

9. NonHATopologyTest#internalTest()

Project: activemq-artemis
File: NonHATopologyTest.java
public void internalTest(boolean isNetty) throws Exception {
    ActiveMQServer server = null;
    ServerLocatorInternal locator = null;
    try {
        server = createServer(false, isNetty);
        if (!isNetty) {
            server.getConfiguration().getAcceptorConfigurations().add(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY));
            server.getConfiguration().getConnectorConfigurations().put("netty", new TransportConfiguration(NETTY_CONNECTOR_FACTORY));
            ArrayList<String> list = new ArrayList<>();
            list.add("netty");
            Configuration config = server.getConfiguration();
            config.getClusterConfigurations().add(new ClusterConnectionConfiguration().setName("tst").setAddress("jms").setConnectorName("netty").setRetryInterval(1000).setConfirmationWindowSize(1000).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(list).setAllowDirectConnectionsOnly(true));
        }
        server.start();
        locator = (ServerLocatorInternal) createNonHALocator(isNetty);
        ClientSessionFactory factory = createSessionFactory(locator);
        Topology topology = locator.getTopology();
        assertEquals(1, topology.getMembers().size());
        factory.close();
        if (!isNetty) {
            TopologyMemberImpl member = topology.getMembers().iterator().next();
            if (isNetty) {
                assertEquals(NettyConnectorFactory.class.getName(), member.getLive().getFactoryClassName());
            } else {
                assertEquals(InVMConnectorFactory.class.getName(), member.getLive().getFactoryClassName());
            }
        }
    } finally {
        try {
            locator.close();
        } catch (Exception ignored) {
        }
        try {
            server.stop();
        } catch (Exception ignored) {
        }
        server = null;
        locator = null;
    }
}

10. 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;
    }
}

11. ClusterManager#stop()

Project: activemq-artemis
File: ClusterManager.java
@Override
public void stop() throws Exception {
    haManager.stop();
    synchronized (this) {
        if (state == State.STOPPED || state == State.STOPPING) {
            return;
        }
        state = State.STOPPING;
        clusterController.stop();
        for (BroadcastGroup group : broadcastGroups.values()) {
            group.stop();
            managementService.unregisterBroadcastGroup(group.getName());
        }
        broadcastGroups.clear();
        for (ClusterConnection clusterConnection : clusterConnections.values()) {
            clusterConnection.stop();
            managementService.unregisterCluster(clusterConnection.getName().toString());
        }
        for (Bridge bridge : bridges.values()) {
            bridge.stop();
            managementService.unregisterBridge(bridge.getName().toString());
        }
        bridges.clear();
    }
    for (ServerLocatorInternal clusterLocator : clusterLocators) {
        try {
            clusterLocator.close();
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.errorClosingServerLocator(e, clusterLocator);
        }
    }
    clusterLocators.clear();
    state = State.STOPPED;
    clearClusterConnections();
}

12. ClusterController#stop()

Project: activemq-artemis
File: ClusterController.java
@Override
public void stop() throws Exception {
    //close all the locators
    for (ServerLocatorInternal serverLocatorInternal : locators.values()) {
        serverLocatorInternal.close();
    }
    //stop the quorum manager
    quorumManager.stop();
    started = false;
}

13. ClusterController#start()

Project: activemq-artemis
File: ClusterController.java
@Override
public void start() throws Exception {
    if (started)
        return;
    //set the default locator that will be used to connecting to the default cluster.
    defaultLocator = locators.get(defaultClusterConnectionName);
    //create a locator for replication, either the default or the specified if not set
    if (replicatedClusterName != null && !replicatedClusterName.equals(defaultClusterConnectionName)) {
        replicationLocator = locators.get(replicatedClusterName);
        if (replicationLocator == null) {
            ActiveMQServerLogger.LOGGER.noClusterConnectionForReplicationCluster();
            replicationLocator = defaultLocator;
        }
    } else {
        replicationLocator = defaultLocator;
    }
    //latch so we know once we are connected
    replicationClusterConnectedLatch = new CountDownLatch(1);
    //and add the quorum manager as a topology listener
    defaultLocator.addClusterTopologyListener(quorumManager);
    //start the quorum manager
    quorumManager.start();
    started = true;
    //connect all the locators in a separate thread
    for (ServerLocatorInternal serverLocatorInternal : locators.values()) {
        if (serverLocatorInternal.isConnectable()) {
            executor.execute(new ConnectRunnable(serverLocatorInternal));
        }
    }
}