@Alias(value="directory-listener") public class DirectoryListener extends org.mule.runtime.extension.api.runtime.source.Source<InputStream,ListenerFileAttributes> implements FlowConstructAware
Whenever a file (or the directory) is created, updated or deleted, this Source will fire a Message which
payload reference the affected file and the attributes will be a ListenerFileAttributes instance.
There're however some special cases to be considered:
nullDeletedFileAttributes which throws IllegalStateException whenever a non available attribute is
requestednullWhen to use it
This source is useful in cases in which a flow should respond to changes done on the filesystem, examples being trigger files,
transaction files being added on a drop folder, settings files updated, etc. All of the above cases could be done using a
<file:list> operation inside a poll scope (maybe also combined with a <watermark>.
However, although polling is a powerful and reliable solution, it's not an efficient one. Because this listener relies on operating system notifications, it's much more efficient in terms of resources.
Reliability
The trade-off between a poll reliability and this listener's performance is reliability. Because operating system events don't generally include the concept of transaction or replay, there's no way to guarantee that no event is going to be lost in case of failure or server crash. Although you can always use mule to implement a reliable acquisition pattern, there's no fallback is such acquisition fails. What this means is that this listener is no silver bullet and it should not been seen as the recommended approach over a poll+list+watermark approach. Users should analyse each use case and environment to determine which the best option is.
Operating system limitations
This component's behaviour might be slightly different depending on the OS on which it is deployed. The main differences are usually (but not exclusively) related to:
| Constructor and Description |
|---|
DirectoryListener() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isStarted() |
void |
onStart(org.mule.runtime.extension.api.runtime.source.SourceCallback<InputStream,ListenerFileAttributes> sourceCallback) |
void |
onStop() |
void |
setFlowConstruct(FlowConstruct flowConstruct) |
public void onStart(org.mule.runtime.extension.api.runtime.source.SourceCallback<InputStream,ListenerFileAttributes> sourceCallback) throws org.mule.runtime.api.exception.MuleException
onStart in class org.mule.runtime.extension.api.runtime.source.Source<InputStream,ListenerFileAttributes>org.mule.runtime.api.exception.MuleExceptionpublic void onStop()
onStop in class org.mule.runtime.extension.api.runtime.source.Source<InputStream,ListenerFileAttributes>public void setFlowConstruct(FlowConstruct flowConstruct)
setFlowConstruct in interface FlowConstructAwarepublic boolean isStarted()
this source is actually startedCopyright © 2003–2017 MuleSoft, Inc.. All rights reserved.