Enum TopicOverloadPolicy

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<TopicOverloadPolicy>

    public enum TopicOverloadPolicy
    extends java.lang.Enum<TopicOverloadPolicy>
    A policy to deal with an overloaded topic; so topic where there is no place to store new messages.

    This policy can only be used in combination with the HazelcastInstance.getReliableTopic(String).

    The reliable topic uses a Ringbuffer to store the messages. A ringbuffer doesn't track where readers are, so it has no concept of a slow consumers. This provides many advantages like high performance reads, but it also gives the ability to the reader to re-read the same message multiple times in case of an error.

    A ringbuffer has a limited, fixed capacity. A fast producer may overwrite old messages that are still being read by a slow consumer. To prevent this, we may configure a time-to-live on the ringbuffer (see RingbufferConfig.setTimeToLiveSeconds(int).

    Once the time-to-live is configured, the TopicOverloadPolicy controls how the publisher is going to deal with the situation that a ringbuffer is full and the oldest item in the ringbuffer is not old enough to get overwritten.

    Keep in mind that this retention period (time-to-live) can keep messages from being overwritten, even though all readers might have already completed reading.

    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      BLOCK
      The caller will wait till there space in the ringbuffer.
      DISCARD_NEWEST
      The message that was to be published is discarded.
      DISCARD_OLDEST
      Using this policy, a message that has not expired can be overwritten.
      ERROR
      The publish call immediately fails.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static TopicOverloadPolicy valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static TopicOverloadPolicy[] 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

      • DISCARD_OLDEST

        public static final TopicOverloadPolicy DISCARD_OLDEST
        Using this policy, a message that has not expired can be overwritten. No matter the retention period set, the overwrite will just overwrite the item.

        This can be a problem for slow consumers because they were promised a certain time window to process messages. But it will benefit producers and fast consumers since they are able to continue. This policy sacrifices the slow producer in favor of fast producers/consumers.

      • DISCARD_NEWEST

        public static final TopicOverloadPolicy DISCARD_NEWEST
        The message that was to be published is discarded.
      • BLOCK

        public static final TopicOverloadPolicy BLOCK
        The caller will wait till there space in the ringbuffer.
    • Method Detail

      • values

        public static TopicOverloadPolicy[] 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 (TopicOverloadPolicy c : TopicOverloadPolicy.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static TopicOverloadPolicy valueOf​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null