Class WatchServiceListener
java.lang.Object
ninja.leaping.configurate.reference.WatchServiceListener
- All Implemented Interfaces:
- AutoCloseable
public class WatchServiceListener extends Object implements AutoCloseable
A wrapper around NIO's 
WatchService that uses the provided event loop to poll for changes, and calls
 listeners once an event occurs.
 Some deduplication is performed because Windows can be fairly spammy with its events, so one callback may receive multiple events at one time.
 Callback functions are Subscribers that take the WatchEvent as their parameter.
 
Listening to a directory provides updates on the directory's immediate children, but does not
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classWatchServiceListener.BuilderSet the parameters needed to create aWatchServiceListener.
- 
Method SummaryModifier and Type Method Description static WatchServiceListener.Builderbuilder()Create a new builder for a WatchServiceListener to create a customized listenervoidclose()static WatchServiceListenercreate()Create a newWatchServiceListenerusing a new cached thread pool executor and the default filesystem.<N extends ConfigurationNode>
 ConfigurationReference<N>listenToConfiguration(Function<Path,ConfigurationLoader<? extends N>> loaderFunc, Path path)DisposablelistenToDirectory(Path directory, Subscriber<WatchEvent<?>> callback)Listen to a directory.DisposablelistenToFile(Path file, Subscriber<WatchEvent<?>> callback)Listen for changes to a specific file or directory.
- 
Method Details- 
builderCreate a new builder for a WatchServiceListener to create a customized listener- Returns:
- A builder
 
- 
createCreate a newWatchServiceListenerusing a new cached thread pool executor and the default filesystem.- Returns:
- A new instance with default values
- Throws:
- IOException- If a watch service cannot be created
- See Also:
- for customization
 
- 
listenToFilepublic Disposable listenToFile(Path file, Subscriber<WatchEvent<?>> callback) throws IOException, IllegalArgumentExceptionListen for changes to a specific file or directory.- Parameters:
- file- The path of the file or directory to listen for changes on.
- callback- A callback function that will be called when changes are made. If return value is false, we will stop monitoring for changes.
- Returns:
- A Disposablethat can be used to cancel this subscription
- Throws:
- IOException- if a filesystem error occurs.
- IllegalArgumentException- if the provided path is a directory.
 
- 
listenToDirectorypublic Disposable listenToDirectory(Path directory, Subscriber<WatchEvent<?>> callback) throws IOException, IllegalArgumentExceptionListen to a directory. Callbacks will receive events both for the directory and for its contents.- Parameters:
- directory- The directory to listen to
- callback- A callback function that will be called when changes are made. If return value is false, we will stop monitoring for changes.
- Returns:
- A Disposablethat can be used to cancel this subscription
- Throws:
- IOException- When an error occurs registering with the underlying watch service.
- IllegalArgumentException- If the provided path is not a directory
 
- 
listenToConfigurationpublic <N extends ConfigurationNode> ConfigurationReference<N> listenToConfiguration(Function<Path,ConfigurationLoader<? extends N>> loaderFunc, Path path) throws IOException- Throws:
- IOException
 
- 
close- Specified by:
- closein interface- AutoCloseable
- Throws:
- IOException
 
 
-