Search in sources :

Example 6 with ConnectionEntry

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

the class RemotingServiceImpl method connectionDestroyed.

@Override
public void connectionDestroyed(final Object connectionID) {
    if (logger.isTraceEnabled()) {
        logger.trace("Connection removed " + connectionID + " from server " + this.server, new Exception("trace"));
    }
    ConnectionEntry conn = connections.get(connectionID);
    if (conn != null && !conn.connection.isSupportReconnect()) {
        RemotingConnection removedConnection = removeConnection(connectionID);
        if (removedConnection != null) {
            try {
                if (server.hasBrokerPlugins()) {
                    server.callBrokerPlugins(plugin -> plugin.afterDestroyConnection(removedConnection));
                }
            } catch (ActiveMQException t) {
                logger.warn("Error executing afterDestroyConnection plugin method: {}", t.getMessage(), t);
                conn.connection.fail(t);
                return;
            }
        }
        conn.connection.fail(new ActiveMQRemoteDisconnectException());
    }
}
Also used : ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Example 7 with ConnectionEntry

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

the class RemotingServiceImpl method freeze.

@Override
public synchronized void freeze(final String scaleDownNodeID, final CoreRemotingConnection connectionToKeepOpen) {
    if (!started)
        return;
    failureCheckAndFlushThread.close(false);
    HashMap<Object, ConnectionEntry> connectionEntries = new HashMap<>(connections);
    // complete then send a disconnect packet
    for (Entry<Object, ConnectionEntry> entry : connectionEntries.entrySet()) {
        RemotingConnection conn = entry.getValue().connection;
        if (conn.equals(connectionToKeepOpen))
            continue;
        if (logger.isTraceEnabled()) {
            logger.trace("Sending connection.disconnection packet to " + conn);
        }
        if (!conn.isClient()) {
            conn.disconnect(scaleDownNodeID, false);
            removeConnection(entry.getKey());
        }
    }
}
Also used : ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 8 with ConnectionEntry

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

the class OpenWireProtocolManager method createConnectionEntry.

@Override
public ConnectionEntry createConnectionEntry(Acceptor acceptorUsed, Connection connection) {
    OpenWireFormat wf = (OpenWireFormat) wireFactory.createWireFormat();
    OpenWireConnection owConn = new OpenWireConnection(connection, server, server.getExecutorFactory().getExecutor(), this, wf);
    owConn.sendHandshake();
    // first we setup ttl to -1
    // then when negotiation, we handle real ttl and delay
    ConnectionEntry entry = new ConnectionEntry(owConn, null, System.currentTimeMillis(), -1);
    owConn.setConnectionEntry(entry);
    return entry;
}
Also used : OpenWireFormat(org.apache.activemq.openwire.OpenWireFormat) ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry)

Example 9 with ConnectionEntry

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

the class MQTTProtocolManager method createConnectionEntry.

@Override
public ConnectionEntry createConnectionEntry(Acceptor acceptorUsed, Connection connection) {
    try {
        MQTTConnection mqttConnection = new MQTTConnection(connection);
        ConnectionEntry entry = new ConnectionEntry(mqttConnection, null, System.currentTimeMillis(), MQTTUtil.DEFAULT_KEEP_ALIVE_FREQUENCY);
        NettyServerConnection nettyConnection = ((NettyServerConnection) connection);
        MQTTProtocolHandler protocolHandler = nettyConnection.getChannel().pipeline().get(MQTTProtocolHandler.class);
        protocolHandler.setConnection(mqttConnection, entry);
        return entry;
    } catch (Exception e) {
        log.error(e);
        return null;
    }
}
Also used : ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) NettyServerConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyServerConnection)

Example 10 with ConnectionEntry

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

the class StompProtocolManager method createConnectionEntry.

@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);
    }
}
Also used : ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) 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