當前位置: 首頁>>代碼示例>>Java>>正文


Java GlobalEventExecutor.INSTANCE屬性代碼示例

本文整理匯總了Java中io.netty.util.concurrent.GlobalEventExecutor.INSTANCE屬性的典型用法代碼示例。如果您正苦於以下問題:Java GlobalEventExecutor.INSTANCE屬性的具體用法?Java GlobalEventExecutor.INSTANCE怎麽用?Java GlobalEventExecutor.INSTANCE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在io.netty.util.concurrent.GlobalEventExecutor的用法示例。


在下文中一共展示了GlobalEventExecutor.INSTANCE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: closeConnectionAsync

@Override
public CompletionStage<NodeConnectionReport> closeConnectionAsync(
    SocketAddress connection, CloseType type) {
  Optional<Channel> channel =
      this.clientChannelGroup
          .stream()
          .filter(c -> c.remoteAddress().equals(connection))
          .findFirst();

  if (channel.isPresent()) {
    ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    channelGroup.add(channel.get());
    ClusterConnectionReport clusterReport = new ClusterConnectionReport(getCluster().getId());
    NodeConnectionReport report =
        clusterReport.addNode(this, Collections.singletonList(connection), getAddress());

    return closeChannelGroup(channelGroup, type).thenApply(f -> report);
  } else {
    CompletableFuture<NodeConnectionReport> failedFuture = new CompletableFuture<>();
    failedFuture.completeExceptionally(new IllegalArgumentException("Not found"));
    return failedFuture;
  }
}
 
開發者ID:datastax,項目名稱:simulacron,代碼行數:23,代碼來源:BoundNode.java

示例2: init

public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap", GlobalEventExecutor.INSTANCE);

    workerExecutor = new NioEventLoopGroup();
    timer = new HashedWheelTimer();
    
    bootstrap = new Bootstrap()
    .group(workerExecutor)
    .channel(NioSocketChannel.class)
    .option(ChannelOption.SO_REUSEADDR, true)
    .option(ChannelOption.SO_KEEPALIVE, true)
    .option(ChannelOption.TCP_NODELAY, true)
    .option(ChannelOption.SO_SNDBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.SO_RCVBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, RPCService.CONNECT_TIMEOUT);
    
    pipelineFactory = new BootstrapChannelInitializer(timer, this);
    bootstrap.handler(pipelineFactory);
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:19,代碼來源:BootstrapClient.java

示例3: init

public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap", GlobalEventExecutor.INSTANCE);

    workerExecutor = new NioEventLoopGroup();
    timer = new HashedWheelTimer();

    bootstrap = new Bootstrap()
    .group(workerExecutor)
    .channel(NioSocketChannel.class)
    .option(ChannelOption.SO_REUSEADDR, true)
    .option(ChannelOption.SO_KEEPALIVE, true)
    .option(ChannelOption.TCP_NODELAY, true)
    .option(ChannelOption.SO_SNDBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.SO_RCVBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, RPCService.CONNECT_TIMEOUT);

    pipelineFactory = new BootstrapChannelInitializer(timer, this);
    bootstrap.handler(pipelineFactory);
}
 
開發者ID:zhenshengcai,項目名稱:floodlight-hardware,代碼行數:19,代碼來源:BootstrapClient.java

示例4: NettyIoAcceptor

public NettyIoAcceptor(NettyIoServiceFactory factory, IoHandler handler) {
    this.factory = factory;
    this.handler = handler;
    channelGroup = new DefaultChannelGroup("sshd-acceptor-channels", GlobalEventExecutor.INSTANCE);;
    bootstrap.group(factory.eventLoopGroup)
            .channel(NioServerSocketChannel.class)
            .option(ChannelOption.SO_BACKLOG, 100)
            .handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();
                    p.addLast(new NettyIoSession(NettyIoAcceptor.this, handler).adapter);
                }
            });
}
 
開發者ID:aeshell,項目名稱:aesh-readline,代碼行數:16,代碼來源:NettyIoAcceptor.java

示例5: testTerminationFutureSuccessReflectively

