本文整理汇总了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;
}
}
示例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);
}
示例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;
}
示例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);
});
}
示例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);
}
示例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);
}
});
}
示例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]);
}
示例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);
}
});
}
示例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;
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}