private static byte[] findFirstMatchingHardwareAddress(List<NetworkInterface> ifaces) { ExecutorService executor = Executors.newFixedThreadPool(ifaces.size(), ActiveMQThreadFactory.defaultThreadFactory()); Collection<Callable<byte[]>> tasks = new ArrayList<>(ifaces.size());
try { ExecutorService executor = Executors.newFixedThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory()); executor.shutdownNow(); } catch (Throwable t) {
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; }
protected final OrderedExecutorFactory getOrderedExecutor() { final ExecutorService executor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()); executorSet.add(executor); return new OrderedExecutorFactory(executor); }
@Override @Before public void setUp() throws Exception { super.setUp(); scheduledExecutor = Executors.newSingleThreadScheduledExecutor(ActiveMQThreadFactory.defaultThreadFactory()); executor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()); }
@Test public void testScheduleNow() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(50, ActiveMQThreadFactory.defaultThreadFactory()); ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1, ActiveMQThreadFactory.defaultThreadFactory()); try { for (int i = 0; i < 100; i++) { // it's better to run the test a few times instead of run millions of messages here internalSchedule(executor, scheduler); } } finally { scheduler.shutdownNow(); executor.shutdownNow(); } }
@Test public void testReferenceWithExecutor() throws Exception { ExecutorService executor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()); internalTestReferenceNoExecutor(executor); executor.shutdown(); }
@Override @Before public void setUp() throws Exception { super.setUp(); pollerExecutor = Executors.newCachedThreadPool(new ActiveMQThreadFactory("ActiveMQ-AIO-poller-pool" + System.identityHashCode(this), false, this.getClass().getClassLoader())); executor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()); }
@Override @Before public void setUp() throws Exception { super.setUp(); executor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()); }
@Before public void setup() throws Exception { serviceRegistry = new ServiceRegistryImpl(); serviceRegistry.setExecutorService(Executors.newFixedThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory())); serviceRegistry.setIOExecutorService(Executors.newFixedThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory())); serviceRegistry.setScheduledExecutorService(Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory())); server = new ActiveMQServerImpl(null, null, null, null, serviceRegistry); server.start(); server.waitForActivation(100, TimeUnit.MILLISECONDS); }
@Override @Before public void setUp() throws Exception { super.setUp(); executor = Executors.newFixedThreadPool(10, ActiveMQThreadFactory.defaultThreadFactory()); factory = new OrderedExecutorFactory(executor); }
@Test public void testStartStop() throws Exception { BufferHandler handler = new BufferHandler() { @Override public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) { } }; Map<String, Object> params = new HashMap<>(); NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory())); connector.start(); Assert.assertTrue(connector.isStarted()); connector.close(); Assert.assertFalse(connector.isStarted()); }
@Before public void before() throws FileNotFoundException, IOException { createUsers(); createGroups(); options = new HashMap<>(); options.put("reload", "true"); // Used to simplify reproduction of the // race condition options.put("org.apache.activemq.jaas.properties.user", USERS_FILE); options.put("org.apache.activemq.jaas.properties.role", ROLES_FILE); options.put("baseDir", temp.getRoot().getAbsolutePath()); errors = new ArrayBlockingQueue<>(processorCount()); pool = Executors.newFixedThreadPool(processorCount(), ActiveMQThreadFactory.defaultThreadFactory()); callback = new JaasCallbackHandler(USERNAME, PASSWORD, null); }
@Test public void testCoreClientWithInjectedThreadPools() throws Exception { ExecutorService threadPool = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()); ScheduledThreadPoolExecutor scheduledThreadPool = new ScheduledThreadPoolExecutor(10); ServerLocator locator = createNonHALocator(false); boolean setThreadPools = locator.setThreadPools(threadPool, scheduledThreadPool); assertTrue(setThreadPools); testCoreClient(true, locator); threadPool.shutdown(); scheduledThreadPool.shutdown(); threadPool.awaitTermination(60, TimeUnit.SECONDS); scheduledThreadPool.awaitTermination(60, TimeUnit.SECONDS); }
@Test public void testBadProtocol() throws Exception { BufferHandler handler = new BufferHandler() { @Override public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) { } }; Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true); params.put(TransportConstants.ENABLED_PROTOCOLS_PROP_NAME, "myBadProtocol"); NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory())); connector.start(); Assert.assertTrue(connector.isStarted()); Assert.assertNull(connector.createConnection()); connector.close(); Assert.assertFalse(connector.isStarted()); }
@Test public void testBadCipherSuite() throws Exception { BufferHandler handler = new BufferHandler() { @Override public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) { } }; Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true); params.put(TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME, "myBadCipherSuite"); NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory())); connector.start(); Assert.assertTrue(connector.isStarted()); Assert.assertNull(connector.createConnection()); connector.close(); Assert.assertFalse(connector.isStarted()); }
@Override @Before public void setUp() throws Exception { super.setUp(); executorService = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()); Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true); params.put(TransportConstants.SSL_PROVIDER, TransportConstants.OPENSSL_PROVIDER); params.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "openssl-server-side-keystore.jks"); params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "secureexample"); params.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "openssl-server-side-truststore.jks"); params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "secureexample"); params.put(TransportConstants.NEED_CLIENT_AUTH_PROP_NAME, true); ConfigurationImpl config = createBasicConfig().addAcceptorConfiguration(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params, "nettySSL")); server = createServer(false, config); server.start(); waitForServerToStart(server); }
@Test public void tesActiveMQSystemProperties() throws Exception { BufferHandler handler = new BufferHandler() { @Override public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) { } }; Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true); NettyConnector connector = new NettyConnector(params, handler, listener, executorService, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory())); System.setProperty(NettyConnector.ACTIVEMQ_KEYSTORE_PATH_PROP_NAME, "openssl-client-side-keystore.jks"); System.setProperty(NettyConnector.ACTIVEMQ_KEYSTORE_PASSWORD_PROP_NAME, "secureexample"); System.setProperty(NettyConnector.ACTIVEMQ_TRUSTSTORE_PATH_PROP_NAME, "openssl-client-side-truststore.jks"); System.setProperty(NettyConnector.ACTIVEMQ_TRUSTSTORE_PASSWORD_PROP_NAME, "secureexample"); connector.start(); Assert.assertTrue(connector.isStarted()); Connection c = connector.createConnection(); assertNotNull(c); connector.close(); Assert.assertFalse(connector.isStarted()); }
@Test public void testReferenceValidExecutorUsed() throws Exception { ExecutorService executor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory()); LatchRunner runner = new LatchRunner(); ReferenceCounterUtil counter = new ReferenceCounterUtil(runner, executor); counter.increment(); counter.decrement(); runner.latch.await(5, TimeUnit.SECONDS); assertNotSame(runner.lastThreadUsed, Thread.currentThread()); runner.latch.setCount(1); runner.lastThreadUsed = Thread.currentThread(); // force a recheck counter.check(); runner.latch.await(5, TimeUnit.SECONDS); assertNotSame(runner.lastThreadUsed, Thread.currentThread()); executor.shutdown(); }
@Override @Before public void setUp() throws Exception { super.setUp(); executor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()); server = createServer(createBasicConfig() .setPersistenceEnabled(false) .setAddressesSettings(Collections.singletonMap("#", new AddressSettings() .setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE) .setPageSizeBytes(50000) .setMaxSizeBytes(404850))) .setAcceptorConfigurations(Collections.singleton(new TransportConfiguration(NettyAcceptorFactory.class.getName())))); server.start(); cf = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616", "cf"); queue = ActiveMQJMSClient.createQueue("simple"); barrierLatch = new CyclicBarrier(PRODUCERS + 1); runnersLatch = new CountDownLatch(PRODUCERS + 1); msgReceived = new AtomicLong(0); msgSent = new AtomicLong(0); }