当前位置: 首页>>代码示例>>Java>>正文


Java Sequence类代码示例

本文整理汇总了Java中com.lmax.disruptor.Sequence的典型用法代码示例。如果您正苦于以下问题:Java Sequence类的具体用法?Java Sequence怎么用?Java Sequence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Sequence类属于com.lmax.disruptor包,在下文中一共展示了Sequence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MultiBufferBatchEventProcessor

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
public MultiBufferBatchEventProcessor(
    DataProvider<T>[] providers,
    SequenceBarrier[] barriers,
    EventHandler<T> handler)
{
    if (providers.length != barriers.length)
    {
        throw new IllegalArgumentException();
    }

    this.providers = providers;
    this.barriers = barriers;
    this.handler = handler;

    this.sequences = new Sequence[providers.length];
    for (int i = 0; i < sequences.length; i++)
    {
        sequences[i] = new Sequence(-1);
    }
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:21,代码来源:MultiBufferBatchEventProcessor.java

示例2: shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
@Test
public void shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately() throws Exception
{
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);

    disruptor.handleEventsWith(
                               new EventProcessorFactory<TestEvent>()
                               {
                                   @Override
                                   public EventProcessor createEventProcessor(
                                                                              final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences)
                                   {
                                       assertEquals("Should not have had any barrier sequences", 0, barrierSequences.length);
                                       return new BatchEventProcessor<TestEvent>(
                                                                                 disruptor.getRingBuffer(), ringBuffer.newBarrier(
                                                                                                                                  barrierSequences), eventHandler);
                                   }
                               });

    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch);
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:23,代码来源:DisruptorTest.java

示例3: shouldHonourDependenciesForCustomProcessors

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
@Test
public void shouldHonourDependenciesForCustomProcessors() throws Exception
{
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();

    disruptor.handleEventsWith(delayedEventHandler).then(
        new EventProcessorFactory<TestEvent>()
        {
            @Override
            public EventProcessor createEventProcessor(
                final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences)
            {
                assertSame("Should have had a barrier sequence", 1, barrierSequences.length);
                return new BatchEventProcessor<TestEvent>(
                    disruptor.getRingBuffer(), ringBuffer.newBarrier(
                    barrierSequences), eventHandler);
            }
        });

    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:24,代码来源:DisruptorTest.java

示例4: RingBufferProcessor

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
private RingBufferProcessor(String name,
                            ExecutorService executor,
                            int bufferSize,
                            WaitStrategy waitStrategy,
                            boolean shared,
                            boolean autoCancel) {
  super(name, executor, autoCancel);

  this.ringBuffer = RingBuffer.create(
    shared ? ProducerType.MULTI : ProducerType.SINGLE,
    new EventFactory<MutableSignal<E>>() {
      @Override
      public MutableSignal<E> newInstance() {
        return new MutableSignal<E>();
      }
    },
    bufferSize,
    waitStrategy
  );

  this.recentSequence = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);
  this.barrier = ringBuffer.newBarrier();
  //ringBuffer.addGatingSequences(recentSequence);
}
 
开发者ID:camunda,项目名称:camunda-bpm-reactor,代码行数:25,代码来源:RingBufferProcessor.java

示例5: replay

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
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;
}
 
开发者ID:camunda,项目名称:camunda-bpm-reactor,代码行数:21,代码来源:RingBufferWorkProcessor.java

