Class SingletonQueue<T>


  • public class SingletonQueue<T>
    extends java.lang.Object
    A simple queue that can hold at most one element while in addition provides a function to close() the queue. The queue is either empty (take() calls will block) or full (calls will block.A closed queue will not block on any put call but will silently ignore the value. Calling take() on a closed queue will always return the special end element.
    Since:
    2.0
    Version:
    2.0
    Author:
    Evren Sirin
    • Constructor Summary

      Constructors 
      Constructor Description
      SingletonQueue​(T eoq)
      Creates a new queue with the specific End-Of-Queue element.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the queue causing all blocked threads to be unblocked.
      T getEOQ()
      Returns the special end of queue (EOQ) value.
      boolean isEmpty()  
      boolean isFull()  
      void put​(T x)
      Puts a value to the queue waiting indefinitely if the queue is full.
      T take()
      Take a value from the queue waiting indefinitely if it is empty.
      • Methods inherited from class java.lang.Object

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

      • SingletonQueue

        public SingletonQueue​(T eoq)
        Creates a new queue with the specific End-Of-Queue element.
    • Method Detail

      • isFull

        public boolean isFull()
      • isEmpty

        public boolean isEmpty()
      • getEOQ

        public T getEOQ()
        Returns the special end of queue (EOQ) value.
      • put

        public void put​(T x)
                 throws java.lang.InterruptedException
        Puts a value to the queue waiting indefinitely if the queue is full. If another thread closes the queue, this function will immediately return and the value will be ignored.
        Throws:
        java.lang.InterruptedException
      • take

        public T take()
               throws java.lang.InterruptedException
        Take a value from the queue waiting indefinitely if it is empty. If another thread closes the queue, this function will immediately return the end element.
        Throws:
        java.lang.InterruptedException
      • close

        public void close()
                   throws java.lang.InterruptedException
        Closes the queue causing all blocked threads to be unblocked. All values put(Object) after this call will be ignored.
        Throws:
        java.lang.InterruptedException