Search in sources :

Example 1 with ServerLocatorImpl

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

the class ClientThreadPoolsTest method testSystemPropertiesThreadPoolSettings.

private void testSystemPropertiesThreadPoolSettings(int expectedMax, int expectedScheduled) throws Exception {
    ServerLocatorImpl serverLocator = new ServerLocatorImpl(false);
    serverLocator.isUseGlobalPools();
    Method setThreadPools = ServerLocatorImpl.class.getDeclaredMethod("setThreadPools");
    setThreadPools.setAccessible(true);
    setThreadPools.invoke(serverLocator);
    // TODO: I would get this from the ActiveMQClient
    Field threadPoolField = ServerLocatorImpl.class.getDeclaredField("threadPool");
    Field scheduledThreadPoolField = ServerLocatorImpl.class.getDeclaredField("scheduledThreadPool");
    threadPoolField.setAccessible(true);
    scheduledThreadPoolField.setAccessible(true);
    ThreadPoolExecutor threadPool = (ThreadPoolExecutor) ActiveMQClient.getGlobalThreadPool();
    final CountDownLatch doneMax = new CountDownLatch(expectedMax);
    final CountDownLatch latch = new CountDownLatch(1);
    // we will schedule 3 * max, so all runnables should execute
    final CountDownLatch latchTotal = new CountDownLatch(expectedMax * 3);
    final AtomicInteger errors = new AtomicInteger(0);
    // Set this to true if you need to debug why executions are not being performed.
    final boolean debugExecutions = false;
    for (int i = 0; i < expectedMax * 3; i++) {
        final int localI = i;
        threadPool.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    if (debugExecutions) {
                        System.out.println("runnable " + localI);
                    }
                    doneMax.countDown();
                    latch.await();
                    latchTotal.countDown();
                } catch (Exception e) {
                    errors.incrementAndGet();
                } finally {
                    if (debugExecutions) {
                        System.out.println("done " + localI);
                    }
                }
            }
        });
    }
    Assert.assertTrue(doneMax.await(5, TimeUnit.SECONDS));
    latch.countDown();
    Assert.assertTrue(latchTotal.await(5, TimeUnit.SECONDS));
    ScheduledThreadPoolExecutor scheduledThreadPool = (ScheduledThreadPoolExecutor) scheduledThreadPoolField.get(serverLocator);
    assertEquals(expectedMax, threadPool.getMaximumPoolSize());
    assertEquals(expectedScheduled, scheduledThreadPool.getCorePoolSize());
}
Also used : Field(java.lang.reflect.Field) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ServerLocatorImpl(org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl) Method(java.lang.reflect.Method) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with ServerLocatorImpl

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

the class ClientThreadPoolsTest method testThreadPoolInjection.

@Test
public void testThreadPoolInjection() throws Exception {
    ServerLocator serverLocator = new ServerLocatorImpl(false);
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, 1, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
    ScheduledThreadPoolExecutor scheduledThreadPool = new ScheduledThreadPoolExecutor(1);
    serverLocator.setThreadPools(threadPool, scheduledThreadPool);
    Field threadPoolField = ServerLocatorImpl.class.getDeclaredField("threadPool");
    Field scheduledThreadPoolField = ServerLocatorImpl.class.getDeclaredField("scheduledThreadPool");
    Method initialise = ServerLocatorImpl.class.getDeclaredMethod("initialise");
    initialise.setAccessible(true);
    initialise.invoke(serverLocator);
    threadPoolField.setAccessible(true);
    scheduledThreadPoolField.setAccessible(true);
    ThreadPoolExecutor tpe = (ThreadPoolExecutor) threadPoolField.get(serverLocator);
    ScheduledThreadPoolExecutor stpe = (ScheduledThreadPoolExecutor) scheduledThreadPoolField.get(serverLocator);
    assertEquals(threadPool, tpe);
    assertEquals(scheduledThreadPool, stpe);
}
Also used : Field(java.lang.reflect.Field) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ServerLocatorImpl(org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Method(java.lang.reflect.Method) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 3 with ServerLocatorImpl

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

the class ClusterConnectionImpl method createNewRecord.

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 by default, as we don't want to lock the queues
    targetLocator.setProducerWindowSize(this.producerWindowSize);
    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, managementService.getManagementAddress(), managementService.getManagementNotificationAddress(), record, record.getConnector(), storeAndForwardPrefix);
    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();
    }
    if (!ConfigurationImpl.checkoutDupCacheSize(serverLocator.getConfirmationWindowSize(), server.getConfiguration().getIDCacheSize())) {
        ActiveMQServerLogger.LOGGER.duplicateCacheSizeWarning(server.getConfiguration().getIDCacheSize(), serverLocator.getConfirmationWindowSize());
    }
}
Also used : IncomingInterceptorLookingForExceptionMessage(org.apache.activemq.artemis.core.server.cluster.ClusterManager.IncomingInterceptorLookingForExceptionMessage) ServerLocatorImpl(org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)

Example 4 with ServerLocatorImpl

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

the class ConnectionFactoryURITest method testWeirdEncodingsOnIP.

@Test
public void testWeirdEncodingsOnIP() throws Exception {
    // This is to make things worse. Having & and = on the property shouldn't break it
    final String BROKEN_PROPERTY = "e80::56ee:75ff:fe53:e6a7%25enp0s25&host=[fe80::56ee:75ff:fe53:e6a7]#";
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.LOCAL_ADDRESS_PROP_NAME, BROKEN_PROPERTY);
    TransportConfiguration configuration = new TransportConfiguration(NettyConnector.class.getName(), params);
    ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, configuration);
    URI uri = factory.toURI();
    ActiveMQConnectionFactory newFactory = ActiveMQJMSClient.createConnectionFactory(uri.toString(), "somefactory");
    TransportConfiguration[] initialConnectors = ((ServerLocatorImpl) newFactory.getServerLocator()).getInitialConnectors();
    Assert.assertEquals(1, initialConnectors.length);
    Assert.assertEquals(BROKEN_PROPERTY, initialConnectors[0].getParams().get(TransportConstants.LOCAL_ADDRESS_PROP_NAME).toString());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) HashMap(java.util.HashMap) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ServerLocatorImpl(org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) URI(java.net.URI) Test(org.junit.Test)

Example 5 with ServerLocatorImpl

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

the class URITest method testParseURIs.

@Test
public void testParseURIs() throws Throwable {
    ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false", "some name");
    Assert.assertEquals(2, ((ServerLocatorImpl) factory.getServerLocator()).getInitialConnectors().length);
    ActiveMQConnectionFactory factory2 = new ActiveMQConnectionFactory("(tcp://localhost:61614,tcp://localhost:61616)?blockOnDurableSend=false");
    Assert.assertEquals(2, ((ServerLocatorImpl) factory2.getServerLocator()).getInitialConnectors().length);
    ServerLocator locator = ServerLocatorImpl.newLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false");
    Assert.assertEquals(2, ((ServerLocatorImpl) locator).getInitialConnectors().length);
    ServerLocator locator2 = ActiveMQClient.createServerLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false");
    Assert.assertEquals(2, ((ServerLocatorImpl) locator2).getInitialConnectors().length);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ServerLocatorImpl(org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

ServerLocatorImpl (org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl)11 Test (org.junit.Test)6 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)3 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)2 ClusterControl (org.apache.activemq.artemis.core.server.cluster.ClusterControl)2 ClusterController (org.apache.activemq.artemis.core.server.cluster.ClusterController)2 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)2 URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Connection (javax.jms.Connection)1 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)1 ActiveMQClusterSecurityException (org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1