Class FsConsumerImpl
- java.lang.Object
-
- com.adaptris.core.AdaptrisMessageWorkerImp
-
- com.adaptris.core.AdaptrisMessageConsumerImp
-
- com.adaptris.core.AdaptrisPollingConsumer
-
- com.adaptris.core.fs.FsConsumerImpl
-
- All Implemented Interfaces:
AdaptrisComponent
,AdaptrisMessageConsumer
,AdaptrisMessageWorker
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,StateManagedComponent
- Direct Known Subclasses:
FsConsumer
,NonDeletingFsConsumer
public abstract class FsConsumerImpl extends AdaptrisPollingConsumer
Abstract implementation of
AdaptrisMessageConsumer
based on thecom.adaptris.fs
package.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.adaptris.core.AdaptrisPollingConsumer
AdaptrisPollingConsumer.LockOperator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.FileFilter
fileFilter
protected FsWorker
fsWorker
-
Fields inherited from class com.adaptris.core.AdaptrisMessageWorkerImp
log
-
-
Constructor Summary
Constructors Constructor Description FsConsumerImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addStandardMetadata(AdaptrisMessage msg, java.io.File originalFile, java.io.File wipFile)
protected java.lang.String
baseDirUrl()
protected boolean
checkModified(java.io.File f)
Does this file match the quiet period directive.java.lang.String
consumeLocationKey()
Provides the metadata key '"fsConsumeDir"' that contains the directory (if not null) where the file was read from.protected AdaptrisMessage
createAdaptrisMessage(java.io.File fileToProcess)
protected java.lang.String
filterExpression()
java.lang.String
getBaseDirectoryUrl()
The base directory specified as a URL.java.lang.Boolean
getCreateDirs()
Create missing directories when trying to polljava.lang.String
getFileFilterImp()
Set the filename filter implementation that will be used for filtering files.@NonNull FileSorter
getFileSorter()
Set the filesorter implementation to use.java.lang.String
getFilterExpression()
The filter expression to use when listing files.java.lang.Boolean
getLogAllExceptions()
Log all the stack traces or not.TimeInterval
getQuietInterval()
Specify how old a file must be before a file is deemed safe to be processed.void
init()
Initialises the component.protected boolean
isFileAccessible(java.io.File f)
Could we read and process this file.boolean
logAllExceptions()
protected void
prepareConsumer()
protected abstract int
processFile(java.io.File f)
Attempt to process this file which might be a directory.protected int
processMessages()
If reacquire-lock-between-messages is set to true, this.reaquireLock is called after each message has been processed.void
setBaseDirectoryUrl(java.lang.String baseDirectoryUrl)
The base directory specified as a URL.void
setCreateDirs(java.lang.Boolean createDirs)
Create missing directories when trying to pollvoid
setFileFilterImp(java.lang.String fileFilterImp)
Set the filename filter implementation that will be used for filtering files.void
setFileSorter(@NonNull FileSorter fileSorter)
Set the filesorter implementation to use.void
setFilterExpression(java.lang.String filterExpression)
The filter expression to use when listing files.void
setLogAllExceptions(java.lang.Boolean logAllExceptions)
Log all the stack traces or not.void
setQuietInterval(TimeInterval quietInterval)
Specify how old a file must be before a file is deemed safe to be processed.boolean
shouldCreateDirs()
protected java.io.File
verifyDirectory()
<T extends FsConsumerImpl>
TwithBaseDirectoryUrl(java.lang.String s)
<T extends FsConsumerImpl>
TwithFilterExpression(java.lang.String s)
-
Methods inherited from class com.adaptris.core.AdaptrisPollingConsumer
close, continueProcessingMessages, getMaxMessagesPerPoll, getPoller, getReacquireLockBetweenMessages, prepare, releaseLock, setMaxMessagesPerPoll, setPoller, setReacquireLockBetweenMessages, start, stop
-
Methods inherited from class com.adaptris.core.AdaptrisMessageConsumerImp
changeState, newThreadName, registerAdaptrisMessageListener, renameThread, requestClose, requestInit, requestStart, requestStop, retrieveAdaptrisMessageListener, retrieveComponentState
-
Methods inherited from class com.adaptris.core.AdaptrisMessageWorkerImp
createName, createQualifier, decode, encode, getEncoder, getIsTrackingEndpoint, getMessageFactory, getUniqueId, handleConnectionException, isTrackingEndpoint, registerConnection, registerEncoderMessageFactory, retrieveConnection, setEncoder, setIsTrackingEndpoint, setMessageFactory, setUniqueId, withMessageFactory, withUniqueID
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.adaptris.core.AdaptrisComponent
getUniqueId
-
Methods inherited from interface com.adaptris.core.AdaptrisMessageWorker
decode, encode, getEncoder, getMessageFactory, handleConnectionException, registerConnection, retrieveConnection, setEncoder, setMessageFactory
-
Methods inherited from interface com.adaptris.core.MessageEventGenerator
createName, createQualifier, isTrackingEndpoint
-
-
-
-
Field Detail
-
fileFilter
protected transient java.io.FileFilter fileFilter
-
fsWorker
protected transient FsWorker fsWorker
-
-
Method Detail
-
prepareConsumer
protected void prepareConsumer() throws CoreException
- Specified by:
prepareConsumer
in classAdaptrisPollingConsumer
- Throws:
CoreException
-
baseDirUrl
protected java.lang.String baseDirUrl()
-
filterExpression
protected java.lang.String filterExpression()
-
processMessages
protected int processMessages()
If reacquire-lock-between-messages is set to true, this.reaquireLock is called after each message has been processed. This gives other Threads (e.g. something stopping the adapter) the opportunity to obtain the lock without waiting for all messages to be processed.
- Specified by:
processMessages
in classAdaptrisPollingConsumer
- See Also:
AdaptrisPollingConsumer.processMessages()
-
checkModified
protected boolean checkModified(java.io.File f) throws java.io.IOException
Does this file match the quiet period directive.- Parameters:
f
- the file.- Returns:
- whether the file has been modified or not.
- Throws:
java.io.IOException
-
isFileAccessible
protected boolean isFileAccessible(java.io.File f)
Could we read and process this file.- Parameters:
f
- the file.- Returns:
- true, if the file is a file, can be read, and can be written to (for renaming purposes).
-
processFile
protected abstract int processFile(java.io.File f) throws CoreException
Attempt to process this file which might be a directory.- Parameters:
f
- the File- Returns:
- the number of files processed.
- Throws:
CoreException
- wrapping any other Exception.
-
init
public void init() throws CoreException
Description copied from interface:ComponentLifecycle
Initialises the component.Component initialisation includes config verification, creation of connections etc.
- Specified by:
init
in interfaceComponentLifecycle
- Overrides:
init
in classAdaptrisPollingConsumer
- Throws:
CoreException
- wrapping any underlyingException
s- See Also:
ComponentLifecycle.init()
-
verifyDirectory
protected java.io.File verifyDirectory() throws java.lang.Exception
- Throws:
java.lang.Exception
-
shouldCreateDirs
public boolean shouldCreateDirs()
-
createAdaptrisMessage
protected AdaptrisMessage createAdaptrisMessage(java.io.File fileToProcess) throws CoreException
- Throws:
CoreException
-
addStandardMetadata
protected void addStandardMetadata(AdaptrisMessage msg, java.io.File originalFile, java.io.File wipFile) throws CoreException
- Throws:
CoreException
-
logAllExceptions
public boolean logAllExceptions()
-
consumeLocationKey
public java.lang.String consumeLocationKey()
Provides the metadata key '"fsConsumeDir"' that contains the directory (if not null) where the file was read from.- Returns:
- the metadata key;
- Since:
- 3.9.0
-
withBaseDirectoryUrl
public <T extends FsConsumerImpl> T withBaseDirectoryUrl(java.lang.String s)
-
withFilterExpression
public <T extends FsConsumerImpl> T withFilterExpression(java.lang.String s)
-
getFileFilterImp
public java.lang.String getFileFilterImp()
Set the filename filter implementation that will be used for filtering files.The file filter implementation that is used in conjunction with the
getFilterExpression()
, if not specified, then the default isorg.apache.commons.io.filefilter.RegexFileFilter
which uses the java.util regular expressions to perform filteringThe expression that is used to filter messages is derived from
getFilterExpression()
.- See Also:
getFilterExpression()
-
setFileFilterImp
public void setFileFilterImp(java.lang.String fileFilterImp)
Set the filename filter implementation that will be used for filtering files.The file filter implementation that is used in conjunction with the
getFilterExpression()
, if not specified, then the default isorg.apache.commons.io.filefilter.RegexFileFilter
which uses the java.util regular expressions to perform filteringThe expression that is used to filter messages is derived from
getFilterExpression()
.- See Also:
getFilterExpression()
-
getCreateDirs
public java.lang.Boolean getCreateDirs()
Create missing directories when trying to pollthis defaults to false because we consider it a dangerous thing to do especially if you have bad configuration. The last thing we want is for you to accuse interlok of creating random directories.
-
setCreateDirs
public void setCreateDirs(java.lang.Boolean createDirs)
Create missing directories when trying to pollthis defaults to false because we consider it a dangerous thing to do especially if you have bad configuration. The last thing we want is for you to accuse interlok of creating random directories.
-
getLogAllExceptions
public java.lang.Boolean getLogAllExceptions()
Log all the stack traces or not.
-
setLogAllExceptions
public void setLogAllExceptions(java.lang.Boolean logAllExceptions)
Log all the stack traces or not.
-
getQuietInterval
public TimeInterval getQuietInterval()
Specify how old a file must be before a file is deemed safe to be processed.The purpose of this is to delay processing of files that may be currently being written to by another process. On certain platforms (e.g. most Unix) it is still possible to obtain an exclusive lock on the file even though it is being written to by another process.
An alternative to specifying a last-modified is to specify
CompositeFileFilter
as the filter implementation and then a combination ofOlderThan
along with your actual filter-implementation.Note: your mileage may vary when using this setting. The only surefire way is for the triggering application to write the file to a staging area and use an atomic operation (such as move) to move the file into the target directory.
- See Also:
File.lastModified()
,CompositeFileFilter
,setFileFilterImp(String)
-
setQuietInterval
public void setQuietInterval(TimeInterval quietInterval)
Specify how old a file must be before a file is deemed safe to be processed.The purpose of this is to delay processing of files that may be currently being written to by another process. On certain platforms (e.g. most Unix) it is still possible to obtain an exclusive lock on the file even though it is being written to by another process.
An alternative to specifying a last-modified is to specify
CompositeFileFilter
as the filter implementation and then a combination ofOlderThan
along with your actual filter-implementation.Note: your mileage may vary when using this setting. The only surefire way is for the triggering application to write the file to a staging area and use an atomic operation (such as move) to move the file into the target directory.
- See Also:
File.lastModified()
,CompositeFileFilter
,setFileFilterImp(String)
-
getFileSorter
@NonNull public @NonNull FileSorter getFileSorter()
Set the filesorter implementation to use.The file sorter is responsible for sorting the list of files that is collected for processing. The sorted list is then processed.
-
setFileSorter
public void setFileSorter(@NonNull @NonNull FileSorter fileSorter)
Set the filesorter implementation to use.The file sorter is responsible for sorting the list of files that is collected for processing. The sorted list is then processed.
-
getBaseDirectoryUrl
public java.lang.String getBaseDirectoryUrl()
The base directory specified as a URL.
-
setBaseDirectoryUrl
public void setBaseDirectoryUrl(java.lang.String baseDirectoryUrl)
The base directory specified as a URL.
-
getFilterExpression
public java.lang.String getFilterExpression()
The filter expression to use when listing files.If not specified then will default in a file filter that matches all files.
-
setFilterExpression
public void setFilterExpression(java.lang.String filterExpression)
The filter expression to use when listing files.If not specified then will default in a file filter that matches all files.
-
-