@Override public void run() { try { serverLocator.connect(); if (serverLocator == replicationLocator) { replicationClusterConnectedLatch.countDown(); } } catch (ActiveMQException e) { if (!started) { return; } server.getScheduledPool().schedule(this, serverLocator.getRetryInterval(), TimeUnit.MILLISECONDS); } } }
@Override public ConnectionEntry createConnectionEntry(final Acceptor acceptorUsed, final Connection connection) { StompConnection conn = new StompConnection(acceptorUsed, connection, this, server.getScheduledPool(), server.getExecutorFactory()); // Note that STOMP 1.0 has no heartbeat, so if connection ttl is non zero, data must continue to be sent or connection // will be timed out and closed! String ttlStr = (String) acceptorUsed.getConfiguration().get(TransportConstants.CONNECTION_TTL); Long ttl = ttlStr == null ? null : Long.valueOf(ttlStr); if (ttl != null) { if (ttl > 0) { return new ConnectionEntry(conn, null, System.currentTimeMillis(), ttl); } throw BUNDLE.negativeConnectionTTL(ttl); } ttl = server.getConfiguration().getConnectionTTLOverride(); if (ttl != -1) { return new ConnectionEntry(conn, null, System.currentTimeMillis(), ttl); } else { // Default to 1 minute - which is same as core protocol return new ConnectionEntry(conn, null, System.currentTimeMillis(), 1 * 60 * 1000); } }
@Override public ConnectionEntry createConnectionEntry(final Acceptor acceptorUsed, final Connection connection) { StompConnection conn = new StompConnection(acceptorUsed, connection, this, server.getScheduledPool(), server.getExecutorFactory()); // Note that STOMP 1.0 has no heartbeat, so if connection ttl is non zero, data must continue to be sent or connection // will be timed out and closed! String ttlStr = (String) acceptorUsed.getConfiguration().get(TransportConstants.CONNECTION_TTL); Long ttl = ttlStr == null ? null : Long.valueOf(ttlStr); if (ttl != null) { if (ttl > 0) { return new ConnectionEntry(conn, null, System.currentTimeMillis(), ttl); } throw BUNDLE.negativeConnectionTTL(ttl); } ttl = server.getConfiguration().getConnectionTTLOverride(); if (ttl != -1) { return new ConnectionEntry(conn, null, System.currentTimeMillis(), ttl); } else { // Default to 1 minute - which is same as core protocol return new ConnectionEntry(conn, null, System.currentTimeMillis(), 1 * 60 * 1000); } }
@Override public synchronized void startAddressQueueScanner() { if (addressQueueReaperPeriod > 0) { if (addressQueueReaperRunnable != null) addressQueueReaperRunnable.stop(); addressQueueReaperRunnable = new AddressQueueReaper(server.getScheduledPool(), server.getExecutorFactory().getExecutor(), addressQueueReaperPeriod, TimeUnit.MILLISECONDS, false); addressQueueReaperRunnable.start(); } }
/** * The expiry scanner can't be started until the whole server has been started other wise you may get races */ @Override public synchronized void startExpiryScanner() { if (expiryReaperPeriod > 0) { if (expiryReaperRunnable != null) expiryReaperRunnable.stop(); expiryReaperRunnable = new ExpiryReaper(server.getScheduledPool(), server.getExecutorFactory().getExecutor(), expiryReaperPeriod, TimeUnit.MILLISECONDS, false); expiryReaperRunnable.start(); } }
@Override public void start() throws Exception { scheduledExecutorService.submit(() -> { ActiveMQAMQPLogger.LOGGER.infov("Starting connector {0}", name); ProtonClientProtocolManager protocolManager = new ProtonClientProtocolManager(new ProtonProtocolManagerFactory(), server); NettyConnector connector = new NettyConnector(connectorConfig, lifecycleHandler, AMQPConnectorService.this, closeExecutor, threadPool, server.getScheduledPool(), protocolManager); connector.start(); Connection connection = connector.createConnection(); if (connection != null) { started = true; } else { ActiveMQAMQPLogger.LOGGER.infov("Error starting connector {0}, retrying in 5 seconds", name); scheduledExecutorService.schedule(() -> { start(); return true; }, 5, TimeUnit.SECONDS); } }); }
@Test public void testServerDoesNotShutdownSuppliedThreadPoolsOnStop() throws Exception { server.stop(); ScheduledExecutorService scheduledExecutorService = server.getScheduledPool(); Field field = server.getExecutorFactory().getClass().getDeclaredField("parent"); field.setAccessible(true); ExecutorService threadPool = (ExecutorService) field.get(server.getExecutorFactory()); // Ensure that references to the supplied Thread Pools still exist after shutdown. assertNotNull(threadPool); assertNotNull(scheduledExecutorService); // Ensure that ActiveMQ Artemis does not shutdown supplied thread pools. assertFalse(threadPool.isShutdown()); assertFalse(scheduledExecutorService.isShutdown()); }
@Test public void testSuppliedThreadPoolsAreCorrectlySet() throws Exception { assertEquals(serviceRegistry.getScheduledExecutorService(), server.getScheduledPool()); // To check the Executor is what we expect we must reflectively inspect the OrderedExecutorFactory. Field field = server.getExecutorFactory().getClass().getDeclaredField("parent"); field.setAccessible(true); assertEquals(serviceRegistry.getExecutorService(), field.get(server.getExecutorFactory())); }
public ActiveMQProtonRemotingConnection createConnection(ProtonProtocolManager protocolManager, Connection connection, Optional<EventHandler> eventHandler, ClientSASLFactory clientSASLFactory) { AMQPConnectionCallback connectionCallback = new AMQPConnectionCallback(protocolManager, connection, server.getExecutorFactory().getExecutor(), server); Executor executor = server.getExecutorFactory().getExecutor(); AMQPConnectionContext amqpConnection = new AMQPConnectionContext(protocolManager, connectionCallback, containerId, ttl, protocolManager.getMaxFrameSize(), AMQPConstants.Connection.DEFAULT_CHANNEL_MAX, useCoreSubscriptionNaming, server.getScheduledPool(), false, clientSASLFactory, connectionProperties); eventHandler.ifPresent(amqpConnection::addEventHandler); ActiveMQProtonRemotingConnection delegate = new ActiveMQProtonRemotingConnection(protocolManager, amqpConnection, connection, executor); delegate.addFailureListener(connectionCallback); delegate.addCloseListener(connectionCallback); connectionCallback.setProtonConnectionDelegate(delegate); return delegate; } }
@Test public void testJobsGetScheduledToSuppliedThreadPool() throws Exception { server.stop(); ScheduledThreadPoolExecutor scheduledExecutorService = (ScheduledThreadPoolExecutor) server.getScheduledPool(); Field field = server.getExecutorFactory().getClass().getDeclaredField("parent"); field.setAccessible(true); ThreadPoolExecutor threadPool = (ThreadPoolExecutor) field.get(server.getExecutorFactory()); // Check jobs are getting scheduled and executed. assertTrue(threadPool.getCompletedTaskCount() > 0); assertTrue(scheduledExecutorService.getTaskCount() > 0); } }
public ActiveMQProtonRemotingConnection createConnection(ProtonProtocolManager protocolManager, Connection connection, Optional<EventHandler> eventHandler, ClientSASLFactory clientSASLFactory) { AMQPConnectionCallback connectionCallback = new AMQPConnectionCallback(protocolManager, connection, server.getExecutorFactory().getExecutor(), server); Executor executor = server.getExecutorFactory().getExecutor(); AMQPConnectionContext amqpConnection = new AMQPConnectionContext(protocolManager, connectionCallback, containerId, ttl, protocolManager.getMaxFrameSize(), AMQPConstants.Connection.DEFAULT_CHANNEL_MAX, useCoreSubscriptionNaming, server.getScheduledPool(), false, clientSASLFactory, connectionProperties); eventHandler.ifPresent(amqpConnection::addEventHandler); ActiveMQProtonRemotingConnection delegate = new ActiveMQProtonRemotingConnection(protocolManager, amqpConnection, connection, executor); delegate.addFailureListener(connectionCallback); delegate.addCloseListener(connectionCallback); connectionCallback.setProtonConnectionDelegate(delegate); return delegate; } }
public ActiveMQProtonRemotingConnection createConnection(ProtonProtocolManager protocolManager, Connection connection, Optional<EventHandler> eventHandler, ClientSASLFactory clientSASLFactory) { AMQPConnectionCallback connectionCallback = new AMQPConnectionCallback(protocolManager, connection, server.getExecutorFactory().getExecutor(), server); Executor executor = server.getExecutorFactory().getExecutor(); AMQPConnectionContext amqpConnection = new AMQPConnectionContext(protocolManager, connectionCallback, containerId, ttl, protocolManager.getMaxFrameSize(), AMQPConstants.Connection.DEFAULT_CHANNEL_MAX, useCoreSubscriptionNaming, server.getScheduledPool(), false, clientSASLFactory, connectionProperties); eventHandler.ifPresent(amqpConnection::addEventHandler); ActiveMQProtonRemotingConnection delegate = new ActiveMQProtonRemotingConnection(protocolManager, amqpConnection, connection, executor); delegate.addFailureListener(connectionCallback); delegate.addCloseListener(connectionCallback); connectionCallback.setProtonConnectionDelegate(delegate); return delegate; } }
public OpenWireProtocolManager(OpenWireProtocolManagerFactory factory, ActiveMQServer server) { this.factory = factory; this.server = server; this.wireFactory = new OpenWireFormatFactory(); // preferred prop, should be done via config wireFactory.setCacheEnabled(false); advisoryProducerId.setConnectionId(ID_GENERATOR.generateId()); scheduledPool = server.getScheduledPool(); this.wireFormat = (OpenWireFormat) wireFactory.createWireFormat(); final ClusterManager clusterManager = this.server.getClusterManager(); ClusterConnection cc = clusterManager.getDefaultConnection(null); if (cc != null) { cc.addClusterTopologyListener(this); } }
private void configAndAdd(SimpleString name, ServerLocatorInternal serverLocator, ClusterConnectionConfiguration config) { serverLocator.setConnectionTTL(config.getConnectionTTL()); serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod()); //if the cluster isn't available we want to hang around until it is serverLocator.setReconnectAttempts(config.getReconnectAttempts()); serverLocator.setInitialConnectAttempts(config.getInitialConnectAttempts()); serverLocator.setRetryInterval(config.getRetryInterval()); serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier()); serverLocator.setMaxRetryInterval(config.getMaxRetryInterval()); //this is used for replication so need to use the server packet decoder serverLocator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(serverLocator)); serverLocator.setThreadPools(server.getThreadPool(), server.getScheduledPool()); try { serverLocator.initialize(); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } locators.put(name, serverLocator); }
NettyConnector connector = new NettyConnector(config, lifeCycleListener, lifeCycleListener, server.getExecutorFactory().getExecutor(), server.getExecutorFactory().getExecutor(), server.getScheduledPool(), protocolManager); connector.start(); connector.createConnection();
@Override public ConnectionEntry createConnectionEntry(Acceptor acceptorUsed, Connection remotingConnection) { AMQPConnectionCallback connectionCallback = new AMQPConnectionCallback(this, remotingConnection, server.getExecutorFactory().getExecutor(), server); long ttl = ActiveMQClient.DEFAULT_CONNECTION_TTL; if (server.getConfiguration().getConnectionTTLOverride() != -1) { ttl = server.getConfiguration().getConnectionTTLOverride(); } if (getAmqpIdleTimeout() != null) { ttl = getAmqpIdleTimeout().longValue(); } if (ttl < 0) { ttl = 0; } String id = server.getConfiguration().getName(); boolean useCoreSubscriptionNaming = server.getConfiguration().isAmqpUseCoreSubscriptionNaming(); AMQPConnectionContext amqpConnection = new AMQPConnectionContext(this, connectionCallback, id, (int) ttl, getMaxFrameSize(), AMQPConstants.Connection.DEFAULT_CHANNEL_MAX, useCoreSubscriptionNaming, server.getScheduledPool(), true, null, null); Executor executor = server.getExecutorFactory().getExecutor(); ActiveMQProtonRemotingConnection delegate = new ActiveMQProtonRemotingConnection(this, amqpConnection, remotingConnection, executor); delegate.addFailureListener(connectionCallback); delegate.addCloseListener(connectionCallback); connectionCallback.setProtonConnectionDelegate(delegate); // connection entry only understands -1 otherwise we would see disconnects for no reason ConnectionEntry entry = new ConnectionEntry(delegate, executor, System.currentTimeMillis(), ttl <= 0 ? -1 : ttl); return entry; }
@Override public ConnectionEntry createConnectionEntry(Acceptor acceptorUsed, Connection remotingConnection) { AMQPConnectionCallback connectionCallback = new AMQPConnectionCallback(this, remotingConnection, server.getExecutorFactory().getExecutor(), server); long ttl = ActiveMQClient.DEFAULT_CONNECTION_TTL; if (server.getConfiguration().getConnectionTTLOverride() != -1) { ttl = server.getConfiguration().getConnectionTTLOverride(); } if (getAmqpIdleTimeout() != null) { ttl = getAmqpIdleTimeout().longValue(); } if (ttl < 0) { ttl = 0; } String id = server.getConfiguration().getName(); boolean useCoreSubscriptionNaming = server.getConfiguration().isAmqpUseCoreSubscriptionNaming(); AMQPConnectionContext amqpConnection = new AMQPConnectionContext(this, connectionCallback, id, (int) ttl, getMaxFrameSize(), AMQPConstants.Connection.DEFAULT_CHANNEL_MAX, useCoreSubscriptionNaming, server.getScheduledPool(), true, null, null); Executor executor = server.getExecutorFactory().getExecutor(); ActiveMQProtonRemotingConnection delegate = new ActiveMQProtonRemotingConnection(this, amqpConnection, remotingConnection, executor); delegate.addFailureListener(connectionCallback); delegate.addCloseListener(connectionCallback); connectionCallback.setProtonConnectionDelegate(delegate); // connection entry only understands -1 otherwise we would see disconnects for no reason ConnectionEntry entry = new ConnectionEntry(delegate, executor, System.currentTimeMillis(), ttl <= 0 ? -1 : ttl); return entry; }
SimpleString.toSimpleString("topic"), FilterImpl.createFilter(Filter.GENERIC_IGNORED_FILTER), null, true, false, false, server.getScheduledPool(), server.getPostOffice(), storage, server.getAddressSettingsRepository(), server.getExecutorFactory().getExecutor(), server, null);
@Test public void controlWithDifferentConnector() throws Exception { try (ServerLocatorImpl locator = (ServerLocatorImpl) createInVMNonHALocator()) { locator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(locator)); ClusterController controller = new ClusterController(getServer(0), getServer(0).getScheduledPool()); ClusterControl clusterControl = controller.connectToNodeInCluster((ClientSessionFactoryInternal) locator.createSessionFactory()); clusterControl.authorize(); } }
@Test public void controlWithDifferentPassword() throws Exception { try (ServerLocatorImpl locator = (ServerLocatorImpl) createInVMNonHALocator()) { locator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(locator)); ClusterController controller = new ClusterController(getServer(1), getServer(1).getScheduledPool()); ClusterControl clusterControl = controller.connectToNodeInCluster((ClientSessionFactoryInternal) locator.createSessionFactory()); try { clusterControl.authorize(); fail("should throw ActiveMQClusterSecurityException"); } catch (Exception e) { assertTrue("should throw ActiveMQClusterSecurityException", e instanceof ActiveMQClusterSecurityException); } } }