public void engage() { System.out.println("Starting the Disruptor"); // starts the event processors final RingBuffer<DemoEvent> ringBuf = disruptor.start(); // now we start the publishers List<Future<?>> futures = new ArrayList<Future<?>>(); ExecutorService execService = Executors.newFixedThreadPool(NUM_PUBLISHERS); try { for (DisruptorDemoPublisher pub : pubs) { futures.add(execService.submit(pub)); } // wait for each publisher to finish for (Future<?> f : futures) { f.get(); } // this should wait until all events are processed disruptor.shutdown(); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } finally { execService.shutdown(); } }
@Override public void stop() { // close all, tcp, udp, multicast synchronized (this) { thread.stop(); // events shouldn't hit the disruptor any more disrupt.shutdown(); } }
public void shutdownGracefully() throws IllegalStateException { if (disruptor == null) { throw new IllegalStateException("disruptor == null, call init"); } for (ExchangeEventProducer<T> producer : producers) { producer.stop(); } try { disruptor.shutdown(shutdownTimeout, TimeUnit.MINUTES); } catch (TimeoutException ex) { LOG.error(ex.getMessage()); } }
public static void stop() { final Disruptor<RingBufferLogEvent> temp = disruptor; // Must guarantee that publishing to the RingBuffer has stopped // before we call disruptor.shutdown() disruptor = null; // client code fails with NPE if log after stop = OK if (temp == null) { return; // stop() has already been called } // Calling Disruptor.shutdown() will wait until all enqueued events are fully processed, // but this waiting happens in a busy-spin. To avoid (postpone) wasting CPU, // we sleep in short chunks, up to 10 seconds, waiting for the ringbuffer to drain. for (int i = 0; hasBacklog(temp) && i < MAX_DRAIN_ATTEMPTS_BEFORE_SHUTDOWN; i++) { try { Thread.sleep(SLEEP_MILLIS_BETWEEN_DRAIN_ATTEMPTS); // give up the CPU for a while } catch (final InterruptedException e) { // ignored } } temp.shutdown(); // busy-spins until all events currently in the disruptor have been processed EXECUTOR.shutdown(); // finally, kill the processor thread Info.THREADLOCAL.remove(); // LOG4J2-323 }
public void close() { for (Disruptor<RecordsHolder> disruptor : this.disruptorMap.values()) { disruptor.shutdown(); } }
@Override public void stop() throws Exception { initProcess(); disruptor.shutdown(); }