org.modeshape.common.collection.ring

## Interface RingBuffer.ConsumerAdapter<EntryType,ConsumerType>

- Type Parameters:
    `EntryType` - the type of event
    `ConsumerType` - the type of consumer
  All Known Implementing Classes:
    RepositoryChangeBus.ChangeSetListenerConsumerAdapter
  Enclosing class:
    RingBuffer<T,C>

      public static interface RingBuffer.ConsumerAdapter<EntryType,ConsumerType>

  Adapts the `consume(Object, Object, long, long)`, `close(Object)` and `handleException(Object, Throwable, Object, long, long)` methods to other methods on an unknown type.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close(ConsumerType consumer)` Called by the `RingBuffer` when the `consume(Object, Object, long, long)` method returns false, or when the buffer has been shutdown and the consumer has `consumed` all entries in the now-closed buffer.
    `boolean` | `consume(ConsumerType consumer, EntryType entry, long position, long maxPosition)` Consume an entry from the ring buffer.
    `void` | `handleException(ConsumerType consumer, Throwable t, EntryType entry, long position, long maxPosition)` Handle an exception that was thrown from the `consume(Object, Object, long, long)`.

- - ### Method Detail

    - #### consume

          boolean consume(ConsumerType consumer,
                        EntryType entry,
                        long position,
                        long maxPosition)

      Consume an entry from the ring buffer. Generally all exceptions should be handled within this method; any exception thrown will result in the `handleException(Object, Throwable, Object, long, long)` being called.
      Parameters:
        `consumer` - the consumer instance that is to consume the event; never null
        `entry` - the entry; will not be null
        `position` - the position of the entry within in the ring buffer; this is typically a monotonically-increasing value
        `maxPosition` - the maximum position of entries in the ring buffer that are being consumed within the same batch; this will be greater or equal to `position`
      Returns:
        `true` if the consumer should continue processing the next entry, or `false` if this consumer is to stop processing any more entries (from this or subsequent batches); returning `false` provides a way for the consumer to signal that it should no longer be used

    - #### close

          void close(ConsumerType consumer)

      Called by the `RingBuffer` when the `consume(Object, Object, long, long)` method returns false, or when the buffer has been shutdown and the consumer has `consumed` all entries in the now-closed buffer.

      This method allows any resources used by the consumer to be cleaned up when no longer needed

      Parameters:
        `consumer` - the consumer instance that is being closed; never null

    - #### handleException

          void handleException(ConsumerType consumer,
                             Throwable t,
                             EntryType entry,
                             long position,
                             long maxPosition)

      Handle an exception that was thrown from the `consume(Object, Object, long, long)`.
      Parameters:
        `consumer` - the consumer instance that is to consume the event; never null
        `t` - the exception; never null
        `entry` - the entry during the consumption of which generated the exception; will not be null
        `position` - the position of the entry within in the ring buffer; this is typically a monotonically-increasing value
        `maxPosition` - the maximum position of entries in the ring buffer that are being consumed within the same batch; this will be greater or equal to `position`

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