com.lmax.disruptor
Class BatchConsumer<T extends AbstractEntry>

java.lang.Object
  extended by com.lmax.disruptor.BatchConsumer<T>
Type Parameters:
T - Entry implementation storing the data for sharing during exchange or parallel coordination of an event.
All Implemented Interfaces:
Consumer, java.lang.Runnable

public final class BatchConsumer<T extends AbstractEntry>
extends java.lang.Object
implements Consumer

Convenience class for handling the batching semantics of consuming entries from a RingBuffer and delegating the available AbstractEntrys to a BatchHandler. If the BatchHandler also implements LifecycleAware it will be notified just after the thread is started and just before the thread is shutdown.


Nested Class Summary
 class BatchConsumer.SequenceTrackerCallback
          Used by the BatchHandler to signal when it has completed consuming a given sequence.
 
Field Summary
 long p1
           
 long p10
           
 long p11
           
 long p12
           
 long p13
           
 long p14
           
 long p15
           
 long p16
           
 long p17
           
 long p18
           
 long p19
           
 long p2
           
 long p20
           
 long p3
           
 long p4
           
 long p5
           
 long p6
           
 long p7
           
 long p8
           
 long p9
           
 
Constructor Summary
BatchConsumer(ConsumerBarrier<T> consumerBarrier, BatchHandler<T> handler)
          Construct a batch consumer that will automatically track the progress by updating its sequence when the BatchHandler.onAvailable(AbstractEntry) method returns.
BatchConsumer(ConsumerBarrier<T> consumerBarrier, SequenceTrackingHandler<T> entryHandler)
          Construct a batch consumer that will rely on the SequenceTrackingHandler to callback via the BatchConsumer.SequenceTrackerCallback when it has completed with a sequence within a batch.
 
Method Summary
 ConsumerBarrier<? extends T> getConsumerBarrier()
          Get the ConsumerBarrier the Consumer is waiting on.
 long getSequence()
          Get the sequence up to which this Consumer has consumed AbstractEntrys
 void halt()
          Signal that this Consumer should stop when it has finished consuming at the next clean break.
 void run()
          It is ok to have another thread rerun this method after a halt().
 void setExceptionHandler(ExceptionHandler exceptionHandler)
          Set a new ExceptionHandler for handling exceptions propagated out of the BatchConsumer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

p1

public long p1

p2

public long p2

p3

public long p3

p4

public long p4

p5

public long p5

p6

public long p6

p7

public long p7

p8

public long p8

p9

public long p9

p10

public long p10

p11

public long p11

p12

public long p12

p13

public long p13

p14

public long p14

p15

public long p15

p16

public long p16

p17

public long p17

p18

public long p18

p19

public long p19

p20

public long p20
Constructor Detail

BatchConsumer

public BatchConsumer(ConsumerBarrier<T> consumerBarrier,
                     BatchHandler<T> handler)
Construct a batch consumer that will automatically track the progress by updating its sequence when the BatchHandler.onAvailable(AbstractEntry) method returns.

Parameters:
consumerBarrier - on which it is waiting.
handler - is the delegate to which AbstractEntrys are dispatched.

BatchConsumer

public BatchConsumer(ConsumerBarrier<T> consumerBarrier,
                     SequenceTrackingHandler<T> entryHandler)
Construct a batch consumer that will rely on the SequenceTrackingHandler to callback via the BatchConsumer.SequenceTrackerCallback when it has completed with a sequence within a batch. Sequence will be updated at the end of a batch regardless.

Parameters:
consumerBarrier - on which it is waiting.
entryHandler - is the delegate to which AbstractEntrys are dispatched.
Method Detail

getSequence

public long getSequence()
Description copied from interface: Consumer
Get the sequence up to which this Consumer has consumed AbstractEntrys

Specified by:
getSequence in interface Consumer
Returns:
the sequence of the last consumed AbstractEntry

halt

public void halt()
Description copied from interface: Consumer
Signal that this Consumer should stop when it has finished consuming at the next clean break. It will call ConsumerBarrier.alert() to notify the thread to check status.

Specified by:
halt in interface Consumer

setExceptionHandler

public void setExceptionHandler(ExceptionHandler exceptionHandler)
Set a new ExceptionHandler for handling exceptions propagated out of the BatchConsumer

Parameters:
exceptionHandler - to replace the existing exceptionHandler.

getConsumerBarrier

public ConsumerBarrier<? extends T> getConsumerBarrier()
Get the ConsumerBarrier the Consumer is waiting on.

Returns:
the barrier this Consumer is using.

run

public void run()
It is ok to have another thread rerun this method after a halt().

Specified by:
run in interface java.lang.Runnable


Copyright © 2011 LMAX Ltd. All Rights Reserved.