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