Search in sources :

Example 1 with ConnectionEntry

use of org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry in project activemq-artemis by apache.

the class CoreProtocolManager method createConnectionEntry.

@Override
public ConnectionEntry createConnectionEntry(final Acceptor acceptorUsed, final Connection connection) {
    final Configuration config = server.getConfiguration();
    Executor connectionExecutor = server.getExecutorFactory().getExecutor();
    final CoreRemotingConnection rc = new RemotingConnectionImpl(new ServerPacketDecoder(), connection, incomingInterceptors, outgoingInterceptors, config.isAsyncConnectionExecutionEnabled() ? connectionExecutor : null, server.getNodeID());
    Channel channel1 = rc.getChannel(CHANNEL_ID.SESSION.id, -1);
    ChannelHandler handler = new ActiveMQPacketHandler(this, server, channel1, rc);
    channel1.setHandler(handler);
    long ttl = ActiveMQClient.DEFAULT_CONNECTION_TTL;
    if (config.getConnectionTTLOverride() != -1) {
        ttl = config.getConnectionTTLOverride();
    }
    final ConnectionEntry entry = new ConnectionEntry(rc, connectionExecutor, System.currentTimeMillis(), ttl);
    final Channel channel0 = rc.getChannel(ChannelImpl.CHANNEL_ID.PING.id, -1);
    channel0.setHandler(new LocalChannelHandler(config, entry, channel0, acceptorUsed, rc));
    server.getClusterManager().addClusterChannelHandler(rc.getChannel(CHANNEL_ID.CLUSTER.id, -1), acceptorUsed, rc, server.getActivation());
    return entry;
}
Also used : Executor(java.util.concurrent.Executor) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) ChannelHandler(org.apache.activemq.artemis.core.protocol.core.ChannelHandler) ServerPacketDecoder(org.apache.activemq.artemis.core.protocol.ServerPacketDecoder)

Example 2 with ConnectionEntry

use of org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry in project activemq-artemis by apache.

the class RemotingServiceImpl method removeConnection.

@Override
public RemotingConnection removeConnection(final Object remotingConnectionID) {
    ConnectionEntry entry = connections.remove(remotingConnectionID);
    if (entry != null) {
        logger.debug("RemotingServiceImpl::removing connection ID " + remotingConnectionID);
        connectionCountLatch.countDown();
        return entry.connection;
    } else {
        logger.debug("The connectionID::" + remotingConnectionID + " was already removed by some other module");
        return null;
    }
}
Also used : ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry)

Example 3 with ConnectionEntry

use of org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry in project activemq-artemis by apache.

the class RemotingServiceImpl method connectionCreated.

@Override
public void connectionCreated(final ActiveMQComponent component, final Connection connection, final ProtocolManager protocol) {
    if (server == null) {
        throw new IllegalStateException("Unable to create connection, server hasn't finished starting up");
    }
    ConnectionEntry entry = protocol.createConnectionEntry((Acceptor) component, connection);
    try {
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.afterCreateConnection(entry.connection));
        }
    } catch (ActiveMQException t) {
        logger.warn("Error executing afterCreateConnection plugin method: {}", t.getMessage(), t);
        throw new IllegalStateException(t.getMessage(), t.getCause());
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Connection created " + connection);
    }
    connections.put(connection.getID(), entry);
    connectionCountLatch.countUp();
    totalConnectionCount.incrementAndGet();
}
Also used : ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 4 with ConnectionEntry

use of org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry 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 5 with ConnectionEntry

use of org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry in project activemq-artemis by apache.

the class ProtonProtocolManager method createConnectionEntry.

@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();
    }
    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);
    ConnectionEntry entry = new ConnectionEntry(delegate, executor, System.currentTimeMillis(), ttl);
    return entry;
}
Also used : Executor(java.util.concurrent.Executor) ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) AMQPConnectionContext(org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

ConnectionEntry (org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry)10 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)4 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)3 Executor (java.util.concurrent.Executor)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1 ActiveMQRemoteDisconnectException (org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 ServerPacketDecoder (org.apache.activemq.artemis.core.protocol.ServerPacketDecoder)1 Channel (org.apache.activemq.artemis.core.protocol.core.Channel)1 ChannelHandler (org.apache.activemq.artemis.core.protocol.core.ChannelHandler)1 NettyServerConnection (org.apache.activemq.artemis.core.remoting.impl.netty.NettyServerConnection)1 AMQPConnectionContext (org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext)1 Acceptor (org.apache.activemq.artemis.spi.core.remoting.Acceptor)1 OpenWireFormat (org.apache.activemq.openwire.OpenWireFormat)1