当前位置: 首页>>代码示例>>Java>>正文


Java EventExecutor类代码示例

本文整理汇总了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 创建异步客户端,添加回调!

}
 
开发者ID:recklessMo,项目名称:nettyRpc,代码行数:18,代码来源:RpcClient.java

示例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()));
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:22,代码来源:NettyServerClient.java

示例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;
}
 
开发者ID:mpusher,项目名称:mpush,代码行数:20,代码来源:Utils.java

示例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));
    }
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:20,代码来源:ProxyRouterEndpointExecutionHandler.java

示例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);
}
 
开发者ID:projectsrepos,项目名称:jim,代码行数:19,代码来源:AutoFlushHandler.java

示例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();
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:23,代码来源:WebSessionResourcesTest.java

示例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();
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:22,代码来源:WebSessionResourcesTest.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:28,代码来源:SslHandler.java

示例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());
                    }
                }
            };
        }
    };
}
 
开发者ID:CodisLabs,项目名称:nedis,代码行数:27,代码来源:PromiseConverter.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:AbstractChannelHandlerContext.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:AbstractChannelHandlerContext.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:AbstractChannelHandlerContext.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:AbstractChannelHandlerContext.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:21,代码来源:AbstractChannelHandlerContext.java

示例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());
                    }
                }
            };
        }
    };
}
 
开发者ID:CodisLabs,项目名称:nedis,代码行数:27,代码来源:PromiseConverter.java


注:本文中的io.netty.util.concurrent.EventExecutor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。