示例6: DisruptorQueueImpl

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
public DisruptorQueueImpl(String queueName, ProducerType producerType,
		int bufferSize, WaitStrategy wait) {
	this._queueName = PREFIX + queueName;
	_buffer = RingBuffer.create(producerType, new ObjectEventFactory(),
			bufferSize, wait);
	_consumer = new Sequence();
	_barrier = _buffer.newBarrier();
	_buffer.addGatingSequences(_consumer);
	if (producerType == ProducerType.SINGLE) {
		consumerStartedFlag = true;
	} else {
		// make sure we flush the pending messages in cache first
		if (bufferSize < 2) {
			throw new RuntimeException("QueueSize must >= 2");
		}
		try {
			publishDirect(FLUSH_CACHE, true);
		} catch (InsufficientCapacityException e) {
			throw new RuntimeException("This code should be unreachable!",
					e);
		}
	}
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:24,代码来源:DisruptorQueueImpl.java

示例7: hasAvailableCapacity

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
private boolean hasAvailableCapacity(Sequence[] gatingSequences, final int requiredCapacity, long cursorValue)
{
    long wrapPoint = (cursorValue + requiredCapacity) - bufferSize;
    long cachedGatingSequence = gatingSequenceCache.get();

    if (wrapPoint > cachedGatingSequence || cachedGatingSequence > cursorValue)
    {
        long minSequence = Util.getMinimumSequence(gatingSequences, cursorValue);
        gatingSequenceCache.set(minSequence);

        if (wrapPoint > minSequence)
        {
            return false;
        }
    }

    return true;
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:19,代码来源:MultiProducerSequencer.java

示例8: DisruptorQueueImpl

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
public DisruptorQueueImpl(String queueName, ProducerType producerType, int bufferSize, WaitStrategy wait) {
    this._queueName = PREFIX + queueName;
    _buffer = RingBuffer.create(producerType, new ObjectEventFactory(), bufferSize, wait);
    _consumer = new Sequence();
    _barrier = _buffer.newBarrier();
    _buffer.addGatingSequences(_consumer);
    if (producerType == ProducerType.SINGLE) {
        consumerStartedFlag = true;
    } else {
        // make sure we flush the pending messages in cache first
        if (bufferSize < 2) {
            throw new RuntimeException("QueueSize must >= 2");
        }
        try {
            publishDirect(FLUSH_CACHE, true);
        } catch (InsufficientCapacityException e) {
            throw new RuntimeException("This code should be unreachable!", e);
        }
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:21,代码来源:DisruptorQueueImpl.java

示例9: init

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
/**
 * Init method.
 * 
 * @return
 */
public DisruptorQueue<ID, DATA> init() {
    /* single producer "seems" to offer better performance */
    ringBuffer = RingBuffer.createSingleProducer(EVENT_FACTORY, ringSize);
    // ringBuffer = RingBuffer.createMultiProducer(EVENT_FACTORY, ringSize);

    if (!isEphemeralDisabled()) {
        int ephemeralBoundSize = Math.max(0, getEphemeralMaxSize());
        ephemeralStorage = new ConcurrentHashMap<>(
                ephemeralBoundSize > 0 ? Math.min(ephemeralBoundSize, ringSize) : ringSize);
    }

    consumedSeq = new Sequence();
    ringBuffer.addGatingSequences(consumedSeq);
    long cursor = ringBuffer.getCursor();
    consumedSeq.set(cursor);
    knownPublishedSeq = cursor;

    return this;
}
 
开发者ID:DDTH,项目名称:ddth-queue,代码行数:25,代码来源:DisruptorQueue.java

示例10: SingleConsumerDisruptorQueue

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
/**
 * Construct a blocking queue based on disruptor.
 * 
 * @param bufferSize
 *            ring buffer size
 * @param singleProducer
 *            whether only single thread produce events.
 */
public SingleConsumerDisruptorQueue(int bufferSize, boolean singleProducer) {
    if (singleProducer) {
        ringBuffer = RingBuffer.createSingleProducer(new Factory<T>(), normalizeBufferSize(bufferSize));
    } else {
        ringBuffer = RingBuffer.createMultiProducer(new Factory<T>(), normalizeBufferSize(bufferSize));
    }

    consumedSeq = new Sequence();
    ringBuffer.addGatingSequences(consumedSeq);
    barrier = ringBuffer.newBarrier();

    long cursor = ringBuffer.getCursor();
    consumedSeq.set(cursor);
    knownPublishedSeq = cursor;
}
 
开发者ID:pulsarIO,项目名称:jetstream,代码行数:24,代码来源:SingleConsumerDisruptorQueue.java

示例11: waitFor

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
public long waitFor(long sequence, Sequence cursorSequence, Sequence dependentSequence, SequenceBarrier barrier) throws AlertException, InterruptedException {
    if(cursorSequence.get() < sequence) {
        this.lock.lock();

        try {
            while(cursorSequence.get() < sequence) {
                barrier.checkAlert();
                this.processorNotifyCondition.await();
            }
        } finally {
            this.lock.unlock();
        }
    }

    long availableSequence;
    while((availableSequence = dependentSequence.get()) < sequence) {
        barrier.checkAlert();
        LockSupport.parkNanos(1L);
    }

    return availableSequence;
}
 
开发者ID:wso2,项目名称:andes,代码行数:23,代码来源:SleepingBlockingWaitStrategy.java

示例12: RingBufferConsumer

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
RingBufferConsumer(@Nonnull final RingBuffer<T> buffer, @Nonnull final Object[] attachments) {
	if (buffer == null) {
		throw new NullPointerException("buffer == null");
	}
	if (attachments == null) {
		throw new NullPointerException("attachments == null");
	}
	if (buffer.getBufferSize() != attachments.length) {
		throw new IllegalArgumentException("buffer.getBufferSize() != attachments.length");
	}
	this.buffer = buffer;
	this.attachments = attachments;
	this.barrier = buffer.newBarrier();
	this.sequence = new Sequence();
	buffer.addGatingSequences(sequence);
	this.cursor = sequence.get();
	this.available = sequence.get();
}
 
开发者ID:ricardopadilha,项目名称:dsys-snio,代码行数:19,代码来源:RingBufferConsumer.java

示例13: DisruptorQueueImpl

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
public DisruptorQueueImpl(String queueName, ProducerType producerType, int bufferSize, WaitStrategy wait, boolean isBatch, int batchSize, long flushMs) {
    _queueName = PREFIX + queueName;
    _buffer = RingBuffer.create(producerType, new ObjectEventFactory(), bufferSize, wait);
    _consumer = new Sequence();
    _barrier = _buffer.newBarrier();
    _buffer.addGatingSequences(_consumer);
    _isBatch = isBatch;
    _cache = new ArrayList<>();
    _inputBatchSize = batchSize;
    if (_isBatch) {
        _batcher = new ThreadLocalBatch();
        _flusher = new DisruptorFlusher(Math.max(flushMs, 1));
        _flusher.start();
    } else {
        _batcher = null;
    }
}
 
开发者ID:alibaba,项目名称:jstorm,代码行数:18,代码来源:DisruptorQueueImpl.java

示例14: start

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
/**
 * <p>Starts the event processors and returns the fully configured ring buffer.</p>
 * <p>
 * <p>The ring buffer is set up to prevent overwriting any entry that is yet to
 * be processed by the slowest event processor.</p>
 * <p>
 * <p>This method must only be called once after all event processors have been added.</p>
 *
 * @return the configured ring buffer.
 */
public RingBuffer<T> start() {
    final Sequence[] gatingSequences = consumerRepository.getLastSequenceInChain(true);
    ringBuffer.addGatingSequences(gatingSequences);

    checkOnlyStartedOnce();
    for (final ConsumerInfo consumerInfo : consumerRepository) {
        consumerInfo.start(executor);
    }

    return ringBuffer;
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:22,代码来源:Disruptor.java

示例15: hasBacklog

import com.lmax.disruptor.Sequence; //导入依赖的package包/类
/**
 * Confirms if all messages have been consumed by all event processors
 */
private boolean hasBacklog() {
    final long cursor = ringBuffer.getCursor();
    for (final Sequence consumer : consumerRepository.getLastSequenceInChain(false)) {
        if (cursor > consumer.get()) {
            return true;
        }
    }
    return false;
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:13,代码来源:Disruptor.java


注:本文中的com.lmax.disruptor.Sequence类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。