本文整理汇总了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;
}
}
示例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);
}
示例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);
}
示例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);
}
});
}
示例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]);
}
示例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();
}
示例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;
}
示例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);
}
示例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());
}
示例10: closeExecutor
@Override
protected Executor closeExecutor() {
if (javaChannel().isOpen() && config().getSoLinger() > 0) {
return GlobalEventExecutor.INSTANCE;
}
return null;
}
示例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);
}
}
示例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();
}
示例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();
}
}
示例14: closeExecutor
@Override
protected Executor closeExecutor() {
if (config().getSoLinger() > 0) {
return GlobalEventExecutor.INSTANCE;
}
return null;
}
示例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());
}