/** * Create a simple {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories * * @param prefix the event loop thread name prefix * * @return a new {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories */ static LoopResources create(String prefix) { return new DefaultLoopResources(prefix, DEFAULT_IO_SELECT_COUNT, DEFAULT_IO_WORKER_COUNT, true); }
/** * Create a simple {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories * * @param prefix the event loop thread name prefix * * @return a new {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories */ static LoopResources create(String prefix) { return new DefaultLoopResources(prefix, DEFAULT_IO_SELECT_COUNT, DEFAULT_IO_WORKER_COUNT, true); }
/** * Create a simple {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories * * @param prefix the event loop thread name prefix * @param workerCount number of worker threads * @param daemon should the thread be released on jvm shutdown * * @return a new {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories */ static LoopResources create(String prefix, int workerCount, boolean daemon) { if (workerCount < 1) { throw new IllegalArgumentException("Must provide a strictly positive " + "worker threads number, " + "was: " + workerCount); } return new DefaultLoopResources(prefix, workerCount, daemon); }
/** * Create a simple {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories * * @param prefix the event loop thread name prefix * @param workerCount number of worker threads * @param daemon should the thread be released on jvm shutdown * * @return a new {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories */ static LoopResources create(String prefix, int workerCount, boolean daemon) { if (workerCount < 1) { throw new IllegalArgumentException("Must provide a strictly positive " + "worker threads number, " + "was: " + workerCount); } return new DefaultLoopResources(prefix, workerCount, daemon); }
/** * Create a simple {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories * * @param prefix the event loop thread name prefix * @param selectCount number of selector threads * @param workerCount number of worker threads * @param daemon should the thread be released on jvm shutdown * * @return a new {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories */ static LoopResources create(String prefix, int selectCount, int workerCount, boolean daemon) { if (Objects.requireNonNull(prefix, "prefix") .isEmpty()) { throw new IllegalArgumentException("Cannot use empty prefix"); } if (workerCount < 1) { throw new IllegalArgumentException("Must provide a strictly positive " + "worker threads number, " + "was: " + workerCount); } if (selectCount < 1) { throw new IllegalArgumentException("Must provide a strictly positive " + "selector threads number, " + "was: " + selectCount); } return new DefaultLoopResources(prefix, selectCount, workerCount, daemon); }
/** * Create a simple {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories * * @param prefix the event loop thread name prefix * @param selectCount number of selector threads * @param workerCount number of worker threads * @param daemon should the thread be released on jvm shutdown * * @return a new {@link LoopResources} to provide automatically for {@link * EventLoopGroup} and {@link Channel} factories */ static LoopResources create(String prefix, int selectCount, int workerCount, boolean daemon) { if (Objects.requireNonNull(prefix, "prefix") .isEmpty()) { throw new IllegalArgumentException("Cannot use empty prefix"); } if (workerCount < 1) { throw new IllegalArgumentException("Must provide a strictly positive " + "worker threads number, " + "was: " + workerCount); } if (selectCount < 1) { throw new IllegalArgumentException("Must provide a strictly positive " + "selector threads number, " + "was: " + selectCount); } return new DefaultLoopResources(prefix, selectCount, workerCount, daemon); }
@Test public void disposeLaterDefers() { DefaultLoopResources loopResources = new DefaultLoopResources( "test", 0, false); Mono<Void> disposer = loopResources.disposeLater(); assertThat(loopResources.isDisposed()).isFalse(); disposer.subscribe(); assertThat(loopResources.isDisposed()).isTrue(); }
@Test public void disposeLaterSubsequentIsQuick() { DefaultLoopResources loopResources = new DefaultLoopResources( "test", 0, false); loopResources.onServer(true); assertThat(loopResources.isDisposed()).isFalse(); Duration firstInvocation = StepVerifier.create(loopResources.disposeLater()) .verifyComplete(); assertThat(loopResources.isDisposed()).isTrue(); if (!loopResources.preferNative()) { assertThat(loopResources.serverLoops.get().isTerminated()).isTrue(); } else { assertThat(loopResources.cacheNativeServerLoops.get().isTerminated()).isTrue(); } Duration secondInvocation = StepVerifier.create(loopResources.disposeLater()) .verifyComplete(); assertThat(secondInvocation).isLessThan(firstInvocation); }