public class FileEventSource extends AbstractEventSource<FileEvent> implements PollingFileSource
| Modifier and Type | Class and Description |
|---|---|
protected static class |
FileEventSource.FileEventFilter
A file filter applying the configured restrictions for the file event
source to the searched directory.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.net.URI[] |
eventManagerURIs
The event manager URIs to provide to the created events.
|
protected java.lang.String |
filterName
Regex for filtering on the file name or null if not set.
|
protected boolean |
isLockFile
Whether the event occurs on the lock file or not.
|
protected boolean |
lockFileEvent
Whether the lock file should also be part of the event.
|
protected java.lang.String |
lockSuffix
The suffix that is used by the handler to lock files.
|
protected java.util.regex.Pattern |
namePattern
Pattern for filtering on the file name or null if not set.
|
protected java.lang.Long |
pollTime
The time in milliseconds this event source polls its data source.
|
protected java.net.URL |
searchPath
The path to the directory which causes an event when a new file is
inserted.
|
protected boolean |
skipDirectories
Whether directories should be skipped.
|
protected boolean |
skipFiles
Whether files should be skipped.
|
protected boolean |
skipLocked
Whether locked files should be skipped.
|
protected java.lang.Long |
startPoint
The start point (in milliseconds) this event should start polling.
|
eventType, handlerList, id, lock, logger, sourceType, thread, threadLockCONF_FILENAME_FILTER, CONF_IS_LOCK_FILE, CONF_LOCK_FILE_EVENT, CONF_LOCK_SUFFIX, CONF_SEARCH_DIRECTORY, CONF_SKIP_DIRECTORIES, CONF_SKIP_FILES, CONF_SKIP_LOCKEDCONF_POLL_TIME, CONF_START_TIME| Constructor and Description |
|---|
FileEventSource(Configuration conf,
EventManager eventManager,
Registry registry)
Default constructor for a plugin of an
EventManager called by
a service registry. |
| Modifier and Type | Method and Description |
|---|---|
void |
checkForAndHandleEvent()
Checks for an event and handles it (usually by using
AbstractEventSource.forwardEvent(Event, boolean, boolean)). |
protected FileEvent |
createFileEvent(java.io.File file)
Deprecated.
Use
createFileEvent(Path) instead. |
protected FileEvent |
createFileEvent(java.nio.file.Path path)
Creates a
FileEvent for the designated path. |
protected FileEvent |
createLockFileEvent(java.io.File file,
java.io.File lockFile)
Deprecated.
Use
createLockFileEvent(Path, Path) instead. |
protected LockFileEvent |
createLockFileEvent(java.nio.file.Path path,
java.nio.file.Path lockPath)
Creates a
FileEvent for the designated file and its lock file. |
long |
getPollTime()
Gets the time in milliseconds this event source polls, more precisely, the
time span between two polls.
|
long |
getStartTime()
Gets the absolute time in milliseconds since midnight, January 1, 1970 UTC
when this polling source should start polling.
|
void |
init()
Initialises this polling source.
|
protected boolean |
nextHandler(FileEvent event,
boolean consumed,
boolean concurrent)
This method is called right before an event is offered to the next handler.
|
protected void |
setConfiguration(Configuration conf,
boolean completed)
Sets the internal fields according to the values of the designated
configuration.
|
void |
setConfiguration(Configuration conf,
java.lang.String id)
Sets the (additional) configuration of this event source and its ID.
|
void |
terminate()
Terminates this polling source.
|
protected void |
verifyConfigurationValues()
This method verifies the configuration values that have been set yet.
|
addAll, addedHandlerLocked, addedHandlerLocked, addHandler, createPattern, forwardEvent, getEventHandler, getHierarchicalSourceName, getID, getType, maskedInterrupt, maskInterrupt, removeHandler, removingHandlerLocked, replaceValueParams, run, unmaskInterruptclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandlerprotected java.lang.Long pollTime
protected java.lang.Long startPoint
protected java.net.URL searchPath
protected java.lang.String filterName
protected java.util.regex.Pattern namePattern
protected boolean skipDirectories
protected boolean skipFiles
protected boolean skipLocked
protected java.lang.String lockSuffix
protected boolean lockFileEvent
protected boolean isLockFile
protected final java.net.URI[] eventManagerURIs
public FileEventSource(Configuration conf, EventManager eventManager, Registry registry) throws ConfigurationException
EventManager called by
a service registry.
Note that this constructor calls
setConfiguration(Configuration, boolean); subclasses may not be
fully initialised at this point.
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.ConfigurationException - If the configuration is not valid for a
PollingFileSource, a ConfigurationException
will be thrown.protected void setConfiguration(Configuration conf, boolean completed) throws ConfigurationException
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.ConfigurationException - If there are problems with the
configuration, for instance the configuration does not provide
required values, a ConfigurationException may be
thrown.protected void verifyConfigurationValues()
throws ConfigurationException
ConfigurationException will be thrown.ConfigurationException - If there are problems with the
configuration, for instance the configuration does not provide
required values, a ConfigurationException may be
thrown.public void setConfiguration(Configuration conf, java.lang.String id) throws ConfigurationException
EventSourceRunnable.run().setConfiguration in interface EventSource<FileEvent>setConfiguration in class AbstractEventSource<FileEvent>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 be null depends on the implementation of
the event source.id - The ID of this event source. This must not be null
nor the empty string.ConfigurationException - If there are problems with the designated
configuration (configuration is null although this
is not allowed, a required configuration value is missing, ...),
a ConfigurationException will be thrown.public long getPollTime()
PollingSourcePollingSource.init() and PollingSource.terminate() will be called.getPollTime in interface PollingSource<FileEvent>public long getStartTime()
PollingSourcePollingSource.getPollTime().getStartTime in interface PollingSource<FileEvent>public void init()
PollingSourceinit in interface PollingSource<FileEvent>public void checkForAndHandleEvent()
AbstractEventSourceAbstractEventSource.forwardEvent(Event, boolean, boolean)).checkForAndHandleEvent in class AbstractEventSource<FileEvent>public void terminate()
PollingSourceterminate in interface PollingSource<FileEvent>protected FileEvent createFileEvent(java.nio.file.Path path) throws java.io.IOException
FileEvent for the designated path.path - The path for which to create a FileEvent.FileEvent created for the designated path.java.io.IOException - If retrieving the basic file attributes of the designated path fails, an
IOException will be thrown.@Deprecated protected FileEvent createFileEvent(java.io.File file) throws java.io.IOException
createFileEvent(Path) instead.FileEvent for the designated file.file - The file for which to create a FileEvent.FileEvent created for the designated file.java.io.IOException - Retrieving the URL of the file may throw an
IOException.protected LockFileEvent createLockFileEvent(java.nio.file.Path path, java.nio.file.Path lockPath) throws java.io.IOException
FileEvent for the designated file and its lock file.path - The path for which to create a LockFileEvent.lockPath - The path for the corresponding lock file.FileEvent created for the designated path and lock file.java.io.IOException - If retrieving the basic file attributes of the designated path fails, an
IOException will be thrown.@Deprecated protected FileEvent createLockFileEvent(java.io.File file, java.io.File lockFile) throws java.io.IOException
createLockFileEvent(Path, Path) instead.FileEvent for the designated file and its lock file.file - The file for which to create a FileEvent.lockFile - The corresponding lock file.FileEvent created for the designated file.java.io.IOException - Retrieving the URL of the file may throw an
IOException.protected boolean nextHandler(FileEvent event, boolean consumed, boolean concurrent)
AbstractEventSourcenextHandler in class AbstractEventSource<FileEvent>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.false here.