Search in sources :

Example 1 with WrappingXnioSocketChannel

use of org.xnio.netty.transport.WrappingXnioSocketChannel in project wildfly by wildfly.

the class HTTPUpgradeService method switchToMessagingProtocol.

private static HttpUpgradeListener switchToMessagingProtocol(final ActiveMQServer activemqServer, final String acceptorName, final String protocolName) {
    return new HttpUpgradeListener() {

        @Override
        public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) {
            ChannelListener<StreamConnection> listener = new ChannelListener<StreamConnection>() {

                @Override
                public void handleEvent(StreamConnection connection) {
                    MessagingLogger.ROOT_LOGGER.debugf("Switching to %s protocol for %s http-acceptor", protocolName, acceptorName);
                    ActiveMQServer server = selectServer(exchange, activemqServer);
                    RemotingService remotingService = server.getRemotingService();
                    if (!server.isActive() || !remotingService.isStarted()) {
                        // ActiveMQ does not accept connection
                        IoUtils.safeClose(connection);
                        return;
                    }
                    NettyAcceptor acceptor = (NettyAcceptor) remotingService.getAcceptor(acceptorName);
                    SocketChannel channel = new WrappingXnioSocketChannel(connection);
                    try {
                        acceptor.transfer(channel);
                        connection.getSourceChannel().resumeReads();
                    } catch (IllegalStateException e) {
                        IoUtils.safeClose(connection);
                    }
                }
            };
            ChannelListeners.invokeChannelListener(streamConnection, listener);
        }
    };
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) WrappingXnioSocketChannel(org.xnio.netty.transport.WrappingXnioSocketChannel) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SocketChannel(io.netty.channel.socket.SocketChannel) WrappingXnioSocketChannel(org.xnio.netty.transport.WrappingXnioSocketChannel) ChannelListener(org.xnio.ChannelListener) RemotingService(org.apache.activemq.artemis.core.remoting.server.RemotingService) NettyAcceptor(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor) HttpUpgradeListener(io.undertow.server.HttpUpgradeListener) StreamConnection(org.xnio.StreamConnection)

Aggregations

SocketChannel (io.netty.channel.socket.SocketChannel)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 HttpUpgradeListener (io.undertow.server.HttpUpgradeListener)1 NettyAcceptor (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor)1 RemotingService (org.apache.activemq.artemis.core.remoting.server.RemotingService)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 ChannelListener (org.xnio.ChannelListener)1 StreamConnection (org.xnio.StreamConnection)1 WrappingXnioSocketChannel (org.xnio.netty.transport.WrappingXnioSocketChannel)1