本文整理匯總了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());
}
}
};
}
};
}