Class FileTaskQueue

  • All Implemented Interfaces:
    TaskQueue

    public class FileTaskQueue
    extends Object
    implements TaskQueue
    FileTaskQueue provides a TaskQueue implementation based on flat files for the queues and semaphores.
    Author:
    richardrodgers
    • Field Detail

      • tqDir

        protected String tqDir
      • readTicket

        protected long readTicket
    • Constructor Detail

      • FileTaskQueue

        public FileTaskQueue()
    • Method Detail

      • queueNames

        public String[] queueNames()
        Description copied from interface: TaskQueue
        Returns list of queue names.
        Specified by:
        queueNames in interface TaskQueue
        Returns:
        queues the list of names of active queues
      • enqueue

        public void enqueue​(String queueName,
                            TaskQueueEntry entry)
                     throws IOException
        Description copied from interface: TaskQueue
        Queues a single entry to a named queue.
        Specified by:
        enqueue in interface TaskQueue
        Parameters:
        queueName - the name of the queue on which to write
        entry - the task entry
        Throws:
        IOException - if IO error
      • enqueue

        public void enqueue​(String queueName,
                            Set<TaskQueueEntry> entrySet)
                     throws IOException
        Description copied from interface: TaskQueue
        Queues a set of task entries to a named queue.
        Specified by:
        enqueue in interface TaskQueue
        Parameters:
        queueName - the name of the queue on which to write
        entrySet - the set of task entries
        Throws:
        IOException - if IO error
      • dequeue

        public Set<TaskQueueEntry> dequeue​(String queueName,
                                           long ticket)
                                    throws IOException
        Description copied from interface: TaskQueue
        Returns the set of task entries from the named queue. The operation locks the queue from any further enqueue or dequeue operations until a release is called. The ticket may be any number, but a timestamp should guarantee sufficient uniqueness.
        Specified by:
        dequeue in interface TaskQueue
        Parameters:
        queueName - the name of the queue to read
        ticket - a token which must be presented to release the queue
        Returns:
        set the current set of queued task entries
        Throws:
        IOException - if IO error
      • release

        public void release​(String queueName,
                            long ticket,
                            boolean remove)
        Description copied from interface: TaskQueue
        Releases the lock upon the named queue, deleting it if removeEntries is set to true.
        Specified by:
        release in interface TaskQueue
        Parameters:
        queueName - the name of the queue to release
        ticket - a token that was presented when queue was dequeued.
        remove - flag to indicate whether entries may be deleted
      • ensureQueue

        protected File ensureQueue​(String queueName)