io.netty.channel.SingleThreadEventLoop Java Examples
The following examples show how to use
io.netty.channel.SingleThreadEventLoop.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java From mpush with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: EtcdClient.java From etcd-java with Apache License 2.0 | 5 votes |
/** * Execute the provided task in the EventLoopGroup only once there * are no more running/queued tasks (but might be future scheduled tasks). * The key thing here is that it will continue to wait if new tasks * are scheduled by the already running/queued ones. */ private void executeWhenIdle(Runnable task) { AtomicInteger remainingTasks = new AtomicInteger(-1); // Two "cycles" are performed, the first with remainingTasks == -1. // If remainingTasks > 0 after the second cycle, this method // is re-called recursively (in an async context) CyclicBarrier cb = new CyclicBarrier(internalExecutor.executorCount(), () -> { int rt = remainingTasks.get(); if (rt == -1) { remainingTasks.incrementAndGet(); } else if (rt > 0) { executeWhenIdle(task); } else { internalExecutor.execute(task); } }); internalExecutor.forEach(ex -> ex.execute(new Runnable() { @Override public void run() { SingleThreadEventLoop stel = (SingleThreadEventLoop) ex; try { if (stel.pendingTasks() > 0) { ex.execute(this); } else { cb.await(); if (stel.pendingTasks() > 0) { remainingTasks.incrementAndGet(); } cb.await(); } } catch (InterruptedException|BrokenBarrierException e) { Thread.currentThread().interrupt(); } } })); }
Example #3
Source File: LocalChannel.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
@Override protected boolean isCompatible(EventLoop loop) { return loop instanceof SingleThreadEventLoop; }
Example #4
Source File: LocalServerChannel.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
@Override protected boolean isCompatible(EventLoop loop) { return loop instanceof SingleThreadEventLoop; }
Example #5
Source File: VirtualChannel.java From quarkus with Apache License 2.0 | 4 votes |
@Override protected boolean isCompatible(EventLoop loop) { return loop instanceof SingleThreadEventLoop; }
Example #6
Source File: VirtualServerChannel.java From quarkus with Apache License 2.0 | 4 votes |
@Override protected boolean isCompatible(EventLoop loop) { return loop instanceof SingleThreadEventLoop; }
Example #7
Source File: LocalChannel.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
@Override protected boolean isCompatible(EventLoop loop) { return loop instanceof SingleThreadEventLoop; }
Example #8
Source File: LocalServerChannel.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
@Override protected boolean isCompatible(EventLoop loop) { return loop instanceof SingleThreadEventLoop; }