com.lmax.disruptor.TimeoutException Java Examples
The following examples show how to use
com.lmax.disruptor.TimeoutException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisruptorAsyncScriptEngine.java From james with Apache License 2.0 | 6 votes |
@Override public void close() { LOG.trace("Shutting down executor..."); isRunning.set(false); try { disruptor.shutdown(5, TimeUnit.SECONDS); executor.shutdownNow(); executor.awaitTermination(5, TimeUnit.SECONDS); } catch (TimeoutException | InterruptedException e) { LOG.trace("Executor shutdown interrupted", e); } finally { LOG.trace("Executor shutdown completed."); delegate.close(); } }
Example #2
Source File: DisruptorAsyncPublisher.java From james with Apache License 2.0 | 6 votes |
@Override public void close() { LOG.trace("Shutting down executor..."); isRunning.set(false); try { disruptor.shutdown(5, TimeUnit.SECONDS); executor.shutdownNow(); executor.awaitTermination(5, TimeUnit.SECONDS); } catch (TimeoutException | InterruptedException e) { LOG.trace("Executor shutdown interrupted", e); } finally { LOG.trace("Executor shutdown completed."); delegate.close(); } }
Example #3
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 6 votes |
private synchronized List<Object> getConsumeBatch() throws AlertException, InterruptedException, TimeoutException { long endCursor = getAvailableConsumeCursor(); long currCursor = _consumer.get(); long eventNumber = endCursor - currCursor; List<Object> batch = new ArrayList<>((int) eventNumber); for (long curr = currCursor + 1; curr <= endCursor; curr++) { try { MutableObject mo = _buffer.get(curr); Object o = mo.o; mo.setObject(null); batch.add(o); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } } _consumer.set(endCursor); return batch; }
Example #4
Source File: RingBufferWorkProcessor.java From camunda-bpm-reactor with Apache License 2.0 | 6 votes |
private boolean replay(final boolean unbounded) { Sequence replayedSequence; MutableSignal<T> signal; while ((replayedSequence = processor.cancelledSequences.poll()) != null) { signal = processor.ringBuffer.get(replayedSequence.get() + 1L); try { if (signal.value == null) { barrier.waitFor(replayedSequence.get() + 1L); } readNextEvent(signal, unbounded); RingBufferSubscriberUtils.routeOnce(signal, subscriber); processor.ringBuffer.removeGatingSequence(replayedSequence); } catch (TimeoutException | InterruptedException | AlertException | CancelException ce) { processor.ringBuffer.removeGatingSequence(sequence); processor.cancelledSequences.add(replayedSequence); return true; } } return false; }
Example #5
Source File: FSHLog.java From hbase with Apache License 2.0 | 6 votes |
@Override protected void doShutdown() throws IOException { // Shutdown the disruptor. Will stop after all entries have been processed. Make sure we // have stopped incoming appends before calling this else it will not shutdown. We are // conservative below waiting a long time and if not elapsed, then halting. if (this.disruptor != null) { long timeoutms = conf.getLong("hbase.wal.disruptor.shutdown.timeout.ms", 60000); try { this.disruptor.shutdown(timeoutms, TimeUnit.MILLISECONDS); } catch (TimeoutException e) { LOG.warn("Timed out bringing down disruptor after " + timeoutms + "ms; forcing halt " + "(It is a problem if this is NOT an ABORT! -- DATALOSS!!!!)"); this.disruptor.halt(); this.disruptor.shutdown(); } } if (LOG.isDebugEnabled()) { LOG.debug("Closing WAL writer in " + CommonFSUtils.getPath(walDir)); } if (this.writer != null) { this.writer.close(); this.writer = null; } }
Example #6
Source File: AbstractDisruptorLifecycleManager.java From disruptor-spring-manager with MIT License | 5 votes |
@Override public void awaitAndShutdown(long time) { try { LOG.debug("Disruptor {} is going to shutdown in {} {}", getThreadName(), time, TimeUnit.SECONDS); disruptor.shutdown(time, TimeUnit.SECONDS); LOG.info("Disruptor {} has shutdown after {} {}.", getThreadName(), time, TimeUnit.SECONDS); } catch (TimeoutException e) { LOG.error(e.getMessage(),e); } }
Example #7
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 5 votes |
public void asyncConsumeBatchToCursor(EventHandler<Object> handler) throws AlertException, InterruptedException, TimeoutException { List<Object> batch = getConsumeBatch(); if (batch == null) return; for (int i = 0; i < batch.size(); i++) { try { handler.onEvent(batch.get(i), 0, i == (batch.size() - 1)); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } } }
Example #8
Source File: QueryLoggerDisruptor.java From phoenix with Apache License 2.0 | 5 votes |
@Override public void close() throws IOException { isClosed = true; LOGGER.info("Shutting down QueryLoggerDisruptor.."); try { //we can wait for 2 seconds, so that backlog can be committed disruptor.shutdown(2, TimeUnit.SECONDS); } catch (TimeoutException e) { throw new IOException(e); } }
Example #9
Source File: AbstractDisruptorLifecycleManagerTest.java From disruptor-spring-manager with MIT License | 5 votes |
@Test public void test_awaitAndShutdown_TimeoutException() throws TimeoutException, InterruptedException { mockDisruptor.shutdown(1, TimeUnit.SECONDS); expectLastCall().andThrow(TimeoutException.INSTANCE); replay(mockDisruptor); disruptorLifecycleManager.awaitAndShutdown(1); verify(mockDisruptor); }
Example #10
Source File: AbstractDisruptorLifecycleManagerTest.java From disruptor-spring-manager with MIT License | 5 votes |
@Test public void test_awaitAndShutdown_InterruptedException() throws TimeoutException, InterruptedException { mockDisruptor.shutdown(1, TimeUnit.SECONDS); replay(mockDisruptor); disruptorLifecycleManager.awaitAndShutdown(1); verify(mockDisruptor); }
Example #11
Source File: AbstractDisruptorLifecycleManagerTest.java From disruptor-spring-manager with MIT License | 5 votes |
@Test public void test_awaitAndShutdown() throws TimeoutException, InterruptedException { mockDisruptor.shutdown(1, TimeUnit.SECONDS); replay(mockDisruptor); disruptorLifecycleManager.awaitAndShutdown(1); verify(mockDisruptor); }
Example #12
Source File: ExchangeCore.java From exchange-core with Apache License 2.0 | 5 votes |
/** * Will throw IllegalStateException if an exchange core can not stop gracefully. * * @param timeout the amount of time to wait for all events to be processed. <code>-1</code> will give an infinite timeout * @param timeUnit the unit the timeOut is specified in */ public synchronized void shutdown(final long timeout, final TimeUnit timeUnit) { if (!stopped) { stopped = true; // TODO stop accepting new events first try { log.info("Shutdown disruptor..."); disruptor.getRingBuffer().publishEvent(SHUTDOWN_SIGNAL_TRANSLATOR); disruptor.shutdown(timeout, timeUnit); log.info("Disruptor stopped"); } catch (TimeoutException e) { throw new IllegalStateException("could not stop a disruptor gracefully. Not all events may be executed."); } } }
Example #13
Source File: ParkWaitStrategy.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
@Override public long waitFor(long sequence, Sequence cursor, Sequence dependentSequence, SequenceBarrier barrier) throws AlertException, InterruptedException, TimeoutException { long availableSequence; while ((availableSequence = dependentSequence.get()) < sequence) { barrier.checkAlert(); LockSupport.parkNanos(parkFor); } return availableSequence; }
Example #14
Source File: LoggerServiceImpl.java From gflogger with Apache License 2.0 | 5 votes |
public long waitFor( long sequence, Sequence cursor, Sequence dependentSequence, SequenceBarrier barrier ) throws AlertException, InterruptedException, TimeoutException { long availableSequence; if ((availableSequence = cursor.get()) < sequence) { flush(); synchronized (lock) { ++numWaiters; while ((availableSequence = cursor.get()) < sequence) { if (state == State.STOPPED) { disruptor.halt(); throw AlertException.INSTANCE; } barrier.checkAlert(); //*/ lock.wait(); /*/ Thread.sleep(1); //*/ } --numWaiters; } } while ((availableSequence = dependentSequence.get()) < sequence) { barrier.checkAlert(); } return availableSequence; }
Example #15
Source File: AppMain.java From perf-workshop with Apache License 2.0 | 4 votes |
public static void main(final String[] args) throws Exception { final CommandLineArgs commandLineArgs = new CommandLineArgs(); new JCommander(commandLineArgs).parse(args); final Disruptor<Packet> packetDisruptor = new Disruptor<>(new Packet.Factory(commandLineArgs.getRecordLength()), commandLineArgs.getBufferSize(), newCachedThreadPool(DAEMON_THREAD_FACTORY), ProducerType.SINGLE, new SpinLoopHintBusySpinWaitStrategy()); final Overrides overrides = new Overrides(commandLineArgs); overrides.init(); final Journaller journaller = new Journaller(SYSTEM_NANO_TIMER, commandLineArgs, overrides.enableJournaller()); journaller.init(); final Histogram[] messageTransitTimeHistograms = new Histogram[commandLineArgs.getNumberOfIterations()]; setAll(messageTransitTimeHistograms, HISTOGRAMS::createHistogramForArray); final Histogram[] interMessageTimeHistograms = new Histogram[commandLineArgs.getNumberOfIterations()]; setAll(interMessageTimeHistograms, HISTOGRAMS::createHistogramForArray); packetDisruptor.handleEventsWith( runOnCpus(wrap(new Accumulator(messageTransitTimeHistograms, interMessageTimeHistograms, SYSTEM_NANO_TIMER, commandLineArgs)::process), "Accumulator", overrides.getAccumulatorThreadAffinity()), runOnCpus(wrap(journaller::process), "Journaller", overrides.getJournallerThreadAffinity())); packetDisruptor.start(); final InputReader inputReader = new InputReader(packetDisruptor.getRingBuffer(), SYSTEM_NANO_TIMER, commandLineArgs); if(commandLineArgs.runSpinners()) { System.out.println("Starting spinner threads to perturb the system"); Spinners.SPINNERS.start(); } System.out.println("Starting replay at " + new Date()); final Thread thread = DAEMON_THREAD_FACTORY.newThread(THREADS.runOnCpu(inputReader::processFiles, overrides.getProducerThreadAffinity())); thread.start(); try { thread.join(); System.out.println("Finished replay at " + new Date()); packetDisruptor.shutdown(1, TimeUnit.MINUTES); } catch (TimeoutException e) { throw new RuntimeException("Consumers did not process remaining events within timeout", e); } finally { Spinners.SPINNERS.stop(); packetDisruptor.halt(); } System.out.println("Pausing for 10 seconds..."); THREADS.sleep(10L, TimeUnit.SECONDS); }
Example #16
Source File: AgileWaitingStrategy.java From camunda-bpm-reactor with Apache License 2.0 | 4 votes |
@Override public long waitFor(long sequence, Sequence cursor, Sequence dependentSequence, SequenceBarrier barrier) throws AlertException, InterruptedException, TimeoutException { return currentStrategy.waitFor(sequence, cursor, dependentSequence, barrier); }
Example #17
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 4 votes |
private long getAvailableConsumeCursor() throws AlertException, InterruptedException, TimeoutException { final long nextSequence = _consumer.get() + 1; return _barrier.waitFor(nextSequence); }
Example #18
Source File: RingBufferSubscriberUtils.java From camunda-bpm-reactor with Apache License 2.0 | 4 votes |
public static <T> boolean waitRequestOrTerminalEvent( Sequence pendingRequest, RingBuffer<MutableSignal<T>> ringBuffer, SequenceBarrier barrier, Subscriber<? super T> subscriber, AtomicBoolean isRunning ) { final long waitedSequence = ringBuffer.getCursor() + 1L; try { MutableSignal<T> event = null; while (pendingRequest.get() < 0l) { //pause until first request if (event == null) { barrier.waitFor(waitedSequence); event = ringBuffer.get(waitedSequence); if (event.type == MutableSignal.Type.COMPLETE) { try { subscriber.onComplete(); return false; } catch (Throwable t) { Exceptions.throwIfFatal(t); subscriber.onError(t); return false; } } else if (event.type == MutableSignal.Type.ERROR) { subscriber.onError(event.error); return false; } } else { barrier.checkAlert(); } LockSupport.parkNanos(1l); } } catch (TimeoutException te) { //ignore } catch (AlertException ae) { if (!isRunning.get()) { return false; } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } return true; }
Example #19
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 4 votes |
@Override public List<Object> retreiveAvailableBatch() throws AlertException, InterruptedException, TimeoutException { // get all events in disruptor queue return getConsumeBatch(); }