Search in sources :

Example 1 with DefaultPromise

use of io.netty.util.concurrent.DefaultPromise in project bgpcep by opendaylight.

the class FiniteStateMachineTest method setup.

@Before
public void setup() {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open localPrefs = new OpenBuilder().setKeepalive((short) 1).build();
    this.serverSession = new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE), this.channel, this.listener, (short) 1, 20, localPrefs);
    this.tlsSessionNegotiator = new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE), this.channel, this.listener, (short) 1, 20, localPrefs, new TlsBuilder().build());
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder) DefaultPromise(io.netty.util.concurrent.DefaultPromise) TlsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.TlsBuilder) Before(org.junit.Before)

Example 2 with DefaultPromise

use of io.netty.util.concurrent.DefaultPromise in project bgpcep by opendaylight.

the class PCEPDispatcherImpl method createServerBootstrap.

synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(final SocketChannel ch) {
            initializer.initializeChannel(ch, new DefaultPromise<>(PCEPDispatcherImpl.this.executor));
        }
    });
    b.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    if (Epoll.isAvailable()) {
        b.channel(EpollServerSocketChannel.class);
        b.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        b.channel(NioServerSocketChannel.class);
    }
    if (!this.keys.isEmpty()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, this.keys);
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
    // Make sure we are doing round-robin processing
    b.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(1));
    if (b.config().group() == null) {
        b.group(this.bossGroup, this.workerGroup);
    }
    return b;
}
Also used : EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) DefaultPromise(io.netty.util.concurrent.DefaultPromise) FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 3 with DefaultPromise

use of io.netty.util.concurrent.DefaultPromise in project teiid by teiid.

the class SSLAwareChannelHandler method channelActive.

@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
    ChannelListener listener = this.listenerFactory.createChannelListener(new ObjectChannelImpl(ctx.channel()));
    this.listeners.put(ctx.channel(), listener);
    maxChannels = Math.max(maxChannels, this.listeners.size());
    SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
    if (sslHandler != null) {
        sslHandler.handshakeFuture().addListener(new GenericFutureListener<DefaultPromise<Channel>>() {

            @Override
            public void operationComplete(DefaultPromise<Channel> future) throws Exception {
                onConnection(ctx.channel());
            }
        });
    } else {
        onConnection(ctx.channel());
    }
}
Also used : DefaultPromise(io.netty.util.concurrent.DefaultPromise) Channel(io.netty.channel.Channel) ObjectChannel(org.teiid.net.socket.ObjectChannel) SslHandler(io.netty.handler.ssl.SslHandler) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with DefaultPromise

use of io.netty.util.concurrent.DefaultPromise in project drill by apache.

the class WebSessionResourcesTest method testCloseWithListener.

/**
 * Validates successful {@link WebSessionResources#close()} with valid CloseFuture and {@link TestClosedListener}
 * getting invoked which is added to the close future.
 * @throws Exception
 */
@Test
public void testCloseWithListener() throws Exception {
    try {
        // Assign latch, executor and closeListener for this test case
        GenericFutureListener<Future<Void>> closeListener = new TestClosedListener();
        latch = new CountDownLatch(1);
        executor = TransportCheck.createEventLoopGroup(1, "Test-Thread").next();
        Promise<Void> closeFuture = new DefaultPromise(executor);
        // create WebSessionResources with above ChannelPromise to notify listener
        webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock(UserSession.class), closeFuture);
        // Add the Test Listener to close future
        assertTrue(!listenerComplete);
        closeFuture.addListener(closeListener);
        // Close the WebSessionResources
        webSessionResources.close();
        // Verify the states
        verify(webSessionResources.getAllocator()).close();
        verify(webSessionResources.getSession()).close();
        assertTrue(webSessionResources.getCloseFuture() == null);
        // Since listener will be invoked so test should not wait forever
        latch.await();
        assertTrue(listenerComplete);
    } catch (Exception e) {
        fail();
    } finally {
        listenerComplete = false;
        executor.shutdownGracefully();
    }
}
Also used : DefaultPromise(io.netty.util.concurrent.DefaultPromise) Future(io.netty.util.concurrent.Future) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

Example 5 with DefaultPromise

use of io.netty.util.concurrent.DefaultPromise in project drill by apache.

the class WebSessionResourcesTest method testChannelPromiseWithValidExecutor.

/**
 * Validates successful {@link WebSessionResources#close()} with valid CloseFuture and other parameters.
 * @throws Exception
 */
@Test
public void testChannelPromiseWithValidExecutor() throws Exception {
    try {
        EventExecutor mockExecutor = mock(EventExecutor.class);
        Promise<Void> closeFuture = new DefaultPromise(mockExecutor);
        webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock(UserSession.class), closeFuture);
        webSessionResources.close();
        verify(webSessionResources.getAllocator()).close();
        verify(webSessionResources.getSession()).close();
        assertTrue(webSessionResources.getCloseFuture() == null);
        assertTrue(!listenerComplete);
    } catch (Exception e) {
        fail();
    }
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) DefaultPromise(io.netty.util.concurrent.DefaultPromise) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

Aggregations

DefaultPromise (io.netty.util.concurrent.DefaultPromise)13 Channel (io.netty.channel.Channel)5 Test (org.junit.Test)5 SocketChannel (io.netty.channel.socket.SocketChannel)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 MultiplexedChannelRecordTest (com.github.ambry.network.http2.MultiplexedChannelRecordTest)3 ChannelFuture (io.netty.channel.ChannelFuture)3 ChannelPool (io.netty.channel.pool.ChannelPool)3 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)3 Http2StreamChannel (io.netty.handler.codec.http2.Http2StreamChannel)3 Test (org.junit.jupiter.api.Test)3 ChannelHandler (io.netty.channel.ChannelHandler)2 EventExecutor (io.netty.util.concurrent.EventExecutor)2 Future (io.netty.util.concurrent.Future)2 IOException (java.io.IOException)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 BaseTest (org.apache.drill.test.BaseTest)2 Before (org.junit.Before)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ByteBuf (io.netty.buffer.ByteBuf)1