类io.netty.channel.SingleThreadEventLoop源码实例Demo

下面列出了怎么用io.netty.channel.SingleThreadEventLoop的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: mpush   文件: Utils.java
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;
}
 
源代码2 项目: etcd-java   文件: EtcdClient.java
/**
 * 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();
            }
        }
    }));
}
 
源代码3 项目: netty-4.1.22   文件: LocalChannel.java
@Override
protected boolean isCompatible(EventLoop loop) {
    return loop instanceof SingleThreadEventLoop;
}
 
源代码4 项目: netty-4.1.22   文件: LocalServerChannel.java
@Override
protected boolean isCompatible(EventLoop loop) {
    return loop instanceof SingleThreadEventLoop;
}
 
源代码5 项目: quarkus   文件: VirtualChannel.java
@Override
protected boolean isCompatible(EventLoop loop) {
    return loop instanceof SingleThreadEventLoop;
}
 
源代码6 项目: quarkus   文件: VirtualServerChannel.java
@Override
protected boolean isCompatible(EventLoop loop) {
    return loop instanceof SingleThreadEventLoop;
}
 
源代码7 项目: netty4.0.27Learn   文件: LocalChannel.java
@Override
protected boolean isCompatible(EventLoop loop) {
    return loop instanceof SingleThreadEventLoop;
}
 
源代码8 项目: netty4.0.27Learn   文件: LocalServerChannel.java
@Override
protected boolean isCompatible(EventLoop loop) {
    return loop instanceof SingleThreadEventLoop;
}
 
 类所在包
 同包方法