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);
}
}
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());
}
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);
}
};
}
Aggregations