Package org.oddjob.io
Class FileWatchService
java.lang.Object
org.oddjob.io.FileWatchService
- Author:
- rob
- See Also:
Description
Provide a service for subscribers to watch a file system for Files existing, being created or being modified. If the file is created during subscription the consumer may receive a notification for the same file twice. Once the subscription has succeeded a consumer should receive every creation and modification happening to the file. If this service is stopped no notification is sent to consumers. Consumers must use the state of this service to know that it has stopped. Consumers will receive creation and modification events on a different thread to the initial event if the file exists.Implementation Note: This facility is still a work in progress. Requiring this service in a configuration is messy. In future releases this service should be hidden from users.
Example
Trigger when two files arrive.
<oddjob>
<job>
<sequential>
<jobs>
<mkdir dir="${some.dir}/etc" name="Create Test Dir"/>
<file-watch id="file-watch" kinds="ENTRY_CREATE"/>
<events:when id="both-files" name="When Both Files" xmlns:events="oddjob:events">
<jobs>
<events:list eventOperator="ALL">
<of>
<events:watch name="Watch File 1">
<eventSource>
<events:file>
<fileWatch>
<value value="${file-watch}"/>
</fileWatch>
<file>
<value value="${some.dir}/file1.txt"/>
</file>
</events:file>
</eventSource>
</events:watch>
<events:watch name="Watch File 2">
<eventSource>
<events:file>
<fileWatch>
<value value="${file-watch}"/>
</fileWatch>
<file>
<value value="${some.dir}/file2.txt"/>
</file>
</events:file>
</eventSource>
</events:watch>
</of>
</events:list>
<echo id="task">
${both-files.trigger.ofs}
</echo>
</jobs>
</events:when>
<folder>
<jobs>
<copy id="createFile1" name="Create File 1" to="${some.dir}/file1.txt">
<input>
<buffer>
Test1
</buffer>
</input>
</copy>
<copy id="createFile2" name="Create File 2" to="${some.dir}/file2.txt">
<input>
<buffer>
Test2
</buffer>
</input>
</copy>
<delete name="Delete All Test Files">
<files>
<files files="${some.dir}/*"/>
</files>
</delete>
</jobs>
</folder>
</jobs>
</sequential>
</job>
</oddjob>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetKinds()getName()intgetPaths()getTo()voidvoidvoidvoidvoidSet the out bound destination.voidstart()Start the service.voidstop()Stop executing.subscribe(Path path, Consumer<? super InstantEvent<Path>> consumer) Subscribe to notifications for the existence or modifications in the file.toString()
-
Constructor Details
-
FileWatchService
public FileWatchService()
-
-
Method Details
-
start
public void start()Description copied from interface:ServiceStart the service. -
stop
public void stop()Description copied from interface:StoppableStop executing. This method should not return until the Stoppable has actually stopped. -
subscribe
Description copied from interface:FileWatchSubscribe to notifications for the existence or modifications in the file. If the file exists already the consumer will be notified before this method returns. If the file is created during the call to this method then the consumer may receive a notification for the same file twice. A consumer could use the modified date to remove duplicated but then may miss file modifications that happen close together. The documentation for implementations should adequately explain such behaviours. -
setFilter
-
getFilter
-
getNumberOfConsumers
public int getNumberOfConsumers() -
getName
-
setName
-
getKinds
-
setKinds
-
getPaths
-
setPaths
-
getTo
-
setTo
Description copied from interface:OutboundSet the out bound destination. -
toString
-