Class FileEventSource
- java.lang.Object
-
- de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource<FileEvent>
-
- de.aristaflow.adept2.core.eventmanager.fileevents.FileEventSource
-
- All Implemented Interfaces:
EventSource<FileEvent>,PollingFileSource,PollingSource<FileEvent>,Runnable
- Direct Known Subclasses:
FileEventActivitySource
public class FileEventSource extends AbstractEventSource<FileEvent> implements PollingFileSource
A source for events based on files in a specific folder (configured). This folder is checked regularly and any file (or directory) found is notified as file event to the corresponding registered event handlers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classFileEventSource.FileEventFilterA file filter applying the configured restrictions for the file event source to the searched directory.
-
Field Summary
Fields Modifier and Type Field Description protected URI[]eventManagerURIsThe event manager URIs to provide to the created events.protected StringfilterNameRegex for filtering on the file name or null if not set.protected booleanisLockFileWhether the event occurs on the lock file or not.protected booleanlockFileEventWhether the lock file should also be part of the event.protected StringlockSuffixThe suffix that is used by the handler to lock files.protected PatternnamePatternPattern for filtering on the file name or null if not set.protected LongpollTimeThe time in milliseconds this event source polls its data source.protected URLsearchPathThe path to the directory which causes an event when a new file is inserted.protected booleanskipDirectoriesWhether directories should be skipped.protected booleanskipFilesWhether files should be skipped.protected booleanskipLockedWhether locked files should be skipped.protected LongstartPointThe start point (in milliseconds) this event should start polling.-
Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource
eventType, handlerList, id, lock, logger, sourceType, thread, threadLock
-
Fields inherited from interface de.aristaflow.adept2.model.events.sources.PollingFileSource
CONF_FILENAME_FILTER, CONF_IS_LOCK_FILE, CONF_LOCK_FILE_EVENT, CONF_LOCK_SUFFIX, CONF_SEARCH_DIRECTORY, CONF_SKIP_DIRECTORIES, CONF_SKIP_FILES, CONF_SKIP_LOCKED
-
Fields inherited from interface de.aristaflow.adept2.model.events.sources.PollingSource
CONF_POLL_TIME, CONF_START_TIME
-
-
Constructor Summary
Constructors Constructor Description FileEventSource(org.apache.commons.configuration2.Configuration conf, EventManager eventManager, Registry registry)Default constructor for a plugin of anEventManagercalled by a service registry.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckForAndHandleEvent()Checks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).protected FileEventcreateFileEvent(Path path)Creates aFileEventfor the designated path.protected LockFileEventcreateLockFileEvent(Path path, Path lockPath)Creates aFileEventfor the designated file and its lock file.longgetPollTime()Gets the time in milliseconds this event source polls, more precisely, the time span between two polls.longgetStartTime()Gets the absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling.protected booleannextHandler(FileEvent event, boolean consumed, boolean concurrent)This method is called right before an event is offered to the next handler.protected voidsetConfiguration(org.apache.commons.configuration2.Configuration conf, boolean completed)Sets the internal fields according to the values of the designated configuration.voidsetConfiguration(org.apache.commons.configuration2.Configuration conf, String id)Sets the (additional) configuration of this event source and its ID.voidterminate()Terminates this polling source.protected voidverifyConfigurationValues()This method verifies the configuration values that have been set yet.-
Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource
addAll, addedHandlerLocked, addedHandlerLocked, addHandler, createPattern, forwardEvent, getEventHandler, getHierarchicalSourceName, getID, getType, maskedInterrupt, maskInterrupt, removeHandler, removingHandlerLocked, replaceValueParams, run, unmaskInterrupt
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.aristaflow.adept2.model.events.sources.EventSource
addAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandler
-
Methods inherited from interface de.aristaflow.adept2.model.events.sources.PollingSource
init
-
-
-
-
Field Detail
-
pollTime
protected Long pollTime
The time in milliseconds this event source polls its data source.
-
startPoint
protected Long startPoint
The start point (in milliseconds) this event should start polling.
-
searchPath
protected URL searchPath
The path to the directory which causes an event when a new file is inserted.
-
filterName
protected String filterName
Regex for filtering on the file name or null if not set.
-
namePattern
protected Pattern namePattern
Pattern for filtering on the file name or null if not set.
-
skipDirectories
protected boolean skipDirectories
Whether directories should be skipped.
-
skipFiles
protected boolean skipFiles
Whether files should be skipped.
-
skipLocked
protected boolean skipLocked
Whether locked files should be skipped.
-
lockSuffix
protected String lockSuffix
The suffix that is used by the handler to lock files. Keep in sync with the corresponding event handler marking files by creating lock files so that the locked files will be skipped.
-
lockFileEvent
protected boolean lockFileEvent
Whether the lock file should also be part of the event.
-
isLockFile
protected boolean isLockFile
Whether the event occurs on the lock file or not.
-
eventManagerURIs
protected final URI[] eventManagerURIs
The event manager URIs to provide to the created events.
-
-
Constructor Detail
-
FileEventSource
public FileEventSource(org.apache.commons.configuration2.Configuration conf, EventManager eventManager, Registry registry) throws ConfigurationExceptionDefault constructor for a plugin of anEventManagercalled by a service registry.Note that this constructor calls
setConfiguration(Configuration, boolean); subclasses may not be fully initialised at this point.- Parameters:
conf- The configuration as provided from the registry.eventManager- The event manager this event source is a plugin of.registry- The registry of this plugin.- Throws:
ConfigurationException- If the configuration is not valid for aPollingFileSource, aConfigurationExceptionwill be thrown.
-
-
Method Detail
-
setConfiguration
protected void setConfiguration(org.apache.commons.configuration2.Configuration conf, boolean completed) throws ConfigurationExceptionSets the internal fields according to the values of the designated configuration. Note that this method is called from the constructor and therefore this object may not be fully initialised!- Parameters:
conf- The configuration from which to get the configuration values.completed- Whether the configuration is complete after this setting and therefore the values should be verified.- Throws:
ConfigurationException- If there are problems with the configuration, for instance the configuration does not provide required values, aConfigurationExceptionmay be thrown.
-
verifyConfigurationValues
protected void verifyConfigurationValues() throws ConfigurationExceptionThis method verifies the configuration values that have been set yet. If a configuration value is missing or inappropriate, aConfigurationExceptionwill be thrown.- Throws:
ConfigurationException- If there are problems with the configuration, for instance the configuration does not provide required values, aConfigurationExceptionmay be thrown.
-
setConfiguration
public void setConfiguration(org.apache.commons.configuration2.Configuration conf, String id) throws ConfigurationExceptionDescription copied from interface:EventSourceSets the (additional) configuration of this event source and its ID. The configuration is additional with respect to the configuration provided by the plugin load mechanism, if the event source is loaded as plugin.
It is ensured that this method will be called beforeRunnable.run().- Specified by:
setConfigurationin interfaceEventSource<FileEvent>- Overrides:
setConfigurationin classAbstractEventSource<FileEvent>- Parameters:
conf- The configuration of this event source. This adheres (and overwrites) the configuration provided by the plugin loading, if this event source has been loaded as plugin. Whether this is allowed to benulldepends on the implementation of the event source.id- The ID of this event source. This must not benullnor the empty string.- Throws:
ConfigurationException- If there are problems with the designated configuration (configuration isnullalthough this is not allowed, a required configuration value is missing, ...), aConfigurationExceptionwill be thrown.
-
getPollTime
public long getPollTime()
Description copied from interface:PollingSourceGets the time in milliseconds this event source polls, more precisely, the time span between two polls. If this is 0 or negative, no polling will apply. However,PollingSource.init()andPollingSource.terminate()will be called.- Specified by:
getPollTimein interfacePollingSource<FileEvent>- Returns:
- The time in milliseconds this event source polls (> 0).
-
getStartTime
public long getStartTime()
Description copied from interface:PollingSourceGets the absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling. This is used for calculating the first poll time by adding the time span defined inPollingSource.getPollTime().- Specified by:
getStartTimein interfacePollingSource<FileEvent>- Returns:
- The absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling.
-
checkForAndHandleEvent
public void checkForAndHandleEvent()
Description copied from class:AbstractEventSourceChecks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).- Specified by:
checkForAndHandleEventin classAbstractEventSource<FileEvent>
-
terminate
public void terminate()
Description copied from interface:PollingSourceTerminates this polling source. This is called once after polling has terminated and this source is removed.
Note that this may be called any time, even when creating or handling an event. So take care to synchronise the implementation appropriately!- Specified by:
terminatein interfacePollingSource<FileEvent>
-
createFileEvent
protected FileEvent createFileEvent(Path path) throws IOException
Creates aFileEventfor the designated path.- Parameters:
path- The path for which to create aFileEvent.- Returns:
- The
FileEventcreated for the designated path. - Throws:
IOException- If retrieving the basic file attributes of the designated path fails, anIOExceptionwill be thrown.
-
createLockFileEvent
protected LockFileEvent createLockFileEvent(Path path, Path lockPath) throws IOException
Creates aFileEventfor the designated file and its lock file.- Parameters:
path- The path for which to create aLockFileEvent.lockPath- The path for the corresponding lock file.- Returns:
- The
FileEventcreated for the designated path and lock file. - Throws:
IOException- If retrieving the basic file attributes of the designated path fails, anIOExceptionwill be thrown.
-
nextHandler
protected boolean nextHandler(FileEvent event, boolean consumed, boolean concurrent)
Description copied from class:AbstractEventSourceThis method is called right before an event is offered to the next handler. In case of concurrent handling, this method will only be called once for all concurrent handling but this will be indicated by the corresponding parameter.- Specified by:
nextHandlerin classAbstractEventSource<FileEvent>- Parameters:
event- The event which is about to be handled by the next registered handler.consumed- Whether the event has been consumed yet.concurrent- Whether the next event handling is concurrent and thus the event will be offered to several event handler concurrently.- Returns:
- Whether the event handling may continue. In case of serious
problems preventing further event handling, return
falsehere.
-
-