Search in sources :

Example 1 with Connection

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

the class ClientSessionFactoryImpl method establishNewConnection.

protected RemotingConnection establishNewConnection() {
    Connection transportConnection = createTransportConnection();
    if (transportConnection == null) {
        if (ClientSessionFactoryImpl.logger.isTraceEnabled()) {
            logger.trace("Neither backup or live were active, will just give up now");
        }
        return null;
    }
    RemotingConnection newConnection = clientProtocolManager.connect(transportConnection, callTimeout, callFailoverTimeout, incomingInterceptors, outgoingInterceptors, new SessionFactoryTopologyHandler());
    newConnection.addFailureListener(new DelegatingFailureListener(newConnection.getID()));
    schedulePing();
    if (logger.isTraceEnabled()) {
        logger.trace("returning " + newConnection);
    }
    return newConnection;
}
Also used : CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 2 with Connection

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

the class NettyConnector method close.

@Override
public synchronized void close() {
    if (channelClazz == null) {
        return;
    }
    if (batchFlusherFuture != null) {
        batchFlusherFuture.cancel(false);
        flusher.cancel();
        flusher = null;
        batchFlusherFuture = null;
    }
    bootstrap = null;
    channelGroup.close().awaitUninterruptibly();
    // Shutdown the EventLoopGroup if no new task was added for 100ms or if
    // 3000ms elapsed.
    group.shutdownGracefully(100, 3000, TimeUnit.MILLISECONDS);
    channelClazz = null;
    for (Connection connection : connections.values()) {
        listener.connectionDestroyed(connection.getID());
    }
    connections.clear();
}
Also used : Connection(org.apache.activemq.artemis.spi.core.remoting.Connection)

Example 3 with Connection

use of org.apache.activemq.artemis.spi.core.remoting.Connection 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 4 with Connection

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

the class NettyAcceptor method stop.

@Override
public synchronized void stop() {
    if (channelClazz == null) {
        return;
    }
    if (protocolHandler != null) {
        protocolHandler.close();
    }
    if (batchFlusherFuture != null) {
        batchFlusherFuture.cancel(false);
        flusher.cancel();
        flusher = null;
        batchFlusherFuture = null;
    }
    // serverChannelGroup has been unbound in pause()
    if (serverChannelGroup != null) {
        serverChannelGroup.close().awaitUninterruptibly();
    }
    if (channelGroup != null) {
        ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly();
        if (!future.isSuccess()) {
            ActiveMQServerLogger.LOGGER.nettyChannelGroupError();
            for (Channel channel : future.group()) {
                if (channel.isActive()) {
                    ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress());
                }
            }
        }
    }
    // Shutdown the EventLoopGroup if no new task was added for 100ms or if
    // 3000ms elapsed.
    eventLoopGroup.shutdownGracefully(100, 3000, TimeUnit.MILLISECONDS);
    eventLoopGroup = null;
    channelClazz = null;
    for (Connection connection : connections.values()) {
        listener.connectionDestroyed(connection.getID());
    }
    connections.clear();
    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("factory"), new SimpleString(NettyAcceptorFactory.class.getName()));
        props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host));
        props.putIntProperty(new SimpleString("port"), port);
        Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props);
        try {
            notificationService.sendNotification(notification);
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.failedToSendNotification(e);
        }
    }
    paused = false;
}
Also used : ChannelGroupFuture(io.netty.channel.group.ChannelGroupFuture) LocalServerChannel(io.netty.channel.local.LocalServerChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) KQueueServerSocketChannel(io.netty.channel.kqueue.KQueueServerSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) Channel(io.netty.channel.Channel) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 5 with Connection

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

the class InVMAcceptor method stop.

@Override
public synchronized void stop() {
    if (!started) {
        return;
    }
    if (!paused) {
        InVMRegistry.instance.unregisterAcceptor(id);
    }
    for (Connection connection : connections.values()) {
        listener.connectionDestroyed(connection.getID());
    }
    connections.clear();
    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("factory"), new SimpleString(InVMAcceptorFactory.class.getName()));
        props.putIntProperty(new SimpleString("id"), id);
        Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props);
        try {
            notificationService.sendNotification(notification);
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.failedToSendNotification(e);
        }
    }
    started = false;
    paused = false;
}
Also used : ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Aggregations

Connection (org.apache.activemq.artemis.spi.core.remoting.Connection)11 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)3 HashMap (java.util.HashMap)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 NettyAcceptor (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor)2 NettyConnection (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection)2 ActiveMQComponent (org.apache.activemq.artemis.core.server.ActiveMQComponent)2 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)2 Notification (org.apache.activemq.artemis.core.server.management.Notification)2 ProtocolManager (org.apache.activemq.artemis.spi.core.protocol.ProtocolManager)2 BufferHandler (org.apache.activemq.artemis.spi.core.remoting.BufferHandler)2 ServerConnectionLifeCycleListener (org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener)2 TypedProperties (org.apache.activemq.artemis.utils.collections.TypedProperties)2 Test (org.junit.Test)2 Channel (io.netty.channel.Channel)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ServerChannel (io.netty.channel.ServerChannel)1