Search in sources :

Example 1 with Acceptor

use of org.apache.activemq.artemis.spi.core.remoting.Acceptor in project activemq-artemis by apache.

the class RemotingServiceImpl method stop.

@Override
public void stop(final boolean criticalError) throws Exception {
    if (!started) {
        return;
    }
    failureCheckAndFlushThread.close(criticalError);
    // We need to stop them accepting first so no new connections are accepted after we send the disconnect message
    for (Acceptor acceptor : acceptors.values()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Pausing acceptor " + acceptor);
        }
        try {
            acceptor.pause();
        } catch (Throwable t) {
            ActiveMQServerLogger.LOGGER.errorStoppingAcceptor(acceptor.getName());
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Sending disconnect on live connections");
    }
    HashSet<ConnectionEntry> connectionEntries = new HashSet<>(connections.values());
    // then send a disconnect packet
    for (ConnectionEntry entry : connectionEntries) {
        RemotingConnection conn = entry.connection;
        if (logger.isTraceEnabled()) {
            logger.trace("Sending connection.disconnection packet to " + conn);
        }
        conn.disconnect(criticalError);
    }
    for (Acceptor acceptor : acceptors.values()) {
        try {
            acceptor.stop();
        } catch (Throwable t) {
            ActiveMQServerLogger.LOGGER.errorStoppingAcceptor(acceptor.getName());
        }
    }
    acceptors.clear();
    connections.clear();
    connectionCountLatch.setCount(0);
    if (managementService != null) {
        managementService.unregisterAcceptors();
    }
    threadPool.shutdown();
    if (!criticalError) {
        boolean ok = threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS);
        if (!ok) {
            ActiveMQServerLogger.LOGGER.timeoutRemotingThreadPool();
        }
    }
    started = false;
}
Also used : Acceptor(org.apache.activemq.artemis.spi.core.remoting.Acceptor) ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) HashSet(java.util.HashSet)

Example 2 with Acceptor

use of org.apache.activemq.artemis.spi.core.remoting.Acceptor in project activemq-artemis by apache.

the class RemotingServiceImpl method createAcceptor.

@Override
public Acceptor createAcceptor(TransportConfiguration info) {
    Acceptor acceptor = null;
    try {
        AcceptorFactory factory = server.getServiceRegistry().getAcceptorFactory(info.getName(), info.getFactoryClassName());
        Map<String, ProtocolManagerFactory> selectedProtocolFactories = new ConcurrentHashMap<>();
        @SuppressWarnings("deprecation") String protocol = ConfigurationHelper.getStringProperty(TransportConstants.PROTOCOL_PROP_NAME, null, info.getParams());
        if (protocol != null) {
            ActiveMQServerLogger.LOGGER.warnDeprecatedProtocol();
            locateProtocols(protocol, info, selectedProtocolFactories);
        }
        String protocols = ConfigurationHelper.getStringProperty(TransportConstants.PROTOCOLS_PROP_NAME, null, info.getParams());
        if (protocols != null) {
            locateProtocols(protocols, info, selectedProtocolFactories);
        }
        ClusterConnection clusterConnection = lookupClusterConnection(info);
        // If empty: we get the default list
        if (selectedProtocolFactories.isEmpty()) {
            selectedProtocolFactories = protocolMap;
        }
        Map<String, ProtocolManager> selectedProtocols = new ConcurrentHashMap<>();
        for (Entry<String, ProtocolManagerFactory> entry : selectedProtocolFactories.entrySet()) {
            selectedProtocols.put(entry.getKey(), entry.getValue().createProtocolManager(server, info.getExtraParams(), incomingInterceptors, outgoingInterceptors));
        }
        acceptor = factory.createAcceptor(info.getName(), clusterConnection, info.getParams(), new DelegatingBufferHandler(), this, threadPool, scheduledThreadPool, selectedProtocols);
        if (defaultInvmSecurityPrincipal != null && acceptor.isUnsecurable()) {
            acceptor.setDefaultActiveMQPrincipal(defaultInvmSecurityPrincipal);
        }
        acceptors.put(info.getName(), acceptor);
        if (managementService != null) {
            acceptor.setNotificationService(managementService);
            managementService.registerAcceptor(acceptor, info);
        }
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.errorCreatingAcceptor(e, info.getFactoryClassName());
    }
    return acceptor;
}
Also used : Acceptor(org.apache.activemq.artemis.spi.core.remoting.Acceptor) ProtocolManagerFactory(org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory) CoreProtocolManagerFactory(org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ProtocolManager(org.apache.activemq.artemis.spi.core.protocol.ProtocolManager) AcceptorFactory(org.apache.activemq.artemis.spi.core.remoting.AcceptorFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with Acceptor

use of org.apache.activemq.artemis.spi.core.remoting.Acceptor in project activemq-artemis by apache.

the class RemotingServiceImpl method destroyAcceptor.

@Override
public void destroyAcceptor(String name) throws Exception {
    Acceptor acceptor = acceptors.get(name);
    if (acceptor != null) {
        acceptor.stop();
        acceptors.remove(name);
    }
}
Also used : Acceptor(org.apache.activemq.artemis.spi.core.remoting.Acceptor)

Example 4 with Acceptor

use of org.apache.activemq.artemis.spi.core.remoting.Acceptor in project activemq-artemis by apache.

the class NettyAcceptorFactoryTest method testCreateAcceptor.

@Test
public void testCreateAcceptor() throws Exception {
    NettyAcceptorFactory factory = new NettyAcceptorFactory();
    Map<String, Object> params = new HashMap<>();
    BufferHandler handler = new BufferHandler() {

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    ServerConnectionLifeCycleListener listener = new ServerConnectionLifeCycleListener() {

        @Override
        public void connectionException(final Object connectionID, final ActiveMQException me) {
        }

        @Override
        public void connectionDestroyed(final Object connectionID) {
        }

        @Override
        public void connectionCreated(ActiveMQComponent component, final Connection connection, final ProtocolManager protocol) {
        }

        @Override
        public void connectionReadyForWrites(Object connectionID, boolean ready) {
        }
    };
    Acceptor acceptor = factory.createAcceptor("netty", null, params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory()), new HashMap<String, ProtocolManager>());
    Assert.assertTrue(acceptor instanceof NettyAcceptor);
}
Also used : ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) NettyAcceptor(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor) Acceptor(org.apache.activemq.artemis.spi.core.remoting.Acceptor) HashMap(java.util.HashMap) NettyAcceptor(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) NettyAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory) ServerConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ProtocolManager(org.apache.activemq.artemis.spi.core.protocol.ProtocolManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

Acceptor (org.apache.activemq.artemis.spi.core.remoting.Acceptor)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ProtocolManager (org.apache.activemq.artemis.spi.core.protocol.ProtocolManager)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1 ActiveMQRemoteDisconnectException (org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException)1 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)1 CoreProtocolManagerFactory (org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory)1 NettyAcceptor (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor)1 NettyAcceptorFactory (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory)1 ActiveMQComponent (org.apache.activemq.artemis.core.server.ActiveMQComponent)1 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)1 ConnectionEntry (org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry)1 ProtocolManagerFactory (org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory)1 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)1 AcceptorFactory (org.apache.activemq.artemis.spi.core.remoting.AcceptorFactory)1 BufferHandler (org.apache.activemq.artemis.spi.core.remoting.BufferHandler)1