org.umber.catalan.queues
Class ReaderQueue

java.lang.Object
  extended byorg.umber.catalan.queues.ReaderQueue
All Implemented Interfaces:
ICommandQueue

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


Constructor Summary
ReaderQueue(java.io.Reader input, java.io.Writer output)
          Creates a new instance of DirectoryPollQueue.
 
Method Summary
protected abstract  IForgeCommand buildCommand(java.io.Reader input)
          Loads a IForgeCommand object from the InputStream.
 boolean canQuit()
          Determines if the queue can safely disconnect without losing its current status.
 void connect()
          Establishes a connection to the queue.
 void disconnect()
          Closes down the queue.
protected  java.io.Reader getInput()
          Retrieves the input stream.
 IForgeCommand getNextCommand()
          Retrieves the next command in the queue, or null if queue is empty.
protected  java.io.Writer getOutput()
          Retrieves the output stream.
 boolean isConnected()
          Determines if the queue is currently connected to a live command feed.
 void sendResult(CommandResult result)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReaderQueue

public ReaderQueue(java.io.Reader input,
                   java.io.Writer output)
Creates a new instance of DirectoryPollQueue.

Parameters:
input - stream to pull command files from
output - stream to write completed command files to
Method Detail

buildCommand

protected abstract IForgeCommand buildCommand(java.io.Reader input)
                                       throws CatalanCommandException
Loads a IForgeCommand object from the InputStream.

Parameters:
input - raw data stream of command data
Returns:
a command object from the InputStream
Throws:
CatalanCommandException - if unable to load or convert the command data

getInput

protected java.io.Reader getInput()
Retrieves the input stream.

Returns:
input stream

getOutput

protected java.io.Writer getOutput()
Retrieves the output stream.

Returns:
output stream

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

connect

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

This implementation checks for valid input and output streams.

Specified by:
connect in interface ICommandQueue
Throws:
CatalanQueueException - if unable to fully access input and output streams

disconnect

public void disconnect()
                throws CatalanQueueException
Closes down the queue.

This implementation closes the input and output streams.

Specified by:
disconnect in interface ICommandQueue
Throws:
CatalanQueueException - if unable to close streams.

canQuit

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

This implementation always returns true.

Specified by:
canQuit in interface ICommandQueue
Returns:
always true

getNextCommand

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

This implementation reads the next command from the InputStream.

Specified by:
getNextCommand in interface ICommandQueue
Returns:
processing command, or null if queue is empty
Throws:
CatalanQueueException - if the input stream is not readable
CatalanCommandException - if unable to process the command data

sendResult

public void sendResult(CommandResult result)
                throws CatalanQueueException
Specified by:
sendResult in interface ICommandQueue
Throws:
CatalanQueueException