Class BlockingQueueMonitorNotificationService<T>

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.util.function.Supplier<T>, MonitorNotificationService<T>

    @ThreadSafe
    public class BlockingQueueMonitorNotificationService<T>
    extends java.lang.Object
    implements MonitorNotificationService<T>, java.util.function.Supplier<T>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Brings this service to a state where it has disposed of its resources.
      T get()
      void init()
      Brings this service to a state where it is ready to process new publication requests.
      boolean publish​(java.nio.ByteBuffer dataBuffer, TypeSupports.TypeSupport<T> typeSupport, int dataCount)
      Publishes a new value to a monitor's subscriber using a value that must first be deserialized from the supplied data buffer.
      boolean publish​(T value)
      Publishes a new value to a monitor's subscriber (which this library models as a Java Consumer) using the value that is directly supplied.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • publish

        public boolean publish​(java.nio.ByteBuffer dataBuffer,
                               TypeSupports.TypeSupport<T> typeSupport,
                               int dataCount)
        Publishes a new value to a monitor's subscriber using a value that must first be deserialized from the supplied data buffer. This method places the responsibility of value deserialization on the service implementor. This provides the extra flexibility to reuse data structures and to avoid the cost of object creation.
        Specified by:
        publish in interface MonitorNotificationService<T>
        Parameters:
        dataBuffer - the byte buffer containing the new value (which must first be deserialized).
        typeSupport - reference to an object which has the capability of deserializing the information in the byte buffer.
        dataCount - the number of items in the buffer to be deserialized.
        Returns:
        true when the new value was accepted without any loss of data; false if the oldest value in the notification buffer was discarded.
        Throws:
        java.lang.NullPointerException - if the passed value was null.
        Implementation Note:
        This implementation does not accept null as a valid publication value.
      • publish

        public boolean publish​(T value)
        Publishes a new value to a monitor's subscriber (which this library models as a Java Consumer) using the value that is directly supplied. The new value will be published to the Consumer on one or more notification threads. Where the subscriber is not immediately able to process it (eg the previous call to the Consumer is blocked) the value may optionally be buffered. If the value notification buffer becomes full the oldest value in the buffer is thrown away.
        Specified by:
        publish in interface MonitorNotificationService<T>
        Parameters:
        value - the new value.
        Returns:
        true when the new value was accepted without any loss of data; false if the oldest value in the notification buffer was discarded.
        Throws:
        java.lang.NullPointerException - if the passed value was null.
        Implementation Note:
        This implementation does not accept null as a publication value.
      • get

        public T get()
        Specified by:
        get in interface java.util.function.Supplier<T>
        Implementation Note:
        This implementation returns the oldest value from the notification queue.
      • init

        public void init()
        Brings this service to a state where it is ready to process new publication requests.

        The implementation here does not need to do anything since the service leverages off a shared ThreadPoolExecutor whose lifecycle is managed outside the scope of this object's lifetime.

        Specified by:
        init in interface MonitorNotificationService<T>
      • close

        public void close()
        Brings this service to a state where it has disposed of its resources. Threads that were created within the service are guaranteed to be destroyed.

        The implementation here does not need to do anything since the service leverages off a shared ThreadPoolExecutor whose lifecycle is managed outside the scope of this object's lifetime.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface MonitorNotificationService<T>