|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.umber.catalan.queues.DirectoryPollQueue
Queue which loads commands as files in the file system. As each single-command file is processed, the queue moves it into an old commands directory.
Constructor Summary | |
DirectoryPollQueue(java.io.File inputDir,
java.io.File outputDir)
Creates a new instance of DirectoryPollQueue. |
Method Summary | |
protected void |
archiveFile(java.io.File commandFile)
Archives a completed command file. |
protected abstract IForgeCommand |
buildCommand(java.io.File commandFile)
Converts the file into an IForgeCommand object. |
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.File |
findNextFile()
Finds the next available command file in the input directory. |
protected java.io.File |
getInputDir()
Retrieves the input directory. |
IForgeCommand |
getNextCommand()
Retrieves the next command in the queue, or null if queue is empty. |
protected java.io.File |
getOutputDir()
Retrieves the output directory. |
boolean |
isConnected()
Determines if the queue is currently connected to a live command feed. |
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 |
public DirectoryPollQueue(java.io.File inputDir, java.io.File outputDir)
inputDir
- directory to pull command files fromoutputDir
- directory to write completed command files toMethod Detail |
protected abstract IForgeCommand buildCommand(java.io.File commandFile) throws CatalanCommandException
commandFile
- File object with command data
CatalanCommandException
- if unable to load or convert the command dataprotected java.io.File getInputDir()
protected java.io.File getOutputDir()
public boolean isConnected()
isConnected
in interface ICommandQueue
public void connect() throws CatalanQueueException
This implementation checks that the input directory is writeable, and attempts to create the input and output directories if they don't already exist. The input and output must be directories, not files, and must not be null.
connect
in interface ICommandQueue
CatalanQueueException
- if unable to fully access input and
output directoriespublic void disconnect()
disconnect
in interface ICommandQueue
public boolean canQuit()
This implementation always returns true, since each file should contain a single atomic command. Subclasses which allow multiple commands per file should override this method to return false in the middle of a multi-command file.
canQuit
in interface ICommandQueue
public IForgeCommand getNextCommand() throws CatalanQueueException, CatalanCommandException
This implementation grabs the next file, in alphabetic order, from the input directory. After processing, it moves the file to the output directory. Before processing, it checks for write permissions on the file, and will abort without processing if the file cannot be deleted. (Read-only files cannot be removed from the input directory, and will interfere with queue directory lookups.)
The file sorting order can be customized by overriding findNextFile().
getNextCommand
in interface ICommandQueue
CatalanQueueException
- if the input file is not writeable (must be
able to delete it when done)
CatalanCommandException
- if unable to process the command datafindNextFile()
protected java.io.File findNextFile() throws CatalanQueueException
CatalanQueueException
- if the file is not writableprotected void archiveFile(java.io.File commandFile) throws CatalanQueueException
This method should rarely throw an exception, since in theory the findNextFile() command should verify that the file can be moved, but in practice it may happen if that check is imperfect.
Also, this may throw an exception if the file is null or doesn't exist; however, this is unlikely unless a subclass improperly overrides getNextCommand().
commandFile
- completed command
CatalanQueueException
- if unable to move the file, or if file is null
or does not exist
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |