Examples of EventLoopGroup


Examples of io.netty.channel.EventLoopGroup

    @Autowired
    public EthereumChannelInitializer ethereumChannelInitializer;

    public void connect(String host, int port) {

      EventLoopGroup workerGroup = new NioEventLoopGroup();
        worldManager.getListener().trace("Connecting to: " + host + ":" + port);

        try {
            Bootstrap b = new Bootstrap();
            b.group(workerGroup);
            b.channel(NioSocketChannel.class);
           
            b.option(ChannelOption.SO_KEEPALIVE, true);
            b.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT);
            b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONFIG.peerConnectionTimeout());
            b.remoteAddress(host, port);
           
            b.handler(ethereumChannelInitializer);

            // Start the client.
            ChannelFuture f = b.connect().sync();

            // Wait until the connection is closed.
            f.channel().closeFuture().sync();
            logger.debug("Connection is closed");

        } catch (Exception e) {
          logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName());
            throw new Error("Disconnnected");
        } finally {
          workerGroup.shutdownGracefully();
        }
    }
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

  }

  private void init(int portToBind) {

    IOMode ioMode = IOMode.valueOf(conf.ioMode());
    EventLoopGroup bossGroup =
      NettyUtils.createEventLoop(ioMode, conf.serverThreads(), "shuffle-server");
    EventLoopGroup workerGroup = bossGroup;

    PooledByteBufAllocator allocator = new PooledByteBufAllocator(
      conf.preferDirectBufs() && PlatformDependent.directBufferPreferred());

    bootstrap = new ServerBootstrap()
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

* @author <a href="mailto:nmaurer@redhat.com">Norman Maurer</a>
*/
public class DeregisterChannel {

    public void deregister() {
        EventLoopGroup group = new NioEventLoopGroup();
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(group).channel(NioSocketChannel.class)
                .handler(new SimpleChannelInboundHandler<ByteBuf>() {
                    @Override
                    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
                        ctx.deregister();
                    }
                });
        ChannelFuture future = bootstrap.connect(new InetSocketAddress("www.manning.com", 80));
        future.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture channelFuture) throws Exception {
                if (channelFuture.isSuccess()) {
                    System.out.println("Connection established");
                } else {
                    System.err.println("Connection attempt failed");
                    channelFuture.cause().printStackTrace();
                }
            }
        });

        // Do something which takes some amount of time

        // Register channel again on eventloop
        Channel channel = future.channel();
        group.register(channel).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    System.out.println("Channel registered");
                } else {
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

public class NettyOioServer {

    public void server(int port) throws Exception {
        final ByteBuf buf = Unpooled.unreleasableBuffer(
                Unpooled.copiedBuffer("Hi!\r\n", Charset.forName("UTF-8")));
        EventLoopGroup group = new OioEventLoopGroup();
        try {
            ServerBootstrap b = new ServerBootstrap();

            b.group(group)
             .channel(OioServerSocketChannel.class)
             .localAddress(new InetSocketAddress(port))
             .childHandler(new ChannelInitializer<SocketChannel>() {
                 @Override
                 public void initChannel(SocketChannel ch)
                     throws Exception {
                     ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                         @Override
                         public void channelActive(ChannelHandlerContext ctx) throws Exception {
                             ctx.write(buf.duplicate()).addListener(ChannelFutureListener.CLOSE);
                         }
                     });
                 }
             });
            ChannelFuture f = b.bind().sync();
            f.channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully().sync();
        }
    }
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

    public void register(java.nio.channels.SocketChannel socket, EventLoopGroup egroup) {
        java.nio.channels.SocketChannel mySocket = socket;

        SocketChannel ch = new NioSocketChannel(mySocket);
        EventLoopGroup group = egroup;
        group.register(ch);

    }
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

* @author <a href="mailto:nmaurer@redhat.com">Norman Maurer</a>
*/
public class ReregisterChannel {

    public void reregister() {
        EventLoopGroup group = new NioEventLoopGroup();
        final EventLoopGroup group2 = new NioEventLoopGroup();

        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(group).channel(NioSocketChannel.class)
                .handler(new SimpleChannelInboundHandler<ByteBuf>() {
                    @Override
                    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
                        ctx.pipeline().remove(this);

                        ChannelFuture cf = ctx.deregister();
                        cf.addListener(new ChannelFutureListener() {
                            @Override
                            public void operationComplete(ChannelFuture future) throws Exception {
                                group2.register(future.channel());
                            }
                        });
                    }
                });
        ChannelFuture future = bootstrap.connect(new InetSocketAddress("www.manning.com", 80));
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

        this.host = host;
        this.port = port;
    }

    public void start() throws Exception {
        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap b = new Bootstrap();
            b.group(group)
             .channel(NioSocketChannel.class)
             .remoteAddress(new InetSocketAddress(host, port))
             .handler(new ChannelInitializer<SocketChannel>() {
                 @Override
                 public void initChannel(SocketChannel ch)
                     throws Exception {
                     ch.pipeline().addLast(
                             new EchoClientHandler());
                 }
             });

            ChannelFuture f = b.connect().sync();

            f.channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully().sync();
        }
    }
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

* @version : 2014年9月12日
* @author 赵永春(zyc@hasor.net)
*/
public class Server {
    public void start(String host, int port) throws Exception {
        final EventLoopGroup bossGroup = new NioEventLoopGroup(1);//
        final ServerRsfContext manager = new ServerRsfContext();
        manager.getCallExecute("aa").execute(new Runnable() {
            public void run() {
                manager.print();
            }
        });
        //
        try {
            ServerBootstrap b = new ServerBootstrap();
            b.group(bossGroup, manager.getLoopGroup()).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
                public void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(//
                            new RSFCodec(),//
                            new ServerHandler(manager));
                }
            }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
            ChannelFuture f = b.bind(host, port).sync();
            f.channel().closeFuture().sync();
        } finally {
            manager.getLoopGroup().shutdownGracefully();
            bossGroup.shutdownGracefully();
        }
    }
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

   * preset. Current channel type supported are nio and epoll.
   */
  private ServerBootstrap setupGroups(final ServerBootstrap boot, final ChannelType type) {
    ThreadFactory bossThreadFactory = createThreadFactory("data-server-boss-%d");
    ThreadFactory workerThreadFactory = createThreadFactory("data-server-worker-%d");
    EventLoopGroup bossGroup;
    EventLoopGroup workerGroup;
    int bossThreadCount = WorkerConf.get().NETTY_BOSS_THREADS;
    int workerThreadCount = WorkerConf.get().NETTY_WORKER_THREADS;
    switch (type) {
      case EPOLL:
        bossGroup = new EpollEventLoopGroup(bossThreadCount, bossThreadFactory);
View Full Code Here

Examples of io.netty.channel.EventLoopGroup

                                     EndpointInfo localInfo,
                                     EndpointReferenceType target)
        throws IOException {
        // need to check if the EventLoopGroup is created or not
        // if not create a new EventLoopGroup for it
        EventLoopGroup eventLoopGroup = bus.getExtension(EventLoopGroup.class);
        if (eventLoopGroup == null) {
            final EventLoopGroup group = new NioEventLoopGroup();
            // register a BusLifeCycleListener for it
            bus.setExtension(group, EventLoopGroup.class);
            registerBusLifeListener(bus, group);
        }
        return new NettyHttpConduit(bus, localInfo, target, this);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.