@Test
public void testTerminationFutureSuccessReflectively() throws Exception {
    Field terminationFutureField =
            ThreadPerChannelEventLoopGroup.class.getDeclaredField("terminationFuture");
    terminationFutureField.setAccessible(true);
    final Exception[] exceptionHolder = new Exception[1];
    for (int i = 0; i < 2; i++) {
        ThreadPerChannelEventLoopGroup loopGroup = new ThreadPerChannelEventLoopGroup(64);
        Promise<?> promise = new DefaultPromise<Void>(GlobalEventExecutor.INSTANCE) {
            @Override
            public Promise<Void> setSuccess(Void result) {
                try {
                    return super.setSuccess(result);
                } catch (IllegalStateException e) {
                    exceptionHolder[0] = e;
                    throw e;
                }
            }
        };
        terminationFutureField.set(loopGroup, promise);
        runTest(loopGroup);
    }
    // The global event executor will not terminate, but this will give the test a chance to fail.
    GlobalEventExecutor.INSTANCE.awaitTermination(100, TimeUnit.MILLISECONDS);
    assertNull(exceptionHolder[0]);
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:26,代碼來源:ThreadPerChannelEventLoopGroupTest.java

示例6: regularUse

@Test
public void regularUse() {
    final DefaultPromise<Boolean> target = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);
    Futures.PromiseAggregator<Boolean, Promise<Boolean>> sut = new Futures.PromiseAggregator<>(
            target);

    sut.expectMore(1);
    sut.arm();
    DefaultPromise<Boolean> part = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);
    sut.add(part);

    assertThat(target.isDone()).isFalse();

    part.setSuccess(true);

    Wait.untilTrue(target::isDone).waitOrTimeout();

    assertThat(target.isDone()).isTrue();
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:19,代碼來源:FuturesTest.java

示例7: sendRequestMsg

public <T extends MessageLite> Future<T> sendRequestMsg(ApplicationIdentifier applicationId, MessageLite appSpecificRequestMsg, final Class<T> appSpecificResponseClass) {
  ByteBuf appSpecificProtobufBytes=ProtobufByteBufCodec.encodeNoLengthPrefix(appSpecificRequestMsg);
  Future<ByteBuf> responseBytesFuture = sendRequestBytes(applicationId, appSpecificProtobufBytes);
  //FIXME should we release() something?

  //FIXME Hum, is that the proper thread to do the decoding?
  final DefaultPromise<T> responseFuture = new DefaultPromise<T>(GlobalEventExecutor.INSTANCE);
  responseBytesFuture.addListener(new GenericFutureListener<Future<? super ByteBuf>>() {
    @Override
    public void operationComplete(Future<? super ByteBuf> future) throws Exception {
      if(future.isSuccess()==false){
        responseFuture.setFailure(future.cause());
        return;
      }
      T decodedAppSpecificResponse=(T) ProtobufByteBufCodec.decodeNoLengthPrefix((ByteBuf) future.get(), appSpecificResponseClass);
      responseFuture.setSuccess(decodedAppSpecificResponse);
    }
  });
  return responseFuture;
}
 
開發者ID:pmarches,項目名稱:peercentrum-core,代碼行數:20,代碼來源:NetworkClientTCPConnection.java

示例8: WebImageViewer

public WebImageViewer(InetSocketAddress address) {
  this.address = address;
  this.bossGroup = new NioEventLoopGroup();
  this.workerGroup = new NioEventLoopGroup();
  this.allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
  this.bootstrap = new ServerBootstrap()
    .group(bossGroup, workerGroup)
    .channel(NioServerSocketChannel.class);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:9,代碼來源:WebImageViewer.java

示例9: testSerialRoundTrip

public void testSerialRoundTrip() throws InterruptedException, ExecutionException {
    final BlockingQueue<Object> serverQueue = new LinkedBlockingQueue<>();
    final BlockingQueue<Object> clientQueue = new LinkedBlockingQueue<>();
    final Promise<SocketChannel> serverChannel = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);
    final Promise<SocketChannel> clientChannel = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);

    SimpleContainer serverContainer = new SimpleContainer();
    addContext(serverContainer);
    Server server = new TestServer(serverQueue, serverChannel);
    serverContainer.register(UDPDiscoveryServer.KEY, new UDPDiscoveryServer());
    serverContainer.register(Server.KEY, server);
    try {
        SimpleContainer clientContainer = new SimpleContainer();
        addContext(clientContainer);
        Client client = new TestClient(clientQueue, clientChannel);
        clientContainer.register(UDPDiscoveryClient.KEY, new UDPDiscoveryClient());
        clientContainer.register(Client.KEY, client);

        try {
            serverChannel.await(1000);
            clientChannel.await(1000);

            runRoundTripTests(serverQueue, clientQueue, serverChannel, clientChannel);
        } finally {
            clientContainer.unregister(Client.KEY);
            client.awaitShutdown();
        }
    } finally {
        shutdownServer(serverContainer);
    }
    assertTrue(serverQueue.isEmpty());
    assertTrue(clientQueue.isEmpty());
}
 
