/** * Creates the {@link NioEventLoopGroup} for this client. * * @param configuration The configuration * @param threadFactory The thread factory * @return The group */ protected NioEventLoopGroup createEventLoopGroup(HttpClientConfiguration configuration, ThreadFactory threadFactory) { OptionalInt numOfThreads = configuration.getNumOfThreads(); Optional<Class<? extends ThreadFactory>> threadFactoryType = configuration.getThreadFactory(); boolean hasThreads = numOfThreads.isPresent(); boolean hasFactory = threadFactoryType.isPresent(); NioEventLoopGroup group; if (hasThreads && hasFactory) { group = new NioEventLoopGroup(numOfThreads.getAsInt(), InstantiationUtils.instantiate(threadFactoryType.get())); } else if (hasThreads) { if (threadFactory != null) { group = new NioEventLoopGroup(numOfThreads.getAsInt(), threadFactory); } else { group = new NioEventLoopGroup(numOfThreads.getAsInt()); } } else { if (threadFactory != null) { group = new NioEventLoopGroup(NettyThreadFactory.DEFAULT_EVENT_LOOP_THREADS, threadFactory); } else { group = new NioEventLoopGroup(); } } return group; }
/** * Creates the {@link NioEventLoopGroup} for this client. * * @param configuration The configuration * @param threadFactory The thread factory * @return The group */ protected NioEventLoopGroup createEventLoopGroup(HttpClientConfiguration configuration, ThreadFactory threadFactory) { OptionalInt numOfThreads = configuration.getNumOfThreads(); Optional<Class<? extends ThreadFactory>> threadFactoryType = configuration.getThreadFactory(); boolean hasThreads = numOfThreads.isPresent(); boolean hasFactory = threadFactoryType.isPresent(); NioEventLoopGroup group; if (hasThreads && hasFactory) { group = new NioEventLoopGroup(numOfThreads.getAsInt(), InstantiationUtils.instantiate(threadFactoryType.get())); } else if (hasThreads) { if (threadFactory != null) { group = new NioEventLoopGroup(numOfThreads.getAsInt(), threadFactory); } else { group = new NioEventLoopGroup(numOfThreads.getAsInt()); } } else { if (threadFactory != null) { group = new NioEventLoopGroup(NettyThreadFactory.DEFAULT_EVENT_LOOP_THREADS, threadFactory); } else { group = new NioEventLoopGroup(); } } return group; }
/** * Creates the {@link NioEventLoopGroup} for this client. * * @param configuration The configuration * @param threadFactory The thread factory * @return The group */ protected NioEventLoopGroup createEventLoopGroup(HttpClientConfiguration configuration, ThreadFactory threadFactory) { OptionalInt numOfThreads = configuration.getNumOfThreads(); Optional<Class<? extends ThreadFactory>> threadFactoryType = configuration.getThreadFactory(); boolean hasThreads = numOfThreads.isPresent(); boolean hasFactory = threadFactoryType.isPresent(); NioEventLoopGroup group; if (hasThreads && hasFactory) { group = new NioEventLoopGroup(numOfThreads.getAsInt(), InstantiationUtils.instantiate(threadFactoryType.get())); } else if (hasThreads) { if (threadFactory != null) { group = new NioEventLoopGroup(numOfThreads.getAsInt(), threadFactory); } else { group = new NioEventLoopGroup(numOfThreads.getAsInt()); } } else { if (threadFactory != null) { group = new NioEventLoopGroup(NettyThreadFactory.DEFAULT_EVENT_LOOP_THREADS, threadFactory); } else { group = new NioEventLoopGroup(); } } return group; }