Directory Watcher Trigger
The Directory Watcher trigger allows applications to respond to file changes within a specified directory on the server's local file system. This capability is essential for scenarios requiring the initiation of further processing upon the addition, modification, or deletion of files in a directory.
File System Compatibility
The performance of the Directory Watcher trigger is contingent on the underlying file system's ability to notify changes. It functions effectively with local file systems on Windows, macOS, and Linux. However, remote or shared files systems are NOT supported by the Directory Watcher trigger. File system must be a locally attached disk to the server.
Usage in Workflows
To learn how to setup and use the Directory Watcher trigger in workflows, see Martini Workflows Trigger Nodes
Usage in Services
To learn how to setup and use the Directory Watcher trigger in services, see Invoking Services via a Trigger
Configuration
General Properties
General trigger configuration applies, including properties such as trigger name, description, among others, as elaborated in the general trigger documentation.
Directory Watcher-Specific Configuration
| Property | Default | Description |
|---|---|---|
| Directory | (required) | The directory to monitor for changes. |
| Recursive | false |
Indicates whether changes in subdirectories should also trigger notifications. |
| Events | (required) | Specifies the types of file system events to monitor: 'Addition', 'Modification', 'Deletion'. |
Parameters
The Directory Watcher trigger provides specific parameters for managing file system event notifications.
| Name | Type | Description |
|---|---|---|
fileAction |
io.toro.martini.event.FileEvent.Action |
Identifies the action that activated the trigger: ADDED, MODIFIED, or DELETED. |
action |
java.lang.String |
The string representation of fileAction. |
file |
java.nio.file.Path |
The file that caused the trigger to activate. |
filename |
java.lang.String |
The absolute path of the file. |
inputStream |
java.io.InputStream |
An InputStream to the file, automatically closed after service execution. |
reader |
java.io.Reader |
A Reader for the file, automatically closed after service execution. |
multipartFile |
org.springframework.web.multipart.MultipartFile |
A multipart file reference. |
bytes |
byte[] |
File data in bytes, made available when matched with a service parameter name. |
content |
java.lang.String |
File content as a string, made available when matched with a service parameter name. |
Best Practices
- Secure the monitored directory to prevent unauthorized access or alterations.
- Extensively test the Directory Watcher trigger in the deployment environment to ensure its functionality meets expectations.
Troubleshooting
- Issue: The trigger does not activate on file changes.
- Check: Verify the directory path is correct and accessible with the appropriate permissions.
- Check: In situations where the Directory Watcher trigger's performance is suboptimal, consider implementing a scheduler for manual file system inspections.
Handling Large Files Warning
For processing large files, it is recommended to use inputStream or direct file access rather than relying on content or bytes to avoid potential memory overload.
Additional Notes
Ensure compatibility with your file system when using the Directory Watcher. For more complex scenarios, consider leveraging extension modules available in Martini.
For further examples and scripts, the Martini examples package provides a wealth of resources to explore.