開發者ID:SecureSmartHome,項目名稱:SecureSmartHome,代碼行數:33,代碼來源:ServerTest.java

示例10: closeExecutor

@Override
protected Executor closeExecutor() {
    if (javaChannel().isOpen() && config().getSoLinger() > 0) {
        return GlobalEventExecutor.INSTANCE;
    }
    return null;
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:7,代碼來源:NioSocketChannel.java

示例11: register

@Override
public ChannelFuture register(Channel channel) {
    if (channel == null) {
        throw new NullPointerException("channel");
    }
    try {
        EventLoop l = nextChild();
        return l.register(channel, new DefaultChannelPromise(channel, l));
    } catch (Throwable t) {
        return new FailedChannelFuture(channel, GlobalEventExecutor.INSTANCE, t);
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:12,代碼來源:ThreadPerChannelEventLoopGroup.java

示例12: testNotThrowBlockingOperationException

@Test
public void testNotThrowBlockingOperationException() throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();

    final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup);
    b.childHandler(new ChannelInboundHandlerAdapter() {
        @Override
        public void channelActive(ChannelHandlerContext ctx) {
            allChannels.add(ctx.channel());
        }
    });
    b.channel(NioServerSocketChannel.class);

    ChannelFuture f = b.bind(0).syncUninterruptibly();

    if (f.isSuccess()) {
        allChannels.add(f.channel());
        allChannels.close().awaitUninterruptibly();
    }

    bossGroup.shutdownGracefully();
    workerGroup.shutdownGracefully();
    bossGroup.terminationFuture().sync();
    workerGroup.terminationFuture().sync();
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:29,代碼來源:DefaultChannnelGroupTest.java

示例13: testBindMultiple

/**
 * Test try to reproduce issue #1335
 */
@Test
public void testBindMultiple() throws Exception {
    DefaultChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    NioEventLoopGroup group = new NioEventLoopGroup();
    try {
        for (int i = 0; i < 100; i++) {
            Bootstrap udpBootstrap = new Bootstrap();
            udpBootstrap.group(group).channel(NioDatagramChannel.class)
                    .option(ChannelOption.SO_BROADCAST, true)
                    .handler(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) {
                            // Discard
                            ReferenceCountUtil.release(msg);
                        }
                    });
            DatagramChannel datagramChannel = (DatagramChannel) udpBootstrap
                    .bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
            channelGroup.add(datagramChannel);
        }
        Assert.assertEquals(100, channelGroup.size());
    } finally {
        channelGroup.close().sync();
        group.shutdownGracefully().sync();
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:29,代碼來源:NioDatagramChannelTest.java

示例14: closeExecutor

@Override
protected Executor closeExecutor() {
    if (config().getSoLinger() > 0) {
        return GlobalEventExecutor.INSTANCE;
    }
    return null;
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:7,代碼來源:EpollSocketChannel.java

示例15: startServer

@Override
protected void startServer(int port, final Action<ServerWebSocket> websocketAction) {
  bossGroup = new NioEventLoopGroup();
  workerGroup = new NioEventLoopGroup();
  channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
  ServerBootstrap bootstrap = new ServerBootstrap();
  bootstrap.group(bossGroup, workerGroup)
    .channel(NioServerSocketChannel.class)
    .childHandler(new ChannelInitializer<SocketChannel>() {
      @Override
      public void channelActive(ChannelHandlerContext ctx) throws Exception {
        channels.add(ctx.channel());
      }

      @Override
      public void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new HttpServerCodec())
        .addLast(new AsityServerCodec() {
          @Override
          protected boolean accept(HttpRequest req) {
            return URI.create(req.getUri()).getPath().equals(TEST_URI);
          }
        }.onwebsocket(websocketAction));
      }
    });
  channels.add(bootstrap.bind(port).channel());
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:28,代碼來源:NettyServerWebSocketTest.java


注:本文中的io.netty.util.concurrent.GlobalEventExecutor.INSTANCE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。