Unify {Epoll,KQueue}EventLoopGroup initialization.

Motivation:
`Epoll.ensureAvailability()` is called multiple times, once in
static initialization and in a couple of the constructors.  This is
redundant and confusing to read.

Modifications:
Move `Epoll.ensureAvailability()` call into an instance initializer
and remove all other references.  This ensures that every EELG
checks availability, while still delaying the check until
construction.  This pattern is used when there are multiple ctors,
as in this class.

Result:
Easier to read code.
This commit is contained in:
Carl Mastrangelo 2017-07-21 12:37:18 -07:00 committed by Norman Maurer
parent 452fd36240
commit d8f4547f5c
2 changed files with 3 additions and 7 deletions

View File

@ -33,8 +33,8 @@ import java.util.concurrent.ThreadFactory;
* it only works on linux. * it only works on linux.
*/ */
public final class EpollEventLoopGroup extends MultithreadEventLoopGroup { public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
static { {
// Ensure JNI is initialized by the time this class is loaded by this time! // Ensure JNI is initialized by the time this class is loaded.
Epoll.ensureAvailability(); Epoll.ensureAvailability();
} }
@ -102,25 +102,21 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
public EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce, public EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce,
SelectStrategyFactory selectStrategyFactory) { SelectStrategyFactory selectStrategyFactory) {
super(nThreads, threadFactory, maxEventsAtOnce, selectStrategyFactory, RejectedExecutionHandlers.reject()); super(nThreads, threadFactory, maxEventsAtOnce, selectStrategyFactory, RejectedExecutionHandlers.reject());
Epoll.ensureAvailability();
} }
public EpollEventLoopGroup(int nThreads, Executor executor, SelectStrategyFactory selectStrategyFactory) { public EpollEventLoopGroup(int nThreads, Executor executor, SelectStrategyFactory selectStrategyFactory) {
super(nThreads, executor, 0, selectStrategyFactory, RejectedExecutionHandlers.reject()); super(nThreads, executor, 0, selectStrategyFactory, RejectedExecutionHandlers.reject());
Epoll.ensureAvailability();
} }
public EpollEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory, public EpollEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
SelectStrategyFactory selectStrategyFactory) { SelectStrategyFactory selectStrategyFactory) {
super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, RejectedExecutionHandlers.reject()); super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, RejectedExecutionHandlers.reject());
Epoll.ensureAvailability();
} }
public EpollEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory, public EpollEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
SelectStrategyFactory selectStrategyFactory, SelectStrategyFactory selectStrategyFactory,
RejectedExecutionHandler rejectedExecutionHandler) { RejectedExecutionHandler rejectedExecutionHandler) {
super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, rejectedExecutionHandler); super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, rejectedExecutionHandler);
Epoll.ensureAvailability();
} }
/** /**

View File

@ -30,7 +30,7 @@ import java.util.concurrent.ThreadFactory;
@UnstableApi @UnstableApi
public final class KQueueEventLoopGroup extends MultithreadEventLoopGroup { public final class KQueueEventLoopGroup extends MultithreadEventLoopGroup {
static { {
// Ensure JNI is initialized by the time this class is loaded by this time! // Ensure JNI is initialized by the time this class is loaded by this time!
KQueue.ensureAvailability(); KQueue.ensureAvailability();
} }