public ActiveMQConnectionFactory(final boolean ha, final DiscoveryGroupConfiguration groupConfiguration) { if (ha) { serverLocator = ActiveMQClient.createServerLocatorWithHA(groupConfiguration); } else { serverLocator = ActiveMQClient.createServerLocatorWithoutHA(groupConfiguration); } serverLocator.disableFinalizeCheck(); }
public static synchronized void clearThreadPools() { clearThreadPools(10, TimeUnit.SECONDS); }
/** * Initializes the global thread pools properties from System properties. This method will update the global * thread pool configuration based on defined System properties (or defaults if they are not set). * The System properties key names are as follow: * * ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY="activemq.artemis.client.global.thread.pool.max.size" * ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY="activemq.artemis.client.global.scheduled.thread.pool.core.size * * The min value for max thread pool size is 2. If the value is not -1, but lower than 2, it will be ignored and will default to 2. * A value of -1 configures an unbounded thread pool. * * Note: If global thread pools have already been created, they will not be updated with these new values. */ public static void initializeGlobalThreadPoolProperties() { setGlobalThreadPoolProperties(Integer.valueOf(System.getProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE)), Integer.valueOf(System.getProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))); }
private synchronized void setThreadPools() { if (threadPool != null) { return; } else if (useGlobalPools) { threadPool = ActiveMQClient.getGlobalThreadPool(); scheduledThreadPool = ActiveMQClient.getGlobalScheduledThreadPool(); } else { this.shutdownPool = true; ThreadFactory factory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() { @Override public ThreadFactory run() { return new ActiveMQThreadFactory("ActiveMQ-client-factory-threads-" + System.identityHashCode(this), true, ClientSessionFactoryImpl.class.getClassLoader()); } }); if (threadPoolMaxSize == -1) { threadPool = Executors.newCachedThreadPool(factory); } else { threadPool = new ActiveMQThreadPoolExecutor(0, threadPoolMaxSize, 60L, TimeUnit.SECONDS, factory); } factory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() { @Override public ThreadFactory run() { return new ActiveMQThreadFactory("ActiveMQ-client-factory-pinger-threads-" + System.identityHashCode(this), true, ClientSessionFactoryImpl.class.getClassLoader()); } }); scheduledThreadPool = Executors.newScheduledThreadPool(scheduledThreadPoolMaxSize, factory); } this.updateArrayActor = new Actor<>(threadPool, this::internalUpdateArray); }
public AbstractActiveMQClientResource(String url) { if (url == null) { throw new IllegalArgumentException(String.format("Error creating %s - url cannot be null", this.getClass().getSimpleName())); } try { this.serverLocator = ActiveMQClient.createServerLocator(url); } catch (Exception ex) { throw new RuntimeException(String.format("Error creating %s - createServerLocator( %s ) failed", this.getClass().getSimpleName(), url), ex); } }
@Override protected ServerLocator internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { TransportConfiguration tc = InVMTransportConfigurationSchema.createTransportConfiguration(uri, query, name, "org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"); ServerLocator factory = ActiveMQClient.createServerLocatorWithoutHA(tc); return BeanSupport.setData(uri, factory, query); }
@Test public void testCoreClientWithGlobalThreadPoolParamtersChanged() throws Exception { int originalScheduled = ActiveMQClient.getGlobalScheduledThreadPoolSize(); int originalGlobal = ActiveMQClient.getGlobalThreadPoolSize(); try { ActiveMQClient.setGlobalThreadPoolProperties(2, 1); ActiveMQClient.clearThreadPools(); ServerLocator locator = createNonHALocator(false); testCoreClient(true, locator); } finally { // restoring original value otherwise future tests would be screwed up ActiveMQClient.setGlobalThreadPoolProperties(originalGlobal, originalScheduled); ActiveMQClient.clearThreadPools(); } }
@Test public void testShutdownPoolInUse() throws Exception { ActiveMQClient.setGlobalThreadPoolProperties(10, 1); ActiveMQClient.clearThreadPools(); final CountDownLatch inUse = new CountDownLatch(1); final CountDownLatch neverLeave = new CountDownLatch(1); ActiveMQClient.getGlobalThreadPool().execute(new Runnable() { @Override public void run() { System.err.println("Hello!"); try { inUse.countDown(); neverLeave.await(); } catch (Exception e) { e.printStackTrace(); neverLeave.countDown(); } } }); Assert.assertTrue(inUse.await(10, TimeUnit.SECONDS)); ActiveMQClient.clearThreadPools(100, TimeUnit.MILLISECONDS); Assert.assertTrue(neverLeave.await(10, TimeUnit.SECONDS)); }
@Test public void testStaticPropertiesThreadPoolSettings() throws Exception { int testMaxSize = 999; int testScheduleSize = 9; ActiveMQClient.setGlobalThreadPoolProperties(testMaxSize, testScheduleSize); ActiveMQClient.clearThreadPools(); testSystemPropertiesThreadPoolSettings(testMaxSize, testScheduleSize); }
@Test public void testDualAuthentication() throws Exception { String text = RandomUtil.randomString(); tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true); tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, CLIENT_SIDE_TRUSTSTORE); tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, PASSWORD); tc.getParams().put(TransportConstants.KEYSTORE_PATH_PROP_NAME, CLIENT_SIDE_KEYSTORE); tc.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, PASSWORD); tc.getParams().put(TransportConstants.PORT_PROP_NAME, "61617"); ServerLocator producerLocator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc)); ClientSessionFactory producerSessionFactory = createSessionFactory(producerLocator); ClientSession producerSession = producerSessionFactory.createSession(false, true, true); producerSession.createQueue(DualAuthenticationTest.QUEUE, DualAuthenticationTest.QUEUE, false); ClientProducer producer = producerSession.createProducer(DualAuthenticationTest.QUEUE); ClientMessage message = createTextMessage(producerSession, text); producer.send(message); ServerLocator consumerLocator = addServerLocator(ActiveMQClient.createServerLocator("tcp://localhost:61616")); ClientSessionFactory consumerSessionFactory = createSessionFactory(consumerLocator); ClientSession consumerSession = consumerSessionFactory.createSession("consumer", "consumerPassword", false, true, true, consumerLocator.isPreAcknowledge(), consumerLocator.getAckBatchSize()); ClientConsumer consumer = consumerSession.createConsumer(DualAuthenticationTest.QUEUE); consumerSession.start(); Message m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(text, m.getBodyBuffer().readString()); }
@AfterClass public static void tearDown() { System.clearProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY); System.clearProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY); ActiveMQClient.initializeGlobalThreadPoolProperties(); ActiveMQClient.clearThreadPools(); Assert.assertEquals(ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE, ActiveMQClient.getGlobalThreadPoolSize()); }
ActiveMQClient.initializeGlobalThreadPoolProperties(); if(threadPoolMaxSizeValue == null) { threadPoolMaxSizeValue = ActiveMQClient.getGlobalThreadPoolSize(); scheduledThreadPoolMaxSizeValue = ActiveMQClient.getGlobalScheduledThreadPoolSize(); ActiveMQClient.setGlobalThreadPoolProperties(threadPoolMaxSizeValue, scheduledThreadPoolMaxSizeValue);
@Test public void testInjectPools() throws Exception { ActiveMQClient.clearThreadPools(); ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory()); ActiveMQClient.injectPools(poolExecutor, scheduledThreadPoolExecutor); final CountDownLatch inUse = new CountDownLatch(1); final CountDownLatch neverLeave = new CountDownLatch(1); ActiveMQClient.getGlobalThreadPool().execute(new Runnable() { @Override public void run() { System.err.println("Hello!"); try { inUse.countDown(); neverLeave.await(); } catch (Exception e) { e.printStackTrace(); neverLeave.countDown(); } } }); Assert.assertTrue(inUse.await(10, TimeUnit.SECONDS)); poolExecutor.shutdownNow(); scheduledThreadPoolExecutor.shutdownNow(); Assert.assertTrue(neverLeave.await(10, TimeUnit.SECONDS)); Assert.assertTrue(inUse.await(10, TimeUnit.SECONDS)); Assert.assertTrue(neverLeave.await(10, TimeUnit.SECONDS)); ActiveMQClient.clearThreadPools(100, TimeUnit.MILLISECONDS); }
@After public void cleanup() { // Resets the global thread pool properties back to default. System.setProperties(systemProperties); ActiveMQClient.initializeGlobalThreadPoolProperties(); ActiveMQClient.clearThreadPools(); }
/** * add a locator for a cluster connection. * * @param name the cluster connection name * @param tcConfigs the transport configurations to use */ public void addClusterConnection(SimpleString name, TransportConfiguration[] tcConfigs, ClusterConnectionConfiguration config) { ServerLocatorImpl serverLocator = (ServerLocatorImpl) ActiveMQClient.createServerLocatorWithHA(tcConfigs); configAndAdd(name, serverLocator, config); }
scheduledThreadPoolField.setAccessible(true); ThreadPoolExecutor threadPool = (ThreadPoolExecutor) ActiveMQClient.getGlobalThreadPool();
private static synchronized ExecutorService getInVMExecutor() { if (threadPoolExecutor == null) { if (ActiveMQClient.getGlobalThreadPoolSize() <= -1) { threadPoolExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), ActiveMQThreadFactory.defaultThreadFactory()); } else { threadPoolExecutor = new ActiveMQThreadPoolExecutor(0, ActiveMQClient.getGlobalThreadPoolSize(), 60L, TimeUnit.SECONDS, ActiveMQThreadFactory.defaultThreadFactory()); } } return threadPoolExecutor; }
public AbstractActiveMQClientResource(String url) { if (url == null) { throw new IllegalArgumentException(String.format("Error creating %s - url cannot be null", this.getClass().getSimpleName())); } try { this.serverLocator = ActiveMQClient.createServerLocator(url); } catch (Exception ex) { throw new RuntimeException(String.format("Error creating %s - createServerLocator( %s ) failed", this.getClass().getSimpleName(), url), ex); } }
@Override protected ServerLocator internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { TransportConfiguration tc = InVMTransportConfigurationSchema.createTransportConfiguration(uri, query, name, "org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"); ServerLocator factory = ActiveMQClient.createServerLocatorWithoutHA(tc); return BeanSupport.setData(uri, factory, query); }
private synchronized void setThreadPools() { if (threadPool != null) { return; } else if (useGlobalPools) { threadPool = ActiveMQClient.getGlobalThreadPool(); scheduledThreadPool = ActiveMQClient.getGlobalScheduledThreadPool(); } else { this.shutdownPool = true; ThreadFactory factory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() { @Override public ThreadFactory run() { return new ActiveMQThreadFactory("ActiveMQ-client-factory-threads-" + System.identityHashCode(this), true, ClientSessionFactoryImpl.class.getClassLoader()); } }); if (threadPoolMaxSize == -1) { threadPool = Executors.newCachedThreadPool(factory); } else { threadPool = new ActiveMQThreadPoolExecutor(0, threadPoolMaxSize, 60L, TimeUnit.SECONDS, factory); } factory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() { @Override public ThreadFactory run() { return new ActiveMQThreadFactory("ActiveMQ-client-factory-pinger-threads-" + System.identityHashCode(this), true, ClientSessionFactoryImpl.class.getClassLoader()); } }); scheduledThreadPool = Executors.newScheduledThreadPool(scheduledThreadPoolMaxSize, factory); } this.updateArrayActor = new Actor<>(threadPool, this::internalUpdateArray); }