本文整理汇总了Java中io.netty.util.concurrent.EventExecutor类的典型用法代码示例。如果您正苦于以下问题:Java EventExecutor类的具体用法?Java EventExecutor怎么用?Java EventExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventExecutor类属于io.netty.util.concurrent包,在下文中一共展示了EventExecutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
public static void main(String[] args) {
//创建客户端连接池
ClientConnectionPool clientConnectionPool = createConnectionPool();
//创建异步调用回调执行器
EventExecutor eventExecutor = createEventExecutor();
//创建同步客户端
IRobotProtocol robotProtocol = RpcClient.createService("RobotService", IRobotProtocol.class, clientConnectionPool, eventExecutor, true);
for(int i = 0; i < 10000; i++) {
String msg = robotProtocol.sendMsg("hello world! request: " + i);
System.out.println("get response: " + msg);
}
clientConnectionPool.close();
eventExecutor.shutdownGracefully();
//TODO 创建异步客户端,添加回调!
}
示例2: mapToThread
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
private EventLoop mapToThread(int affinity, HandlerRegistration handler) {
EventLoopGroup group;
// Check if a dedicated thread pool is defined for this protocol.
if (handler.config().getEventLoop() == null) {
// Use core thread pool.
group = coreEventLoopGroup;
} else {
// Use dedicated thread pool.
group = handler.config().getEventLoop();
}
List<EventLoop> eventLoops = new ArrayList<>();
// Assumes that the same group always returns its event loops in the same order.
for (Iterator<EventExecutor> it = group.iterator(); it.hasNext(); ) {
eventLoops.add((EventLoop)it.next());
}
return eventLoops.get(Utils.mod(affinity, eventLoops.size()));
}
示例3: getPoolInfo
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
public static Map<String, Object> getPoolInfo(EventLoopGroup executors) {
Map<String, Object> info = new HashMap<>(3);
int poolSize = 0, queueSize = 0, activeCount = 0;
for (EventExecutor e : executors) {
poolSize++;
if (e instanceof SingleThreadEventLoop) {
SingleThreadEventLoop executor = (SingleThreadEventLoop) e;
queueSize += executor.pendingTasks();
ThreadProperties tp = executor.threadProperties();
if (tp.state() == Thread.State.RUNNABLE) {
activeCount++;
}
}
}
info.put("poolSize(workThread)", poolSize);
info.put("activeCount(workingThread)", activeCount);
info.put("queueSize(blockedTask)", queueSize);
return info;
}
示例4: unrecoverableErrorOccurred
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
@Override
public void unrecoverableErrorOccurred(Throwable error, boolean guaranteesBrokenDownstreamResponse) {
// Cancel request streaming so it stops trying to send data downstream and releases any chunks we've been
// holding onto. This holds true no matter the value of guaranteesBrokenDownstreamResponse
// (i.e. we want to stop sending data downstream no matter what). Note that this does not stop the
// downstream call's response, and that is intentional to support use cases where the downstream
// system can still successfully send a full response even though the request wasn't fully sent.
proxyRouterProcessingState.cancelRequestStreaming(error, ctx);
setDownstreamCallTimeOnRequestAttributesIfNotAlreadyDone();
EventExecutor executor = ctx.executor();
if (executor.inEventLoop()) {
sendUnrecoverableErrorDownPipeline(error, guaranteesBrokenDownstreamResponse);
}
else {
executor.execute(() -> sendUnrecoverableErrorDownPipeline(error, guaranteesBrokenDownstreamResponse));
}
}
示例5: initialize
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
private void initialize(ChannelHandlerContext ctx) {
// Avoid the case where destroy() is called before scheduling timeouts.
// See: https://github.com/netty/netty/issues/143
switch (state) {
case 1:
case 2:
return;
}
state = 1;
EventExecutor loop = ctx.executor();
lastWriteTime = System.nanoTime();
writerIdleTimeout = loop.schedule(
new WriterIdleTimeoutTask(ctx),
writerIdleTimeNanos, TimeUnit.NANOSECONDS);
}
示例6: testChannelPromiseWithValidExecutor
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
/**
* Validates successful {@link WebSessionResources#close()} with valid CloseFuture and other parameters.
* @throws Exception
*/
@Test
public void testChannelPromiseWithValidExecutor() throws Exception {
try {
EventExecutor mockExecutor = mock(EventExecutor.class);
ChannelPromise closeFuture = new DefaultChannelPromise(null, mockExecutor);
webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock
(UserSession.class), closeFuture);
webSessionResources.close();
verify(webSessionResources.getAllocator()).close();
verify(webSessionResources.getSession()).close();
verify(mockExecutor).inEventLoop();
verify(mockExecutor).execute(any(Runnable.class));
assertTrue(webSessionResources.getCloseFuture() == null);
assertTrue(!listenerComplete);
} catch (Exception e) {
fail();
}
}
示例7: testDoubleClose
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
/**
* Validates double call to {@link WebSessionResources#close()} doesn't throw any exception.
* @throws Exception
*/
@Test
public void testDoubleClose() throws Exception {
try {
ChannelPromise closeFuture = new DefaultChannelPromise(null, mock(EventExecutor.class));
webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock
(UserSession.class), closeFuture);
webSessionResources.close();
verify(webSessionResources.getAllocator()).close();
verify(webSessionResources.getSession()).close();
assertTrue(webSessionResources.getCloseFuture() == null);
webSessionResources.close();
} catch (Exception e) {
fail();
}
}
示例8: renegotiate
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
/**
* Performs TLS renegotiation.
*/
public Future<Channel> renegotiate(final Promise<Channel> promise) {
if (promise == null) {
throw new NullPointerException("promise");
}
ChannelHandlerContext ctx = this.ctx;
if (ctx == null) {
throw new IllegalStateException();
}
EventExecutor executor = ctx.executor();
if (!executor.inEventLoop()) {
executor.execute(new OneTimeTask() {
@Override
public void run() {
handshake(promise);
}
});
return promise;
}
handshake(promise);
return promise;
}
示例9: toLong
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
public static PromiseConverter<Long> toLong(EventExecutor executor) {
return new PromiseConverter<Long>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Long> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess((Long) resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例10: fireChannelRegistered
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
@Override
public ChannelHandlerContext fireChannelRegistered() {
final AbstractChannelHandlerContext next = findContextInbound();
EventExecutor executor = next.executor();
if (executor.inEventLoop()) {
next.invokeChannelRegistered();
} else {
executor.execute(new OneTimeTask() {
@Override
public void run() {
next.invokeChannelRegistered();
}
});
}
return this;
}
示例11: fireChannelUnregistered
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
@Override
public ChannelHandlerContext fireChannelUnregistered() {
final AbstractChannelHandlerContext next = findContextInbound();
EventExecutor executor = next.executor();
if (executor.inEventLoop()) {
next.invokeChannelUnregistered();
} else {
executor.execute(new OneTimeTask() {
@Override
public void run() {
next.invokeChannelUnregistered();
}
});
}
return this;
}
示例12: fireChannelActive
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
@Override
public ChannelHandlerContext fireChannelActive() {
final AbstractChannelHandlerContext next = findContextInbound();
EventExecutor executor = next.executor();
if (executor.inEventLoop()) {
next.invokeChannelActive();
} else {
executor.execute(new OneTimeTask() {
@Override
public void run() {
next.invokeChannelActive();
}
});
}
return this;
}
示例13: fireChannelInactive
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
@Override
public ChannelHandlerContext fireChannelInactive() {
final AbstractChannelHandlerContext next = findContextInbound();
EventExecutor executor = next.executor();
if (executor.inEventLoop()) {
next.invokeChannelInactive();
} else {
executor.execute(new OneTimeTask() {
@Override
public void run() {
next.invokeChannelInactive();
}
});
}
return this;
}
示例14: fireUserEventTriggered
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
@Override
public ChannelHandlerContext fireUserEventTriggered(final Object event) {
if (event == null) {
throw new NullPointerException("event");
}
final AbstractChannelHandlerContext next = findContextInbound();
EventExecutor executor = next.executor();
if (executor.inEventLoop()) {
next.invokeUserEventTriggered(event);
} else {
executor.execute(new OneTimeTask() {
@Override
public void run() {
next.invokeUserEventTriggered(event);
}
});
}
return this;
}
示例15: toBytes
import io.netty.util.concurrent.EventExecutor; //导入依赖的package包/类
public static PromiseConverter<byte[]> toBytes(EventExecutor executor) {
return new PromiseConverter<byte[]>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<byte[]> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess((byte[]) resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}