org.umber.catalan.queues
Class SingleFileQueue

java.lang.Object
  extended byorg.umber.catalan.queues.SingleFileQueue
All Implemented Interfaces:
ICommandQueue
Direct Known Subclasses:
XmlFileQueue

public abstract class SingleFileQueue
extends java.lang.Object
implements ICommandQueue

Command queue which pulls commands from files on the file system.

Author:
jsheets

Constructor Summary
SingleFileQueue()
           
 
Method Summary
 boolean canQuit()
          Determines if the queue can safely shut down without losing its current status.
 void connect()
          Establishes a connection to the queue.
 void disconnect()
          Closes down the queue.
 IForgeCommand getNextCommand()
          Retrieves the next command in the queue, or null if queue is empty.
 java.io.File getQueueFile()
          Retrieves the current file that backs this queue.
 boolean isConnected()
          Determines if the queue is currently connected to a live command feed.
protected abstract  IForgeCommand[] parseQueueFile()
          Reads the contents of the file and converts it into an array of commands.
 void setQueueFile(java.io.File queueFile)
          Assigns a new queue file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.umber.catalan.queues.ICommandQueue
sendResult
 

Constructor Detail

SingleFileQueue

public SingleFileQueue()
Method Detail

parseQueueFile

protected abstract IForgeCommand[] parseQueueFile()
                                           throws CatalanQueueException
Reads the contents of the file and converts it into an array of commands. That array becomes the entire contents of the queue.

Returns:
all commands in queue
Throws:
CatalanQueueException - if unable to load file

isConnected

public boolean isConnected()
Determines if the queue is currently connected to a live command feed.

Specified by:
isConnected in interface ICommandQueue
Returns:
true if connected

canQuit

public boolean canQuit()
Determines if the queue can safely shut down without losing its current status. This should only be called between commands.

This implementation returns true when the command is empty, but false whenver there are commands in the queue.

Specified by:
canQuit in interface ICommandQueue
Returns:
true if the queue can safely disconnect now

getQueueFile

public java.io.File getQueueFile()
Retrieves the current file that backs this queue.

Returns:
queue file

setQueueFile

public void setQueueFile(java.io.File queueFile)
                  throws CatalanQueueException
Assigns a new queue file. Can only be called when not connected.

Parameters:
queueFile - file containing queue commands
Throws:
CatalanQueueException - if currently connected

connect

public void connect()
             throws CatalanQueueException
Establishes a connection to the queue. Calls loadQueueFile().

Specified by:
connect in interface ICommandQueue
Throws:
CatalanQueueException - if unable to open queue file

disconnect

public void disconnect()
                throws CatalanQueueException
Closes down the queue. Should only call this if all commands have been retrieved.

Specified by:
disconnect in interface ICommandQueue
Throws:
CatalanQueueException - if queue is not empty

getNextCommand

public IForgeCommand getNextCommand()
Retrieves the next command in the queue, or null if queue is empty.

This implementation loads commands from a single queue file.

Specified by:
getNextCommand in interface ICommandQueue
Returns:
processing command