Search in sources :

Example 11 with RemotingConnection

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

the class CertificateUtil method getPeerPrincipalFromConnection.

public static Principal getPeerPrincipalFromConnection(RemotingConnection remotingConnection) {
    Principal result = null;
    if (remotingConnection != null) {
        Connection transportConnection = remotingConnection.getTransportConnection();
        if (transportConnection instanceof NettyConnection) {
            NettyConnection nettyConnection = (NettyConnection) transportConnection;
            ChannelHandler channelHandler = nettyConnection.getChannel().pipeline().get("ssl");
            if (channelHandler != null && channelHandler instanceof SslHandler) {
                SslHandler sslHandler = (SslHandler) channelHandler;
                try {
                    result = sslHandler.engine().getSession().getPeerPrincipal();
                } catch (SSLPeerUnverifiedException ignored) {
                }
            }
        }
    }
    return result;
}
Also used : NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ChannelHandler(io.netty.channel.ChannelHandler) Principal(java.security.Principal) SslHandler(io.netty.handler.ssl.SslHandler)

Example 12 with RemotingConnection

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

the class BridgeImpl method nodeUP.

// To be called by the topology update
// This logic will be updated on the cluster connection
protected void nodeUP(TopologyMember member, boolean last) {
    ClientSessionInternal sessionToUse = session;
    RemotingConnection connectionToUse = sessionToUse != null ? sessionToUse.getConnection() : null;
    if (member != null && this.targetNodeID != null && this.targetNodeID.equals(member.getNodeId())) {
        // this could be an update of the topology say after a backup started
        BridgeImpl.this.targetNode = member;
    } else {
        // we don't need synchronization here, but we need to make sure we won't get a NPE on races
        if (connectionToUse != null && member.isMember(connectionToUse)) {
            this.targetNode = member;
            this.targetNodeID = member.getNodeId();
        }
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 13 with RemotingConnection

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

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

the class ReplicationManager method stop.

@Override
public void stop() throws Exception {
    synchronized (this) {
        if (!started) {
            logger.trace("Stopping being ignored as it hasn't been started");
            return;
        }
    }
    // This is to avoid the write holding a lock while we are trying to close it
    if (replicatingChannel != null) {
        replicatingChannel.close();
        replicatingChannel.getConnection().getTransportConnection().fireReady(true);
    }
    enabled = false;
    writable.set(true);
    clearReplicationTokens();
    RemotingConnection toStop = remotingConnection;
    if (toStop != null) {
        toStop.removeFailureListener(failureListener);
    }
    remotingConnection = null;
    started = false;
}
Also used : CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 15 with RemotingConnection

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

the class ProtonClientConnectionManager method connectionDestroyed.

@Override
public void connectionDestroyed(Object connectionID) {
    RemotingConnection connection = connectionMap.remove(connectionID);
    if (connection != null) {
        log.info("Connection " + connection.getRemoteAddress() + " destroyed");
        connection.fail(new ActiveMQRemoteDisconnectException());
    } else {
        log.error("Connection with id " + connectionID + " not found in connectionDestroyed");
    }
}
Also used : ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) ActiveMQProtonRemotingConnection(org.apache.activemq.artemis.protocol.amqp.broker.ActiveMQProtonRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Aggregations

RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)84 Test (org.junit.Test)44 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)36 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)31 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)30 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)22 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)21 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)17 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)16 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)16 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)15 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)14 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)13 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)12 Connection (javax.jms.Connection)11 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)11 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)11 Session (javax.jms.Session)10