org.modeshape.common.collection.ring

## Class Consumer<T>

- java.lang.Object
- - org.modeshape.common.collection.ring.Consumer<T>

- Type Parameters:
    `T` - the type of entry
  All Implemented Interfaces:
    AutoCloseable

      @NotThreadSafe
      public abstract class Consumer<T>
      extends Object
      implements AutoCloseable

  A consumer of entries that are added to the ring buffer. Note that consumers do not need to be threadsafe, since they are called from only a single thread in the ring buffer.
  See Also:
    `RingBuffer.addConsumer(Object)`, `RingBuffer.addConsumer(Object, int)`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Consumer()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Called by the `RingBuffer` when the buffer has been shutdown and after this consumer's has `consumed` all entries that remain in the now-closed buffer.
    `abstract boolean` | `consume(T entry, long position, long maxPosition)` Consume an entry from the ring buffer.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Consumer

          public Consumer()

  - ### Method Detail

    - #### consume

          public abstract boolean consume(T entry,
                        long position,
                        long maxPosition)

      Consume an entry from the ring buffer. All exceptions should be handled by the implementation.
      Parameters:
        `entry` - the entry
        `position` - the position of the entry in the ring buffer;
        `maxPosition` - the maximum position that available in the ring buffer; in the case of a batch of entries, this may be greater than position
      Returns:
        true if the consumer should continue processing the next entry, or false if this consumer should stop

    - #### close

          public void close()

      Called by the `RingBuffer` when the buffer has been shutdown and after this consumer's has `consumed` all entries that remain in the now-closed buffer.

      This method does nothing by default, but subclasses can override it to be notified when the consumer will not be called again and can clean up any resources.

      Specified by:
        `close` in interface `AutoCloseable`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.