use of io.netty.channel.EventLoop in project activemq-artemis by apache.
the class NettyConnection method close.
@Override
public final void close() {
if (closed) {
return;
}
EventLoop eventLoop = channel.eventLoop();
boolean inEventLoop = eventLoop.inEventLoop();
// if we are in an event loop we need to close the channel after the writes have finished
if (!inEventLoop) {
final SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
closeSSLAndChannel(sslHandler, channel, false);
} else {
eventLoop.execute(() -> {
final SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
closeSSLAndChannel(sslHandler, channel, true);
});
}
closed = true;
listener.connectionDestroyed(getID());
}
use of io.netty.channel.EventLoop in project activemq-artemis by apache.
the class NettyConnection method pendingWritesOnEventLoop.
public final long pendingWritesOnEventLoop() {
final EventLoop eventLoop = channel.eventLoop();
final boolean inEventLoop = eventLoop.inEventLoop();
final long pendingWritesOnEventLoop;
if (inEventLoop) {
pendingWritesOnEventLoop = this.pendingWritesOnEventLoop;
} else {
pendingWritesOnEventLoop = pendingWritesOnEventLoopView.get();
}
return pendingWritesOnEventLoop;
}
use of io.netty.channel.EventLoop in project activemq-artemis by apache.
the class NettyConnection method isAllowedToBlock.
private boolean isAllowedToBlock() {
final EventLoop eventLoop = channel.eventLoop();
final boolean inEventLoop = eventLoop.inEventLoop();
return !inEventLoop;
}
use of io.netty.channel.EventLoop in project ratpack by ratpack.
the class DefaultContext method start.
public static void start(EventLoop eventLoop, final RequestConstants requestConstants, Registry registry, Handler[] handlers, Action<? super Execution> onComplete) {
ChainIndex index = new ChainIndex(handlers, registry, true);
requestConstants.indexes.push(index);
DefaultContext context = new DefaultContext(requestConstants);
requestConstants.context = context;
context.pathBindings = new PathBindingStorage(new RootPathBinding(requestConstants.request.getPath()));
requestConstants.applicationConstants.execController.fork().onError(throwable -> requestConstants.context.error(throwable instanceof HandlerException ? throwable.getCause() : throwable)).onComplete(onComplete).register(s -> s.add(Context.TYPE, context).add(Request.TYPE, requestConstants.request).add(Response.TYPE, requestConstants.response).add(PathBindingStorage.TYPE, context.pathBindings).addLazy(RequestId.TYPE, () -> registry.get(RequestId.Generator.TYPE).generate(requestConstants.request))).eventLoop(eventLoop).onStart(e -> DefaultRequest.setDelegateRegistry(requestConstants.request, e)).start(e -> {
requestConstants.execution = e;
context.joinedRegistry = new ContextRegistry(context).join(requestConstants.execution);
context.next();
});
}
use of io.netty.channel.EventLoop in project zuul by Netflix.
the class DefaultClientChannelManagerTest method initializeAndShutdown.
@Test
public void initializeAndShutdown() throws Exception {
final String appName = "app-" + UUID.randomUUID();
final ServerSocket serverSocket = new ServerSocket(0);
final InetSocketAddress serverSocketAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
final String serverHostname = serverSocketAddress.getHostName();
final int serverPort = serverSocketAddress.getPort();
final OriginName originName = OriginName.fromVipAndApp("vip", appName);
final DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
Server.defaultOutboundChannelType.set(NioSocketChannel.class);
final InstanceInfo instanceInfo = Builder.newBuilder().setAppName(appName).setHostName(serverHostname).setPort(serverPort).build();
DiscoveryResult discoveryResult = DiscoveryResult.from(instanceInfo, true);
final DynamicServerResolver resolver = mock(DynamicServerResolver.class);
when(resolver.resolve(any())).thenReturn(discoveryResult);
when(resolver.hasServers()).thenReturn(true);
final Registry registry = new DefaultRegistry();
final DefaultClientChannelManager clientChannelManager = new DefaultClientChannelManager(originName, clientConfig, resolver, registry);
final NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(10);
final EventLoop eventLoop = eventLoopGroup.next();
clientChannelManager.init();
Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(0);
final Promise<PooledConnection> promiseConn = clientChannelManager.acquire(eventLoop);
promiseConn.await(200, TimeUnit.MILLISECONDS);
assertTrue(promiseConn.isDone());
assertTrue(promiseConn.isSuccess());
final PooledConnection connection = promiseConn.get();
assertTrue(connection.isActive());
assertFalse(connection.isInPool());
Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(1);
final boolean releaseResult = clientChannelManager.release(connection);
assertTrue(releaseResult);
assertTrue(connection.isInPool());
Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(0);
clientChannelManager.shutdown();
serverSocket.close();
}
Aggregations