Class DirPoll
java.lang.Object
org.jpos.util.SimpleLogSource
org.jpos.util.DirPoll
- All Implemented Interfaces:
FilenameFilter, Runnable, Configurable, Destroyable, LogSource
public class DirPoll
extends SimpleLogSource
implements Runnable, FilenameFilter, Configurable, Destroyable
DirPoll operates on a set of directories which defaults to
- request
- response
- tmp
- run
- bad
- archive
- Since:
- jPOS 1.2.7
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown byDirPoll.ProcessororDirPoll.FileProcessorto signal a processing error.static interfaceCallback interface for processing requestFileobjects directly.static interfaceCallback interface for processing binary request files.classRunnable that moves a request to the run directory and dispatches it to the processor. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConfigurationConfiguration for this DirPoll instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanFilenameFilterimplementation that selects files matching the current priority extension.voidaddPriority(String fileExtension) Adds a file extension to the priority list.voidCreates all required poll directories (request, response, tmp, bad, run, archive).voiddestroy()Releases resources held by this object.protected FileReturns the archive directory.protected FileReturns the bad (failed) directory.getPath()Returns the base poll directory path.longReturns the polling interval in milliseconds.Return instance implementingDirPoll.FileProcessororDirPoll.Processorprotected FileReturns the request directory.protected FileReturns the response directory.protected FileReturns the run (in-progress) directory.protected FileReturns the tmp directory.booleanisPaused()Returns whether the poll loop is currently paused.booleanReturns whether regex-based priority matching is enabled.voidpause()Pauses the poll loop.voidrun()protected Filescan()Scans the request directory for the next file to process, respecting priority order.voidsetAcceptZeroLength(boolean acceptZeroLength) Whentrue, zero-length request files are accepted.voidsetArchiveDateFormat(String dateFormat) Sets the date format pattern used when timestamping archived files.voidsetArchiveDir(String dir) Sets the archive sub-directory name relative to the base path.voidSets the bad (failed) sub-directory name relative to the base path.voidDirPool receives Configuration requests and pass along them to the underlying processor.voidSets the base poll directory and derives the standard subdirectories from it.voidsetPollInterval(long pollInterval) Sets the polling interval in milliseconds.voidsetPriorities(String priorities) Sets the file extension priority order for polling.voidsetProcessor(Object processor) Sets the processor used to handle request files.voidsetRegexPriorityMatching(boolean regexPriorityMatching) Enables or disables regex-based file extension priority matching.voidsetRequestDir(String dir) Sets the request sub-directory name relative to the base path.voidsetResponseDir(String dir) Sets the response sub-directory name relative to the base path.voidsetResponseSuffix(String suffix) Sets the suffix appended to response file names.voidSets the run (in-progress) sub-directory name relative to the base path.voidsetShouldArchive(boolean shouldArchive) Whentrue, processed request files are moved to the archive directory.voidsetShouldCompressArchive(boolean shouldCompressArchive) Whentrue, archived files are compressed.voidsetShouldTimestampArchive(boolean shouldTimestampArchive) Whentrue, archive files are timestamped.voidsetThreadPool(ExecutorService executor) Sets the thread pool used to execute processor tasks.voidSets the tmp sub-directory name relative to the base path.voidunpause()Resumes a paused poll loop.Methods inherited from class SimpleLogSource
error, error, getLogger, getRealm, info, info, setLogger, setRealm, warning, warningModifier and TypeMethodDescriptionvoidLogs an error message.voidLogs an error message with an attached object.Returns the logger.getRealm()Returns the logging realm.voidLogs an informational message.voidLogs an informational message with an attached object.voidSets the logger and realm for this log source.voidSets the logging realm.voidLogs a warning message.voidLogs a warning message with an attached object.
-
Field Details
-
cfg
Configuration for this DirPoll instance.
-
-
Constructor Details
-
DirPoll
public DirPoll()Default constructor.
-
-
Method Details
-
setPath
-
setShouldTimestampArchive
Whentrue, archive files are timestamped.- Parameters:
shouldTimestampArchive- true to timestamp archived files
-
setArchiveDateFormat
Sets the date format pattern used when timestamping archived files.- Parameters:
dateFormat- the date format pattern (seeSimpleDateFormat)
-
setShouldArchive
Whentrue, processed request files are moved to the archive directory.- Parameters:
shouldArchive- true to archive processed files
-
setShouldCompressArchive
Whentrue, archived files are compressed.- Parameters:
shouldCompressArchive- true to compress archived files
-
setAcceptZeroLength
Whentrue, zero-length request files are accepted.- Parameters:
acceptZeroLength- true to accept zero-length files
-
getPath
-
setRequestDir
Sets the request sub-directory name relative to the base path.- Parameters:
dir- the sub-directory name
-
setResponseDir
Sets the response sub-directory name relative to the base path.- Parameters:
dir- the sub-directory name
-
setTmpDir
-
setBadDir
-
setRunDir
-
setArchiveDir
Sets the archive sub-directory name relative to the base path.- Parameters:
dir- the sub-directory name
-
setPollInterval
Sets the polling interval in milliseconds.- Parameters:
pollInterval- the interval in milliseconds
-
setResponseSuffix
Sets the suffix appended to response file names.- Parameters:
suffix- the response file suffix
-
getPollInterval
-
setProcessor
Sets the processor used to handle request files.- Parameters:
processor- aDirPoll.ProcessororDirPoll.FileProcessorinstance
-
getRequestDir
-
getResponseDir
-
getTmpDir
-
getBadDir
-
getRunDir
-
getArchiveDir
-
isRegexPriorityMatching
Returns whether regex-based priority matching is enabled.- Returns:
- true if regex priority matching is active
-
setRegexPriorityMatching
Enables or disables regex-based file extension priority matching.- Parameters:
regexPriorityMatching- true to enable regex priority matching
-
getProcessor
Return instance implementingDirPoll.FileProcessororDirPoll.Processor- Returns:
- Object - need to be casted to
DirPoll.FileProcessororDirPoll.Processor
-
setConfiguration
DirPool receives Configuration requests and pass along them to the underlying processor.- Specified by:
setConfigurationin interfaceConfigurable- Parameters:
cfg- Configuration object- Throws:
ConfigurationException- on errors
-
setPriorities
Sets the file extension priority order for polling.- Parameters:
priorities- blank-separated list of file extensions in priority order
-
setThreadPool
Sets the thread pool used to execute processor tasks.- Parameters:
executor- the executor service to use
-
accept
FilenameFilterimplementation that selects files matching the current priority extension.- Specified by:
acceptin interfaceFilenameFilter- Parameters:
dir- the directoryname- the file name- Returns:
- true if the file should be accepted
-
run
-
destroy
Description copied from interface:DestroyableReleases resources held by this object.- Specified by:
destroyin interfaceDestroyable
-
createDirs
Creates all required poll directories (request, response, tmp, bad, run, archive). -
addPriority
Adds a file extension to the priority list.- Parameters:
fileExtension- the extension to add (e.g."xml")
-
scan
-
pause
Pauses the poll loop. -
unpause
Resumes a paused poll loop. -
isPaused
Returns whether the poll loop is currently paused.- Returns:
- true if paused
-