/** * Creates a new {@link TopicProcessor} using the properties * of this builder. * @return a fresh processor */ public TopicProcessor<T> build() { this.name = this.name != null ? this.name : TopicProcessor.class.getSimpleName(); this.waitStrategy = this.waitStrategy != null ? this.waitStrategy : WaitStrategy.phasedOffLiteLock(200, 100, TimeUnit.MILLISECONDS); ThreadFactory threadFactory = this.executor != null ? null : new EventLoopFactory(name, autoCancel); ExecutorService requestTaskExecutor = this.requestTaskExecutor != null ? this.requestTaskExecutor : defaultRequestTaskExecutor(defaultName(threadFactory, TopicProcessor.class)); return new TopicProcessor<>( threadFactory, executor, requestTaskExecutor, bufferSize, waitStrategy, share, autoCancel, signalSupplier); } }
private void assertProcessor(TopicProcessor<Integer> processor, boolean shared, @Nullable String name, @Nullable Integer bufferSize, @Nullable WaitStrategy waitStrategy, @Nullable Boolean autoCancel, @Nullable ExecutorService executor, @Nullable ExecutorService requestTaskExecutor) { String expectedName = name != null ? name : TopicProcessor.class.getSimpleName(); int expectedBufferSize = bufferSize != null ? bufferSize : Queues.SMALL_BUFFER_SIZE; boolean expectedAutoCancel = autoCancel != null ? autoCancel : true; WaitStrategy expectedWaitStrategy = waitStrategy != null ? waitStrategy : WaitStrategy.phasedOffLiteLock(200, 100, TimeUnit.MILLISECONDS); Class<?> sequencerClass = shared ? MultiProducerRingBuffer.class : SingleProducerSequencer.class; assertEquals(expectedName, processor.name); assertEquals(expectedBufferSize, processor.getBufferSize()); assertEquals(expectedAutoCancel, processor.autoCancel); assertEquals(expectedWaitStrategy.getClass(), processor.ringBuffer.getSequencer().waitStrategy.getClass()); assertEquals(sequencerClass, processor.ringBuffer.getSequencer().getClass()); if (executor != null) assertEquals(executor, processor.executor); if (requestTaskExecutor != null) assertEquals(requestTaskExecutor, processor.requestTaskExecutor); }
@Test public void testForceShutdownAfterShutdown() throws InterruptedException { WorkQueueProcessor<String> processor = WorkQueueProcessor.<String>builder() .name("processor").bufferSize(4) .waitStrategy(WaitStrategy.phasedOffLiteLock(200, 100, TimeUnit.MILLISECONDS)) //eliminate the waitstrategy diff .build(); Publisher<String> publisher = Flux.fromArray(new String[] { "1", "2", "3", "4", "5" }); publisher.subscribe(processor); AssertSubscriber<String> subscriber = AssertSubscriber.create(0); processor.subscribe(subscriber); subscriber.request(1); Thread.sleep(250); processor.shutdown(); assertFalse(processor.awaitAndShutdown(Duration.ofMillis(400))); processor.forceShutdown(); assertTrue(processor.awaitAndShutdown(Duration.ofMillis(400))); }
/** * Creates a new {@link TopicProcessor} using the properties * of this builder. * @return a fresh processor */ public TopicProcessor<T> build() { this.name = this.name != null ? this.name : TopicProcessor.class.getSimpleName(); this.waitStrategy = this.waitStrategy != null ? this.waitStrategy : WaitStrategy.phasedOffLiteLock(200, 100, TimeUnit.MILLISECONDS); ThreadFactory threadFactory = this.executor != null ? null : new EventLoopFactory(name, autoCancel); ExecutorService requestTaskExecutor = this.requestTaskExecutor != null ? this.requestTaskExecutor : defaultRequestTaskExecutor(defaultName(threadFactory, TopicProcessor.class)); return new TopicProcessor<>( threadFactory, executor, requestTaskExecutor, bufferSize, waitStrategy, share, autoCancel, signalSupplier); } }