com.hazelcast.ringbuffer

## Enum OverflowPolicy

- java.lang.Object
- - java.lang.Enum<OverflowPolicy>
  - - com.hazelcast.ringbuffer.OverflowPolicy

- All Implemented Interfaces:
    Serializable, Comparable<OverflowPolicy>

      public enum OverflowPolicy
      extends Enum<OverflowPolicy>

  Using this policy one can control the behavior what should to be done when an item is about to be added to the ringbuffer, but there is `0` remaining capacity. Overflowing happens when a time-to-live is set and the oldest item in the ringbuffer (the head) is not old enough to expire.
  See Also:
    `Ringbuffer.addAsync(Object, OverflowPolicy)`, `Ringbuffer.addAllAsync(java.util.Collection, OverflowPolicy)`, `RingbufferConfig.setTimeToLiveSeconds(int)`

- - ### Enum Constant Summary

    Enum Constants
    Enum Constant and Description
    `FAIL` Using this policy the call will fail immediately and the oldest item will not be overwritten before it is old enough to retire.
    `OVERWRITE` Using this policy the oldest item is overwritten no matter it is not old enough to retire.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static OverflowPolicy` | `getById(int id)` Returns the OverflowPolicy for the given ID.
    `int` | `getId()` Gets the ID for the given OverflowPolicy.
    `static OverflowPolicy` | `valueOf(String name)` Returns the enum constant of this type with the specified name.
    `static OverflowPolicy[]` | `values()` Returns an array containing the constants of this enum type, in the order they are declared.

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

      `clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

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

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### Enum Constant Detail

    - #### OVERWRITE

          public static final OverflowPolicy OVERWRITE

      Using this policy the oldest item is overwritten no matter it is not old enough to retire. Using this policy you are sacrificing the time-to-live in favor of being able to write. Example: if there is a time-to-live of 30 seconds, the buffer is full and the oldest item in the ring has been placed a second ago, then there are 29 seconds remaining for that item. Using this policy you are going to overwrite no matter what.

    - #### FAIL

          public static final OverflowPolicy FAIL

      Using this policy the call will fail immediately and the oldest item will not be overwritten before it is old enough to retire. So this policy sacrificing the ability to write in favor of time-to-live. The advantage of `FAIL` is that the caller can decide what to do since it doesn't trap the thread due to backoff. Example: if there is a time-to-live of 30 seconds, the buffer is full and the oldest item in the ring has been placed a second ago, then there are 29 seconds remaining for that item. Using this policy you are not going to overwrite that item for the next 29 seconds.

  - ### Method Detail

    - #### values

          public static OverflowPolicy[] values()

      Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:

          for (OverflowPolicy c : OverflowPolicy.values())
              System.out.println(c);

      Returns:
        an array containing the constants of this enum type, in the order they are declared

    - #### valueOf

          public static OverflowPolicy valueOf(String name)

      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
        `name` - the name of the enum constant to be returned.
      Returns:
        the enum constant with the specified name
      Throws:
        `IllegalArgumentException` - if this enum type has no constant with the specified name
        `NullPointerException` - if the argument is null

    - #### getId

          public int getId()

      Gets the ID for the given OverflowPolicy. The reason this ID is used instead of an the ordinal value is that the ordinal value is more prone to changes due to reordering.
      Returns:
        the ID

    - #### getById

          public static OverflowPolicy getById(int id)

      Returns the OverflowPolicy for the given ID.
      Returns:
        the OverflowPolicy found or null if not found

Copyright © 2019. All rights reserved.