Example usage for io.netty.channel EventLoopGroup next

List of usage examples for io.netty.channel EventLoopGroup next

Introduction

In this page you can find the example usage for io.netty.channel EventLoopGroup next.

Prototype

@Override
EventLoop next();

Source Link

Document

Return the next EventLoop to use

Usage

From source file:io.vertx.core.spi.metrics.MetricsTest.java

License:Open Source License

@Test
public void testInitialization() {
    assertSame(vertx, ((FakeVertxMetrics) FakeMetricsBase.getMetrics(vertx)).vertx());
    startNodes(1);// w ww  . j  a  va2s .  co  m
    assertSame(vertices[0], ((FakeVertxMetrics) FakeMetricsBase.getMetrics(vertices[0])).vertx());
    EventLoopGroup group = vertx.nettyEventLoopGroup();
    Set<EventLoop> loops = new HashSet<>();
    int count = 0;
    while (true) {
        EventLoop next = group.next();
        if (!loops.add(next)) {
            break;
        }
        count++;
        assertTrue(count <= VertxOptions.DEFAULT_EVENT_LOOP_POOL_SIZE);
    }
    assertEquals(loops.size(), VertxOptions.DEFAULT_EVENT_LOOP_POOL_SIZE);
}

From source file:me.ferrybig.p2pnetwork.Peer.java

public Peer(EventLoopGroup group, boolean peerExchange) {
    this.group = group;
    this.events = group.next();
    this.peerExchange = peerExchange;
}

From source file:org.apache.pulsar.client.impl.AcknowledgmentsGroupingTracker.java

License:Apache License

public AcknowledgmentsGroupingTracker(ConsumerImpl<?> consumer, ConsumerConfigurationData<?> conf,
        EventLoopGroup eventLoopGroup) {
    this.consumer = consumer;
    this.pendingIndividualAcks = new ConcurrentSkipListSet<>();
    this.acknowledgementGroupTimeMicros = conf.getAcknowledgementsGroupTimeMicros();

    if (acknowledgementGroupTimeMicros > 0) {
        scheduledTask = eventLoopGroup.next().scheduleWithFixedDelay(this::flush,
                acknowledgementGroupTimeMicros, acknowledgementGroupTimeMicros, TimeUnit.MICROSECONDS);
    } else {//w  ww  . ja v  a2s.c o m
        scheduledTask = null;
    }
}

From source file:org.apache.pulsar.client.impl.PersistentAcknowledgmentsGroupingTracker.java

License:Apache License

public PersistentAcknowledgmentsGroupingTracker(ConsumerImpl<?> consumer, ConsumerConfigurationData<?> conf,
        EventLoopGroup eventLoopGroup) {
    this.consumer = consumer;
    this.pendingIndividualAcks = new ConcurrentSkipListSet<>();
    this.acknowledgementGroupTimeMicros = conf.getAcknowledgementsGroupTimeMicros();

    if (acknowledgementGroupTimeMicros > 0) {
        scheduledTask = eventLoopGroup.next().scheduleWithFixedDelay(this::flush,
                acknowledgementGroupTimeMicros, acknowledgementGroupTimeMicros, TimeUnit.MICROSECONDS);
    } else {//from   ww  w .  jav a2 s.c  om
        scheduledTask = null;
    }
}

From source file:org.apache.spark.sql.hive.thriftserver.rsc.Rpc.java

License:Apache License

/**
 * Creates an RPC client for a server running on the given remote host and port.
 *
 * @param config RPC configuration data.
 * @param eloop Event loop for managing the connection.
 * @param host Host name or IP address to connect to.
 * @param port Port where server is listening.
 * @param clientId The client ID that identifies the connection.
 * @param secret Secret for authenticating the client with the server.
 * @param dispatcher Dispatcher used to handle RPC calls.
 * @return A future that can be used to monitor the creation of the RPC object.
 *//*  w  w  w.  j  a v a2  s .c  o m*/
public static Promise<Rpc> createClient(final RSCConf config, final EventLoopGroup eloop, String host, int port,
        final String clientId, final String secret, final RpcDispatcher dispatcher) throws Exception {
    int connectTimeoutMs = (int) config.getTimeAsMs(RSCConf.Entry.RPC_CLIENT_CONNECT_TIMEOUT);

    final ChannelFuture cf = new Bootstrap().group(eloop).handler(new ChannelInboundHandlerAdapter() {
    }).channel(NioSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutMs).connect(host, port);

    final Promise<Rpc> promise = eloop.next().newPromise();
    final AtomicReference<Rpc> rpc = new AtomicReference<Rpc>();

    // Set up a timeout to undo everything.
    final Runnable timeoutTask = new Runnable() {
        @Override
        public void run() {
            promise.setFailure(new TimeoutException("Timed out waiting for RPC server connection."));
        }
    };
    final ScheduledFuture<?> timeoutFuture = eloop.schedule(timeoutTask,
            config.getTimeAsMs(RSCConf.Entry.RPC_CLIENT_HANDSHAKE_TIMEOUT), TimeUnit.MILLISECONDS);

    // The channel listener instantiates the Rpc instance when the connection is established,
    // and initiates the SASL handshake.
    cf.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture cf) throws Exception {
            if (cf.isSuccess()) {
                SaslClientHandler saslHandler = new SaslClientHandler(config, clientId, promise, timeoutFuture,
                        secret, dispatcher);
                Rpc rpc = createRpc(config, saslHandler, (SocketChannel) cf.channel(), eloop);
                saslHandler.rpc = rpc;
                saslHandler.sendHello(cf.channel());
            } else {
                promise.setFailure(cf.cause());
            }
        }
    });

    // Handle cancellation of the promise.
    promise.addListener(new GenericFutureListener<Promise<Rpc>>() {
        @Override
        public void operationComplete(Promise<Rpc> p) {
            if (p.isCancelled()) {
                cf.cancel(true);
            }
        }
    });

    return promise;
}

From source file:org.robotninjas.protobuf.netty.server.RpcServer.java

License:Open Source License

<T extends ServerSocketChannel> RpcServer(EventLoopGroup eventLoopGroup,
        Optional<EventExecutorGroup> eventExecutor, Class<T> channel, SocketAddress address) {
    this.address = address;
    this.allChannels = new DefaultChannelGroup(eventLoopGroup.next());
    this.handler = new ServerHandler(allChannels);
    this.bootstrap = new ServerBootstrap();
    bootstrap.channel(channel);//from   ww w . j ava 2 s .co  m
    if (eventExecutor.isPresent()) {
        bootstrap.childHandler(new ServerInitializer(eventExecutor.get(), handler));
    } else {
        bootstrap.childHandler(new ServerInitializer(handler));
    }
    bootstrap.group(eventLoopGroup);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
}

From source file:org.vertx.java.core.impl.DefaultContext.java

License:Open Source License

protected DefaultContext(VertxInternal vertx, Executor orderedBgExec) {
    this.vertx = vertx;
    this.orderedBgExec = orderedBgExec;
    EventLoopGroup group = vertx.getEventLoopGroup();
    if (group != null) {
        this.eventLoop = group.next();
        this.tccl = Thread.currentThread().getContextClassLoader();
    } else {/*from   ww w .  jav  a2s.c om*/
        this.eventLoop = null;
        this.tccl = null;
    }
}