Search in sources :

Example 21 with ChannelListener

use of org.xnio.ChannelListener in project undertow by undertow-io.

the class AutobahnWebSocketServer method run.

public void run() {
    xnio = Xnio.getInstance();
    try {
        worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
        OptionMap serverOptions = OptionMap.builder().set(Options.WORKER_ACCEPT_THREADS, 4).set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
        openListener = new HttpOpenListener(new DefaultByteBufferPool(false, 8192));
        ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
        server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
        setRootHandler(getRootHandler());
        server.resumeAccepts();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) InetSocketAddress(java.net.InetSocketAddress) OptionMap(org.xnio.OptionMap) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) IOException(java.io.IOException)

Example 22 with ChannelListener

use of org.xnio.ChannelListener in project wildfly by wildfly.

the class HttpsListenerService method startListening.

@Override
protected void startListening(XnioWorker worker, InetSocketAddress socketAddress, ChannelListener<AcceptingChannel<StreamConnection>> acceptListener) throws IOException {
    SSLContext sslContext = sslContextSupplier.get();
    Builder builder = OptionMap.builder().addAll(commonOptions);
    builder.addAll(socketOptions);
    builder.set(Options.USE_DIRECT_BUFFERS, true);
    if (cipherSuites != null) {
        String[] cipherList = CipherSuiteSelector.fromString(cipherSuites).evaluate(sslContext.getSupportedSSLParameters().getCipherSuites());
        builder.setSequence((Option<Sequence<String>>) HttpsListenerResourceDefinition.ENABLED_CIPHER_SUITES.getOption(), cipherList);
    }
    OptionMap combined = builder.getMap();
    XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), combined, sslContext);
    sslServer = xnioSsl.createSslConnectionServer(worker, socketAddress, (ChannelListener) acceptListener, combined);
    sslServer.resumeAccepts();
    UndertowLogger.ROOT_LOGGER.listenerStarted("HTTPS", getName(), NetworkUtils.formatIPAddressForURI(socketAddress.getAddress()), socketAddress.getPort());
}
Also used : ChannelListener(org.xnio.ChannelListener) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) Builder(org.xnio.OptionMap.Builder) OptionMap(org.xnio.OptionMap) SSLContext(javax.net.ssl.SSLContext) Sequence(org.xnio.Sequence) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl)

Example 23 with ChannelListener

use of org.xnio.ChannelListener 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

ChannelListener (org.xnio.ChannelListener)23 IOException (java.io.IOException)16 InetSocketAddress (java.net.InetSocketAddress)8 OptionMap (org.xnio.OptionMap)7 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)6 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)6 ByteBuffer (java.nio.ByteBuffer)6 StreamConnection (org.xnio.StreamConnection)6 StreamSinkChannel (org.xnio.channels.StreamSinkChannel)6 PooledByteBuffer (io.undertow.connector.PooledByteBuffer)5 HttpHandler (io.undertow.server.HttpHandler)4 HttpServerExchange (io.undertow.server.HttpServerExchange)4 ChannelExceptionHandler (org.xnio.ChannelExceptionHandler)4 StreamSourceChannel (org.xnio.channels.StreamSourceChannel)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Channel (java.nio.channels.Channel)3 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)2 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)2 DeploymentManager (io.undertow.servlet.api.DeploymentManager)2 FilterInfo (io.undertow.servlet.api.FilterInfo)2