Example usage for io.netty.channel.socket SocketChannel eventLoop

List of usage examples for io.netty.channel.socket SocketChannel eventLoop

Introduction

In this page you can find the example usage for io.netty.channel.socket SocketChannel eventLoop.

Prototype

EventLoop eventLoop();

Source Link

Document

Return the EventLoop this Channel was registered to.

Usage

From source file:com.mycompany.nettyweb.HttpServerInitializer.java

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();//from  ww  w . j  av a  2  s  .  com
    GlobalTrafficShapingHandler globalTrafficShapingHandler = new GlobalTrafficShapingHandler(ch.eventLoop());
    trafficCounter = globalTrafficShapingHandler.trafficCounter();
    trafficCounter.start();

    p.addLast(globalTrafficShapingHandler);
    p.addLast("codec", new HttpServerCodec());
    p.addLast("handler", new HttpServerHandler(trafficCounter, statistics));
}

From source file:org.opendaylight.protocol.bgp.rib.impl.AbstractAddPathTest.java

License:Open Source License

private static ChannelFuture createClient(final BGPDispatcherImpl dispatcher,
        final InetSocketAddress remoteAddress, final BGPPeerRegistry registry,
        final InetSocketAddress localAddress, final BGPHandlerFactory hf) throws InterruptedException {
    final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(registry);

    final Bootstrap bootstrap = dispatcher.createClientBootStrap(Optional.<KeyMapping>absent(),
            Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup());
    bootstrap.localAddress(localAddress);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {
        @Override// w w  w .  j  a v  a 2  s. com
        protected void initChannel(final SocketChannel ch) throws Exception {
            ch.pipeline().addLast(hf.getDecoders());
            ch.pipeline().addLast("negotiator",
                    snf.getSessionNegotiator(ch, new DefaultPromise<BGPSessionImpl>(ch.eventLoop())));
            ch.pipeline().addLast(hf.getEncoders());
        }
    });
    return bootstrap.connect(remoteAddress).sync();
}

From source file:org.restlet.engine.netty.NettyServerHelper.java

License:Open Source License

@Override
public void start() throws Exception {
    super.start();
    setBossGroup(new NioEventLoopGroup());
    setWorkerGroup(new NioEventLoopGroup());
    setServerBootstrap(new ServerBootstrap());
    getServerBootstrap().option(ChannelOption.SO_BACKLOG, 1024);
    getServerBootstrap().group(getBossGroup(), getWorkerGroup()).channel(NioServerSocketChannel.class)
            .childOption(ChannelOption.AUTO_READ, false).localAddress(getHelped().getPort())
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override//from  ww w  .j  a v  a  2s  .  c  o m
                protected void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline pipeline = ch.pipeline();

                    pipeline.addLast(new HttpRequestDecoder(), new HttpResponseEncoder())
                            .addLast("serverStreamsHandler", new HttpStreamsServerHandler());

                    HandlerSubscriber<HttpResponse> subscriber = new HandlerSubscriber<>(ch.eventLoop(), 2, 4);
                    HandlerPublisher<HttpRequest> publisher = new HandlerPublisher<>(ch.eventLoop(),
                            HttpRequest.class);

                    pipeline.addLast("serverSubscriber", subscriber);
                    pipeline.addLast("serverPublisher", publisher);

                    publisher.subscribe(NettyServerHelper.this);
                    NettyServerHelper.this.subscribe(subscriber);
                }
            });

    setServerChannel(getServerBootstrap().bind().sync().channel());
    setEphemeralPort(((InetSocketAddress) getServerChannel().localAddress()).getPort());
    getLogger().info("Starting the Netty " + getProtocols() + " server on port " + getHelped().getPort());
}

From source file:reactor.io.net.netty.tcp.NettyTcpClient.java

License:Apache License

@Override
protected <C> NetChannel<IN, OUT> createChannel(C ioChannel) {
    SocketChannel ch = (SocketChannel) ioChannel;
    int backlog = getEnvironment().getProperty("reactor.tcp.connectionReactorBacklog", Integer.class, 128);

    return new NettyNetChannel<IN, OUT>(getEnvironment(), getCodec(),
            new NettyEventLoopDispatcher(ch.eventLoop(), backlog), getReactor(), ch);
}

From source file:reactor.tcp.netty.NettyTcpClient.java

License:Open Source License

@Override
protected <C> TcpConnection<IN, OUT> createConnection(C channel) {
    SocketChannel ch = (SocketChannel) channel;
    int backlog = env.getProperty("reactor.tcp.connectionReactorBacklog", Integer.class, 128);

    return new NettyTcpConnection<IN, OUT>(env, getCodec(),
            new NettyEventLoopDispatcher(ch.eventLoop(), backlog), eventsReactor, ch);
}