@Override public void stop() { // fix bug #968,对于pool与 workerPool.halt(); simpleParserStage.halt(); sinkStoreStage.halt(); try { parserExecutor.shutdownNow(); while (!parserExecutor.awaitTermination(1, TimeUnit.SECONDS)) { if (parserExecutor.isShutdown() || parserExecutor.isTerminated()) { break; } parserExecutor.shutdownNow(); } } catch (Throwable e) { // ignore } try { stageExecutor.shutdownNow(); while (!stageExecutor.awaitTermination(1, TimeUnit.SECONDS)) { if (stageExecutor.isShutdown() || stageExecutor.isTerminated()) { break; } stageExecutor.shutdownNow(); } } catch (Throwable e) { // ignore } super.stop(); }
@Test public void shouldNotifyOfBatchProcessorLifecycle() throws Exception { new Thread(batchEventProcessor).start(); startLatch.await(); batchEventProcessor.halt(); shutdownLatch.await(); assertThat(Integer.valueOf(handler.startCounter), is(Integer.valueOf(1))); assertThat(Integer.valueOf(handler.shutdownCounter), is(Integer.valueOf(1))); }
eventLatch.await(); batchEventProcessor.halt(); thread.join();
@Test public void shouldCallExceptionHandlerOnUncaughtException() throws Exception { CountDownLatch exceptionLatch = new CountDownLatch(1); LatchExceptionHandler latchExceptionHandler = new LatchExceptionHandler(exceptionLatch); final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessor<StubEvent>( ringBuffer, sequenceBarrier, new ExceptionEventHandler()); ringBuffer.addGatingSequences(batchEventProcessor.getSequence()); batchEventProcessor.setExceptionHandler(latchExceptionHandler); Thread thread = new Thread(batchEventProcessor); thread.start(); ringBuffer.publish(ringBuffer.next()); assertTrue(exceptionLatch.await(2, TimeUnit.SECONDS)); batchEventProcessor.halt(); thread.join(); }
@Test public void shouldCallMethodsInLifecycleOrderForBatch() throws Exception { CountDownLatch eventLatch = new CountDownLatch(3); LatchEventHandler eventHandler = new LatchEventHandler(eventLatch); final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessor<StubEvent>( ringBuffer, sequenceBarrier, eventHandler); ringBuffer.addGatingSequences(batchEventProcessor.getSequence()); ringBuffer.publish(ringBuffer.next()); ringBuffer.publish(ringBuffer.next()); ringBuffer.publish(ringBuffer.next()); Thread thread = new Thread(batchEventProcessor); thread.start(); assertTrue(eventLatch.await(2, TimeUnit.SECONDS)); batchEventProcessor.halt(); thread.join(); }
@Test public void shouldReportProgressByUpdatingSequenceViaCallback() throws Exception { final RingBuffer<StubEvent> ringBuffer = createMultiProducer(StubEvent.EVENT_FACTORY, 16); final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier(); final SequenceReportingEventHandler<StubEvent> handler = new TestSequenceReportingEventHandler(); final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessor<StubEvent>( ringBuffer, sequenceBarrier, handler); ringBuffer.addGatingSequences(batchEventProcessor.getSequence()); Thread thread = new Thread(batchEventProcessor); thread.setDaemon(true); thread.start(); assertEquals(-1L, batchEventProcessor.getSequence().get()); ringBuffer.publish(ringBuffer.next()); callbackLatch.await(); assertEquals(0L, batchEventProcessor.getSequence().get()); onEndOfBatchLatch.countDown(); assertEquals(0L, batchEventProcessor.getSequence().get()); batchEventProcessor.halt(); thread.join(); }
processor2.halt();
logEntryDispatchEventProcessor.halt(); traceAlertEventProcessor.halt(); traceAnalyzeEventProcessor.halt(); traceStoreEventProcessor.halt(); metricAlertEventProcessor.halt(); metricAnalyzeEventProcessor.halt(); metricStoreEventProcessor.halt(); exceptionAlertEventProcessor.halt(); exceptionAnalyzeEventProcessor.halt(); exceptionStoreEventProcessor.halt(); appLogAlertEventProcessor.halt(); appLogAnalyzeEventProcessor.halt(); appLogStoreEventProcessor.halt(); gcLogAlertEventProcessor.halt(); gcLogAnalyzeEventProcessor.halt(); gcLogStoreEventProcessor.halt();