1 构造
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
protected MultithreadEventExecutorGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory, Object... args ) {
if (executor == null) executor = new ThreadPerTaskExecutor(this.newDefaultThreadFactory());
this.children = new EventExecutor[nThreads];
for (int i = 0; i < nThreads; i ++) { boolean success = false; try {
children[i] = this.newChild(executor, args); success = true; } catch (Exception e) { throw new IllegalStateException("failed to create a child event loop", e); } finally { if (!success) { for (int j = 0; j < i; j ++) { children[j].shutdownGracefully(); }
for (int j = 0; j < i; j ++) { EventExecutor e = children[j]; try { while (!e.isTerminated()) { e.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS); } } catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); break; } } } } }
this.chooser = chooserFactory.newChooser(children);
final FutureListener<Object> terminationListener = new FutureListener<Object>() { @Override public void operationComplete(Future<Object> future) throws Exception { if (terminatedChildren.incrementAndGet() == children.length) terminationFuture.setSuccess(null); } };
for (EventExecutor e: children) e.terminationFuture().addListener(terminationListener);
Set<EventExecutor> childrenSet = new LinkedHashSet<EventExecutor>(children.length); Collections.addAll(childrenSet, children); readonlyChildren = Collections.unmodifiableSet(childrenSet); }
|
从上面名字就可以猜出来一定有个SingleThreadEventLoop抽象了NioEventLoop的
2 提交任务
在任务提交这件事情上,NioEventLoopGroup不进行实质性的流程处理,真正干活的是NioEventLoop这个组件。
1 2 3 4
| @Override public Future<?> submit(Runnable task) { return this.next().submit(task); }
|
Netty-11-EventLoop