com.lmax.disruptor.InsufficientCapacityException Java Examples
The following examples show how to use
com.lmax.disruptor.InsufficientCapacityException.
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: TaskDispatcher.java From sofa-jraft with Apache License 2.0 | 6 votes |
@Override public boolean dispatch(final Runnable message) { final RingBuffer<MessageEvent<Runnable>> ringBuffer = disruptor.getRingBuffer(); try { final long sequence = ringBuffer.tryNext(); try { final MessageEvent<Runnable> event = ringBuffer.get(sequence); event.setMessage(message); } finally { ringBuffer.publish(sequence); } return true; } catch (final InsufficientCapacityException e) { // This exception is used by the Disruptor as a global goto. It is a singleton // and has no stack trace. Don't worry about performance. return false; } }
Example #2
Source File: DataEndpointGroup.java From product-microgateway with Apache License 2.0 | 6 votes |
private void put(Event event) { do { try { long sequence = this.ringBuffer.tryNext(1); WrappedEventFactory.WrappedEvent bufferedEvent = this.ringBuffer.get(sequence); bufferedEvent.setEvent(event); this.ringBuffer.publish(sequence); return; } catch (InsufficientCapacityException ex) { try { Thread.sleep(2); } catch (InterruptedException ignored) { } } } while (isActiveDataEndpointExists()); }
Example #3
Source File: RetryDelegate.java From Electrons with MIT License | 6 votes |
public void publish(String tag, Electron electron) { try { boolean result = super.getEleCircuit().publish(tag, electron); if (!result) { retry(tag, electron); } } catch (Exception e) { if (e instanceof InsufficientCapacityException) { //满了,睡眠300ms重试 try { Thread.sleep(300); } catch (InterruptedException e1) { //ignore } retry(tag, electron); } else { logger.error("Async publish failed electron : { tag: " + tag + "electron: " + electron.toString() + "}", e); } } }
Example #4
Source File: MultiProducerSequencer.java From jstorm with Apache License 2.0 | 6 votes |
/** * @see Sequencer#tryNext(int) */ @Override public long tryNext(int n) throws InsufficientCapacityException { if (n < 1) { throw new IllegalArgumentException("n must be > 0"); } long current; long next; do { current = cursor.get(); next = current + n; if (!hasAvailableCapacity(gatingSequences, n, current)) { throw InsufficientCapacityException.INSTANCE; } } while (!cursor.compareAndSet(current, next)); return next; }
Example #5
Source File: DefaultTableStoreWriter.java From aliyun-tablestore-java-sdk with Apache License 2.0 | 6 votes |
private void addSignal(CountDownLatch latch) { while (true) { try { long sequence = ringBuffer.tryNext(); RowChangeEvent event = ringBuffer.get(sequence); event.setValue(latch); ringBuffer.publish(sequence); return; } catch (InsufficientCapacityException e) { try { Thread.sleep(1); } catch (InterruptedException exp) { } } } }
Example #6
Source File: OnePOneC.java From aliyun-tablestore-java-sdk with Apache License 2.0 | 6 votes |
public void tryPut(long value) { while (true) { try { long sequence = ringBuffer.tryNext(); LongEvent event = ringBuffer.get(sequence); event.set(value); ringBuffer.publish(sequence); return; } catch (InsufficientCapacityException e) { try { Thread.sleep(1); } catch (InterruptedException exp) { } } } }
Example #7
Source File: TaskDispatcher.java From Jupiter with Apache License 2.0 | 6 votes |
@Override public boolean dispatch(Runnable message) { RingBuffer<MessageEvent<Runnable>> ringBuffer = disruptor.getRingBuffer(); try { long sequence = ringBuffer.tryNext(); try { MessageEvent<Runnable> event = ringBuffer.get(sequence); event.setMessage(message); } finally { ringBuffer.publish(sequence); } return true; } catch (InsufficientCapacityException e) { // 这个异常是Disruptor当做全局goto使用的, 是单例的并且没有堆栈信息, 不必担心抛出异常的性能问题 return false; } }
Example #8
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Allows a variable number of user supplied arguments per event. * * @param translator The user specified translation for the event * @param batchStartsAt The first element of the array which is within the batch. * @param batchSize The actual size of the batch. * @param args User supplied arguments, one Object[] per event. * @return true if the value was published, false if there was insufficient capacity. * @see #publishEvents(EventTranslator[]) */ public boolean tryPublishEvents(EventTranslatorVararg<E> translator, int batchStartsAt, int batchSize, Object[]... args) { checkBounds(args, batchStartsAt, batchSize); try { final long finalSequence = sequencer.tryNext(batchSize); translateAndPublishBatch(translator, batchStartsAt, batchSize, finalSequence, args); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #9
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Attempts to publish an event to the ring buffer. It handles claiming the next sequence, getting the current (uninitialised) event from the ring buffer * and publishing the claimed sequence after translation. Will return false if specified capacity was not available. * * @param translator The user specified translation for the event * @return true if the value was published, false if there was insufficient capacity. */ public boolean tryPublishEvent(EventTranslator<E> translator) { try { final long sequence = sequencer.tryNext(); translateAndPublish(translator, sequence); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #10
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Allows one user supplied argument. * * @see #tryPublishEvent(EventTranslator) * @param translator The user specified translation for the event * @param arg0 A user supplied argument. * @return true if the value was published, false if there was insufficient capacity. */ public <A> boolean tryPublishEvent(EventTranslatorOneArg<E, A> translator, A arg0) { try { final long sequence = sequencer.tryNext(); translateAndPublish(translator, sequence, arg0); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #11
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Allows two user supplied arguments. * * @see #tryPublishEvent(EventTranslator) * @param translator The user specified translation for the event * @param arg0 A user supplied argument. * @param arg1 A user supplied argument. * @return true if the value was published, false if there was insufficient capacity. */ public <A, B> boolean tryPublishEvent(EventTranslatorTwoArg<E, A, B> translator, A arg0, B arg1) { try { final long sequence = sequencer.tryNext(); translateAndPublish(translator, sequence, arg0, arg1); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #12
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Allows a variable number of user supplied arguments * * @see #publishEvent(EventTranslator) * @param translator The user specified translation for the event * @param args User supplied arguments. * @return true if the value was published, false if there was insufficient capacity. */ public boolean tryPublishEvent(EventTranslatorVararg<E> translator, Object... args) { try { final long sequence = sequencer.tryNext(); translateAndPublish(translator, sequence, args); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #13
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Attempts to publish multiple events to the ring buffer. It handles claiming the next sequence, getting the current (uninitialised) event from the ring * buffer and publishing the claimed sequence after translation. Will return false if specified capacity was not available. * * @param translators The user specified translation for the event * @param batchStartsAt The first element of the array which is within the batch. * @param batchSize The actual size of the batch * @return true if all the values were published, false if there was insufficient capacity. */ public boolean tryPublishEvents(EventTranslator<E>[] translators, int batchStartsAt, int batchSize) { checkBounds(translators, batchStartsAt, batchSize); try { final long finalSequence = sequencer.tryNext(batchSize); translateAndPublishBatch(translators, batchStartsAt, batchSize, finalSequence); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #14
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Allows one user supplied argument. * * @param translator The user specified translation for each event * @param batchStartsAt The first element of the array which is within the batch. * @param batchSize The actual size of the batch * @param arg0 An array of user supplied arguments, one element per event. * @return true if the value was published, false if there was insufficient capacity. * @see #tryPublishEvents(EventTranslator[]) */ public <A> boolean tryPublishEvents(EventTranslatorOneArg<E, A> translator, int batchStartsAt, int batchSize, A[] arg0) { checkBounds(arg0, batchStartsAt, batchSize); try { final long finalSequence = sequencer.tryNext(batchSize); translateAndPublishBatch(translator, arg0, batchStartsAt, batchSize, finalSequence); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #15
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 5 votes |
public synchronized void flush() { try { if (_batcher != null && _batcher.size() > 0) { publishDirect(_batcher, true); _batcher = new ArrayList<>(_inputBatchSize); } } catch (InsufficientCapacityException e) { // Ignored we should not block } }
Example #16
Source File: SingleProducerSequencer.java From jstorm with Apache License 2.0 | 5 votes |
/** * @see Sequencer#tryNext(int) */ @Override public long tryNext(int n) throws InsufficientCapacityException { if (n < 1) { throw new IllegalArgumentException("n must be > 0"); } if (!hasAvailableCapacity(n)) { throw InsufficientCapacityException.INSTANCE; } return pad.nextValue += n; }
Example #17
Source File: DisruptorTest.java From jstorm with Apache License 2.0 | 5 votes |
public void push(DisruptorQueue queue, int num) { for (int i = 0; i < num; i++) { String msg = String.valueOf(Thread.currentThread().getId()) + "@" + i; try { queue.publish(msg, false); } catch (InsufficientCapacityException e) { e.printStackTrace(); } produceNum.incrementAndGet(); System.out.println(Thread.currentThread().getId() + " Publish one :" + i); } }
Example #18
Source File: FileDataPublisher.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private void tryPut(Event event) throws EventQueueFullException { long sequence; try { sequence = this.ringBuffer.tryNext(1); WrappedEventFactory.WrappedEvent bufferedEvent = this.ringBuffer.get(sequence); bufferedEvent.setEvent(event); this.ringBuffer.publish(sequence); } catch (InsufficientCapacityException e) { throw new EventQueueFullException("Cannot persist events because the event queue is full", e); } }
Example #19
Source File: DataEndpointGroup.java From product-microgateway with Apache License 2.0 | 5 votes |
private void tryPut(Event event) throws EventQueueFullException { long sequence; try { sequence = this.ringBuffer.tryNext(1); WrappedEventFactory.WrappedEvent bufferedEvent = this.ringBuffer.get(sequence); bufferedEvent.setEvent(event); this.ringBuffer.publish(sequence); } catch (InsufficientCapacityException e) { throw new EventQueueFullException("Cannot send events because the event queue is full", e); } }
Example #20
Source File: DefaultTableStoreWriter.java From aliyun-tablestore-java-sdk with Apache License 2.0 | 5 votes |
public boolean addRowChangeInternal(RowChange rowChange) { if (closed.get()) { throw new ClientException("The writer has been closed."); } try { long sequence = ringBuffer.tryNext(); RowChangeEvent event = ringBuffer.get(sequence); event.setValue(rowChange); ringBuffer.publish(sequence); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #21
Source File: RingBufferDispatcher.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
@Override protected Task tryAllocateTask() throws org.camunda.bpm.extension.reactor.projectreactor.processor.InsufficientCapacityException { try { long seqId = ringBuffer.tryNext(); return ringBuffer.get(seqId).setSequenceId(seqId); } catch (InsufficientCapacityException e) { throw org.camunda.bpm.extension.reactor.projectreactor.processor.InsufficientCapacityException.get(); } }
Example #22
Source File: WorkQueueDispatcher.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
@Override protected Task tryAllocateTask() throws org.camunda.bpm.extension.reactor.projectreactor.processor.InsufficientCapacityException { try { long seqId = ringBuffer.tryNext(); return ringBuffer.get(seqId).setSequenceId(seqId); } catch (InsufficientCapacityException e) { throw org.camunda.bpm.extension.reactor.projectreactor.processor.InsufficientCapacityException.get(); } }
Example #23
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 5 votes |
public synchronized void addAndFlush(Object obj) { ArrayList<Object> batchTobeFlushed = add(obj); if (batchTobeFlushed != null) { try { publishDirect(batchTobeFlushed, true); } catch (InsufficientCapacityException e) { LOG.warn("Failed to publish batch"); } } }
Example #24
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 5 votes |
public void publish(Object obj) { try { if (_isBatch) { publishBatch(obj); } else { publish(obj, true); } } catch (InsufficientCapacityException ex) { throw new RuntimeException("This code should be unreachable!"); } }
Example #25
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 5 votes |
protected void publishDirect(Object obj, boolean block) throws InsufficientCapacityException { final long id; if (block) { id = _buffer.next(); } else { id = _buffer.tryNext(1); } final MutableObject m = _buffer.get(id); m.setObject(obj); _buffer.publish(id); }
Example #26
Source File: MysqlMultiStageCoprocessor.java From canal with Apache License 2.0 | 4 votes |
private boolean publish(LogBuffer buffer, LogEvent event) { if (!isStart()) { if (exception != null) { throw exception; } return false; } boolean interupted = false; long blockingStart = 0L; int fullTimes = 0; do { /** * 由于改为processor仅终止自身stage而不是stop,那么需要由incident标识coprocessor是否正常工作。 * 让dump线程能够及时感知 */ if (exception != null) { throw exception; } try { long next = disruptorMsgBuffer.tryNext(); MessageEvent data = disruptorMsgBuffer.get(next); if (buffer != null) { data.setBuffer(buffer); } else { data.setEvent(event); } disruptorMsgBuffer.publish(next); if (fullTimes > 0) { eventsPublishBlockingTime.addAndGet(System.nanoTime() - blockingStart); } break; } catch (InsufficientCapacityException e) { if (fullTimes == 0) { blockingStart = System.nanoTime(); } // park // LockSupport.parkNanos(1L); applyWait(++fullTimes); interupted = Thread.interrupted(); if (fullTimes % 1000 == 0) { long nextStart = System.nanoTime(); eventsPublishBlockingTime.addAndGet(nextStart - blockingStart); blockingStart = nextStart; } } } while (!interupted && isStart()); return isStart(); }
Example #27
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 4 votes |
public void tryPublish(Object obj) throws InsufficientCapacityException { publish(obj, false); }
Example #28
Source File: DisruptorQueueImpl.java From jstorm with Apache License 2.0 | 4 votes |
public void publish(Object obj, boolean block) throws InsufficientCapacityException { publishDirect(obj, block); }
Example #29
Source File: SingleProducerSequencer.java From jstorm with Apache License 2.0 | 4 votes |
/** * @see Sequencer#tryNext() */ @Override public long tryNext() throws InsufficientCapacityException { return tryNext(1); }
Example #30
Source File: MultiProducerSequencer.java From jstorm with Apache License 2.0 | 4 votes |
/** * @see Sequencer#tryNext() */ @Override public long tryNext() throws InsufficientCapacityException { return tryNext(1); }