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


Java GlobalEventExecutor類代碼示例

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


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

示例1: closeConnectionAsync

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
@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,代碼行數:24,代碼來源:BoundNode.java

示例2: init

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
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,代碼行數:20,代碼來源:BootstrapClient.java

示例3: shutdown

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
/**
 * Disconnect from the AudioConnect server and shutdown this client.<br>
 * If this client has already been or is being shutdown, this will do nothing.<br>
 * <b>Note:</b> This client instance will no longer be able to connect after this is called.
 * @return a Future for when this client has completely disconnected and been shutdown.
 */
public Future<?> shutdown() {
    if (bootstrap.group().isShuttingDown()) {
        return GlobalEventExecutor.INSTANCE.newSucceededFuture(null);
    }

    final Promise<Object> shutdownPromise = GlobalEventExecutor.INSTANCE.newPromise();

    disconnect().addListener(new FutureListener<Object>() {

        @Override
        public void operationComplete(Future<Object> future) {
            bootstrap.group().shutdownGracefully().addListener(new PromiseNotifier<>(shutdownPromise));
        }
    });

    return shutdownPromise;
}
 
開發者ID:DeadmanDungeons,項目名稱:AudioConnect,代碼行數:24,代碼來源:AudioConnectClient.java

示例4: FibManagerImpl

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
@Inject
public FibManagerImpl(final NexthopManager nexthopManager,
                      final VrfEntryListener vrfEntryListener,
                      final BundleContext bundleContext,
                      final FibUtil fibUtil,
                      final InterVpnLinkCache interVpnLinkCache) {
    this.nexthopManager = nexthopManager;
    this.vrfEntryListener = vrfEntryListener;
    this.fibUtil = fibUtil;
    this.interVpnLinkCache = interVpnLinkCache;

    GlobalEventExecutor.INSTANCE.execute(() -> {
        final WaitingServiceTracker<IVpnManager> tracker = WaitingServiceTracker.create(
            IVpnManager.class, bundleContext);
        vpnmanager = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
        LOG.info("FibManagerImpl initialized. IVpnManager={}", vpnmanager);
    });
}
 
開發者ID:opendaylight,項目名稱:netvirt,代碼行數:19,代碼來源:FibManagerImpl.java

示例5: init

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
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,代碼行數:20,代碼來源:BootstrapClient.java

示例6: NettyIoAcceptor

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
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,代碼行數:17,代碼來源:NettyIoAcceptor.java

示例7: testTerminationFutureSuccessReflectively

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
@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,代碼行數:27,代碼來源:ThreadPerChannelEventLoopGroupTest.java

示例8: NettyIoAcceptor

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
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:termd,項目名稱:termd,代碼行數:17,代碼來源:NettyIoAcceptor.java

示例9: releaseLater

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
/**
 * Schedules the specified object to be released when the caller thread terminates. Note that this operation is
 * intended to simplify reference counting of ephemeral objects during unit tests. Do not use it beyond the
 * intended use case.
 */
public static <T> T releaseLater(T msg, int decrement) {
    if (msg instanceof ReferenceCounted) {
        synchronized (pendingReleases) {
            Thread thread = Thread.currentThread();
            List<Entry> entries = pendingReleases.get(thread);
            if (entries == null) {
                // Start the periodic releasing task (if not started yet.)
                if (pendingReleases.isEmpty()) {
                    ReleasingTask task = new ReleasingTask();
                    task.future = GlobalEventExecutor.INSTANCE.scheduleWithFixedDelay(task, 1, 1, TimeUnit.SECONDS);
                }

                // Create a new entry.
                entries = new ArrayList<Entry>();
                pendingReleases.put(thread, entries);
            }

            entries.add(new Entry((ReferenceCounted) msg, decrement));
        }
    }
    return msg;
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:28,代碼來源:ReferenceCountUtil.java

示例10: testEstablishTLS

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
/**
 * Establish PCEPS TLS connection with peer
 */
@Test
public void testEstablishTLS() {
    final DefaultPCEPSessionNegotiator negotiator = new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE),
            this.channel, this.listener, (short) 1, 20, new OpenBuilder().setKeepalive((short) 1).build(),
            SslContextFactoryTest.createTlsConfig());
    negotiator.channelActive(null);
    assertEquals(1, this.msgsSend.size());
    assertTrue(this.msgsSend.get(0) instanceof Starttls);
    assertEquals(DefaultPCEPSessionNegotiator.State.START_TLS_WAIT, negotiator.getState());
    negotiator.handleMessage(this.startTlsMsg);
    assertEquals(DefaultPCEPSessionNegotiator.State.OPEN_WAIT, negotiator.getState());
    assertEquals(2, this.msgsSend.size());
    assertTrue(this.msgsSend.get(1) instanceof Open);
    negotiator.handleMessage(this.openMsg);
    assertEquals(DefaultPCEPSessionNegotiator.State.KEEP_WAIT, negotiator.getState());
}
 
開發者ID:opendaylight,項目名稱:bgpcep,代碼行數:20,代碼來源:FiniteStateMachineTest.java

示例11: init

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
public synchronized void init() {
    this.transactionChain = this.dataBroker.createTransactionChain(this);
    final TimerTask task = new TimerTask() {
        @Override
        @SuppressWarnings("checkstyle:IllegalCatch")
        public void run() {
            synchronized (StateProviderImpl.this) {
                final WriteTransaction wTx = StateProviderImpl.this.transactionChain.newWriteOnlyTransaction();
                try {
                    updateBGPStats(wTx);
                } catch (final Exception e) {
                    LOG.warn("Failed to update BGP Stats", e);
                } finally {
                    wTx.submit();
                }
            }
        }
    };

    this.scheduleTask = GlobalEventExecutor.INSTANCE.scheduleAtFixedRate(task, 0, this.timeout,
            TimeUnit.SECONDS);
}
 
開發者ID:opendaylight,項目名稱:bgpcep,代碼行數:23,代碼來源:StateProviderImpl.java

示例12: setUp

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    super.setup();
    MockitoAnnotations.initMocks(this);
    final String hexMessages = "/bgp_hex.txt";
    final List<byte[]> bgpMessages = HexDumpBGPFileParser.parseMessages(ParserToSalTest.class.getResourceAsStream(hexMessages));
    this.mock = new BGPMock(new EventBus("test"), ServiceLoaderBGPExtensionProviderContext
            .getSingletonInstance().getMessageRegistry(), Lists.newArrayList(fixMessages(bgpMessages)));

    Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher)
            .createReconnectingClient(Mockito.any(InetSocketAddress.class), Mockito.anyInt(),
                    Mockito.any(KeyMapping.class));

    this.ext1 = new SimpleRIBExtensionProviderContext();
    this.ext2 = new SimpleRIBExtensionProviderContext();
    this.baseact = new RIBActivator();
    this.lsact = new org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator();

    this.baseact.startRIBExtensionProvider(this.ext1);
    this.lsact.startRIBExtensionProvider(this.ext2);
}
 
開發者ID:opendaylight,項目名稱:bgpcep,代碼行數:22,代碼來源:ParserToSalTest.java

示例13: sendRequestMsg

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
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,代碼行數:21,代碼來源:NetworkClientTCPConnection.java

示例14: regularUse

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
@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,代碼行數:20,代碼來源:FuturesTest.java

示例15: WebImageViewer

import io.netty.util.concurrent.GlobalEventExecutor; //導入依賴的package包/類
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,代碼行數:10,代碼來源:WebImageViewer.java


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