Search in sources :

Example 46 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project tutorials by eugenp.

the class NettyServerB method run.

private void run() throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new ChannelHandlerA(), new ChannelHandlerB());
            }
        }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
        // (7)
        ChannelFuture f = b.bind(port).sync();
        f.channel().closeFuture().sync();
    } finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 47 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project tutorials by eugenp.

the class NettyServer method run.

private void run() throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new RequestDecoder(), new ResponseDataEncoder(), new ProcessingHandler());
            }
        }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
        ChannelFuture f = b.bind(port).sync();
        f.channel().closeFuture().sync();
    } finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 48 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project bgpcep by opendaylight.

the class PCEPDispatcherImplTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final List<PCEPCapability> capList = new ArrayList<>();
    final PCEPSessionProposalFactory sessionProposal = new BasePCEPSessionProposalFactory(DEAD_TIMER, KEEP_ALIVE, capList);
    final EventLoopGroup eventLoopGroup;
    if (Epoll.isAvailable()) {
        eventLoopGroup = new EpollEventLoopGroup();
    } else {
        eventLoopGroup = new NioEventLoopGroup();
    }
    final MessageRegistry msgReg = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry();
    this.dispatcher = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0), eventLoopGroup, eventLoopGroup);
    doReturn(KeyMapping.getKeyMapping()).when(this.dispatcherDependencies).getKeys();
    doReturn(null).when(this.dispatcherDependencies).getPeerProposal();
    doReturn("mockChannel").when(this.mockChannel).toString();
    final PCEPDispatcherImpl dispatcher2 = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0), eventLoopGroup, eventLoopGroup);
    this.disp2Spy = Mockito.spy(dispatcher2);
    this.pccMock = new PCCMock(new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0), new PCEPHandlerFactory(msgReg));
}
Also used : ArrayList(java.util.ArrayList) PCEPSessionProposalFactory(org.opendaylight.protocol.pcep.PCEPSessionProposalFactory) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) MessageRegistry(org.opendaylight.protocol.pcep.spi.MessageRegistry) PCEPCapability(org.opendaylight.protocol.pcep.PCEPCapability) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Before(org.junit.Before)

Example 49 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project incubator-pulsar by apache.

the class ConnectionPoolTest method testDoubleIpAddress.

@Test
public void testDoubleIpAddress() throws Exception {
    String serviceUrl = "pulsar://non-existing-dns-name:" + BROKER_PORT;
    ClientConfigurationData conf = new ClientConfigurationData();
    EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, new DefaultThreadFactory("test"));
    ConnectionPool pool = Mockito.spy(new ConnectionPool(conf, eventLoop));
    conf.setServiceUrl(serviceUrl);
    PulsarClientImpl client = new PulsarClientImpl(conf, eventLoop, pool);
    List<InetAddress> result = Lists.newArrayList();
    // Add a non existent IP to the response to check that we're trying the 2nd address as well
    result.add(InetAddress.getByName("127.0.0.99"));
    result.add(InetAddress.getByName("127.0.0.1"));
    Mockito.when(pool.resolveName("non-existing-dns-name")).thenReturn(CompletableFuture.completedFuture(result));
    // Create producer should succeed by trying the 2nd IP
    client.createProducer("persistent://sample/standalone/ns/my-topic");
    client.close();
}
Also used : ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) EventLoopGroup(io.netty.channel.EventLoopGroup) InetAddress(java.net.InetAddress) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 50 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project incubator-pulsar by apache.

the class ClientCnxTest method testClientCnxTimeout.

@Test
public void testClientCnxTimeout() throws Exception {
    EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, new DefaultThreadFactory("testClientCnxTimeout"));
    ClientConfigurationData conf = new ClientConfigurationData();
    conf.setOperationTimeoutMs(10);
    ClientCnx cnx = new ClientCnx(conf, eventLoop);
    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    ChannelFuture listenerFuture = mock(ChannelFuture.class);
    when(listenerFuture.addListener(anyObject())).thenReturn(listenerFuture);
    when(ctx.writeAndFlush(anyObject())).thenReturn(listenerFuture);
    Field ctxField = PulsarHandler.class.getDeclaredField("ctx");
    ctxField.setAccessible(true);
    ctxField.set(cnx, ctx);
    try {
        cnx.newLookup(null, 123).get();
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof PulsarClientException.TimeoutException);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) ChannelFuture(io.netty.channel.ChannelFuture) Field(java.lang.reflect.Field) EventLoopGroup(io.netty.channel.EventLoopGroup) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) Test(org.testng.annotations.Test)

Aggregations

EventLoopGroup (io.netty.channel.EventLoopGroup)367 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)271 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)162 Bootstrap (io.netty.bootstrap.Bootstrap)137 Channel (io.netty.channel.Channel)131 ChannelFuture (io.netty.channel.ChannelFuture)129 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)109 SocketChannel (io.netty.channel.socket.SocketChannel)94 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)92 InetSocketAddress (java.net.InetSocketAddress)69 Test (org.junit.jupiter.api.Test)67 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)60 LoggingHandler (io.netty.handler.logging.LoggingHandler)55 ChannelPipeline (io.netty.channel.ChannelPipeline)51 SslContext (io.netty.handler.ssl.SslContext)51 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)50 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)49 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)46 LocalServerChannel (io.netty.channel.local.LocalServerChannel)42 LocalChannel (io.netty.channel.local.LocalChannel)40