Package ch.cern.dirq

Class QueueNull

java.lang.Object
ch.cern.dirq.QueueNull
All Implemented Interfaces:
Queue, Iterable<String>

public class QueueNull extends Object implements Queue
QueueNull - object oriented interface to a null directory based queue.
The goal of this module is to offer a null queue system using the same API as the other directory queue implementations. The queue will behave like a black hole: added data will disappear immediately so the queue will therefore always appear empty.
This can be used for testing purposes or to discard data like one would do on Unix by redirecting output to /dev/null.
Please refer to Queue for general information about directory queues.
All the methods that add data will return an invalid element name.
All the methods that work on elements will throw an UnsupportedOperationException exception.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
    Iterator for the null directory queue (private).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the null directory queue.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(byte[] data)
    Add byte array data to the queue.
    add(String data)
    Add String data to the queue.
    Add the given file (identified by its path) to the queue and return the corresponding element name, the file must be on the same filesystem and will be moved to the queue.
    int
    Return the number of elements in the queue.
    get(String name)
    Get the given locked element as String data.
    byte[]
    Get the given locked element as byte array data.
    Return a unique identifier for the queue.
    Get the path of the given locked element.
    Return the path of the queue.
    Iterator for the null directory queue.
    boolean
    lock(String name)
    Lock an element in permissive mode.
    boolean
    lock(String name, boolean permissive)
    Lock an element.
    void
    Purge the queue by removing unused intermediate directories, removing too old temporary elements and unlocking too old locked elements (aka staled locks); note: this can take a long time on queues with many elements.
    void
    purge(int maxLock)
    Purge the queue by removing unused intermediate directories, removing too old temporary elements and unlocking too old locked elements (aka staled locks); note: this can take a long time on queues with many elements.
    void
    purge(int maxLock, int maxTemp)
    Purge the queue by removing unused intermediate directories, removing too old temporary elements and unlocking too old locked elements (aka staled locks); note: this can take a long time on queues with many elements.
    void
    remove(String name)
    Remove a locked element from the queue.
    boolean
    unlock(String name)
    Unlock an element in non-permissive mode.
    boolean
    unlock(String name, boolean permissive)
    Unlock an element.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • QueueNull

      public QueueNull()
      Constructor for the null directory queue.
  • Method Details

    • getQueuePath

      public String getQueuePath()
      Description copied from interface: Queue
      Return the path of the queue.
      Specified by:
      getQueuePath in interface Queue
      Returns:
      queue path
    • getId

      public String getId()
      Description copied from interface: Queue
      Return a unique identifier for the queue.
      Specified by:
      getId in interface Queue
      Returns:
      unique queue identifier
    • add

      public String add(String data)
      Description copied from interface: Queue
      Add String data to the queue.
      Specified by:
      add in interface Queue
      Parameters:
      data - data to be added
      Returns:
      element name (as directory_name/file_name)
    • add

      public String add(byte[] data)
      Description copied from interface: Queue
      Add byte array data to the queue.
      Specified by:
      add in interface Queue
      Parameters:
      data - data to be added
      Returns:
      element name (as directory_name/file_name)
    • addPath

      public String addPath(String path) throws IOException
      Description copied from interface: Queue
      Add the given file (identified by its path) to the queue and return the corresponding element name, the file must be on the same filesystem and will be moved to the queue.
      Specified by:
      addPath in interface Queue
      Parameters:
      path - path of the file to be added
      Returns:
      element name (as directory_name/file_name)
      Throws:
      IOException - if any file operation fails
    • get

      public String get(String name)
      Description copied from interface: Queue
      Get the given locked element as String data.
      Specified by:
      get in interface Queue
      Parameters:
      name - name of the element to be retrieved
      Returns:
      data associated with the given element
    • getAsByteArray

      public byte[] getAsByteArray(String name)
      Description copied from interface: Queue
      Get the given locked element as byte array data.
      Specified by:
      getAsByteArray in interface Queue
      Parameters:
      name - name of the element to be retrieved
      Returns:
      data associated with the given element
    • getPath

      public String getPath(String path)
      Description copied from interface: Queue
      Get the path of the given locked element.
      This pathFile can be read but not removed, you must use the remove() method for this purpose.
      Specified by:
      getPath in interface Queue
      Parameters:
      path - name of the element
      Returns:
      path of the element
    • lock

      public boolean lock(String name)
      Description copied from interface: Queue
      Lock an element in permissive mode.
      Specified by:
      lock in interface Queue
      Parameters:
      name - name of the element to be locked
      Returns:
      true on success, false if the element could not be locked
    • lock

      public boolean lock(String name, boolean permissive)
      Description copied from interface: Queue
      Lock an element.
      Specified by:
      lock in interface Queue
      Parameters:
      name - name of the element to be locked
      permissive - work in permissive mode
      Returns:
      true on success, false if the element could not be locked
    • unlock

      public boolean unlock(String name)
      Description copied from interface: Queue
      Unlock an element in non-permissive mode.
      Specified by:
      unlock in interface Queue
      Parameters:
      name - name of the element to be unlocked
      Returns:
      true on success, false if the element could not be unlocked
    • unlock

      public boolean unlock(String name, boolean permissive)
      Description copied from interface: Queue
      Unlock an element.
      Specified by:
      unlock in interface Queue
      Parameters:
      name - name of the element to be unlocked
      permissive - work in permissive mode
      Returns:
      true on success, false if the element could not be unlocked
    • remove

      public void remove(String name)
      Description copied from interface: Queue
      Remove a locked element from the queue.
      Specified by:
      remove in interface Queue
      Parameters:
      name - name of the element to be removed
    • count

      public int count()
      Description copied from interface: Queue
      Return the number of elements in the queue.
      Locked elements are counted but temporary elements are not.
      Specified by:
      count in interface Queue
      Returns:
      number of elements in the queue
    • purge

      public void purge()
      Description copied from interface: Queue
      Purge the queue by removing unused intermediate directories, removing too old temporary elements and unlocking too old locked elements (aka staled locks); note: this can take a long time on queues with many elements.
      It uses default value for maxTemp and maxLock
      Specified by:
      purge in interface Queue
    • purge

      public void purge(int maxLock)
      Description copied from interface: Queue
      Purge the queue by removing unused intermediate directories, removing too old temporary elements and unlocking too old locked elements (aka staled locks); note: this can take a long time on queues with many elements.
      Specified by:
      purge in interface Queue
      Parameters:
      maxLock - maximum time for a locked element (in seconds); if set to 0, locked elements will not be unlocked; if set to null, the object's default value will be used
    • purge

      public void purge(int maxLock, int maxTemp)
      Description copied from interface: Queue
      Purge the queue by removing unused intermediate directories, removing too old temporary elements and unlocking too old locked elements (aka staled locks); note: this can take a long time on queues with many elements.
      Specified by:
      purge in interface Queue
      Parameters:
      maxLock - maximum time for a locked element (in seconds); if set to 0, locked elements will not be unlocked; if set to null, the object's default value will be used
      maxTemp - maximum time for a temporary element (in seconds); if set to 0, temporary elements will not be removed if set to null, the object's default value will be used
    • iterator

      public Iterator<String> iterator()
      Iterator for the null directory queue.
      Specified by:
      iterator in interface Iterable<String>