Class WatchServiceListener
java.lang.Object
org.spongepowered.configurate.reference.WatchServiceListener
- All Implemented Interfaces:
- AutoCloseable
A wrapper around NIO's 
WatchService that uses the provided watch key
 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 listen recursively.
- Since:
- 4.0.0
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classSet the parameters needed to create aWatchServiceListener.
- 
Method SummaryModifier and TypeMethodDescriptionstatic WatchServiceListener.Builderbuilder()Returns a new builder for a WatchServiceListener to create a customized listener.voidclose()static WatchServiceListenercreate()Create a newWatchServiceListenerusing a new cached thread pool executor and the default filesystem.<N extends ScopedConfigurationNode<N>>
 ConfigurationReference<N>listenToConfiguration(Function<Path, ConfigurationLoader<? extends N>> loaderFunc, Path path) Create a newConfigurationReferencesubscribed to FS updates.listenToDirectory(Path directory, Subscriber<WatchEvent<?>> callback) Listen to a directory.listenToFile(Path file, Subscriber<WatchEvent<?>> callback) Listen for changes to a specific file or directory.
- 
Method Details- 
builderReturns a new builder for a WatchServiceListener to create a customized listener.- Returns:
- a new builder
- Since:
- 4.0.0
 
- 
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
- Since:
- 4.0.0
- See Also:
 
- 
listenToFilepublic Disposable listenToFile(Path file, Subscriber<WatchEvent<?>> callback) throws ConfigurateException, IllegalArgumentException Listen for changes to a specific file or directory.- Parameters:
- file- the path of the file or directory to listen for changes on.
- callback- a subscriber that will be notified when changes occur.
- Returns:
- a Disposablethat can be used to cancel this subscription
- Throws:
- ConfigurateException- if a filesystem error occurs.
- IllegalArgumentException- if the provided path is a directory.
- Since:
- 4.0.0
 
- 
listenToDirectorypublic Disposable listenToDirectory(Path directory, Subscriber<WatchEvent<?>> callback) throws ConfigurateException, IllegalArgumentException Listen to a directory. Callbacks will receive events both for the directory and for its contents.- Parameters:
- directory- the directory to listen to
- callback- a subscriber that will be notified when changes occur.
- Returns:
- a Disposablethat can be used to cancel this subscription
- Throws:
- ConfigurateException- when an error occurs registering with the underlying watch service.
- IllegalArgumentException- if the provided path is not a directory
- Since:
- 4.0.0
 
- 
listenToConfigurationpublic <N extends ScopedConfigurationNode<N>> ConfigurationReference<N> listenToConfiguration(Function<Path, ConfigurationLoader<? extends N>> loaderFunc, Path path) throws ConfigurateExceptionCreate a newConfigurationReferencesubscribed to FS updates.- Type Parameters:
- N- node type
- Parameters:
- loaderFunc- function that will create a new loader
- path- path to to for changes
- Returns:
- new reference
- Throws:
- ConfigurateException- if unable to complete an initial load of the configuration.
- Since:
- 4.0.0
 
- 
close- Specified by:
- closein interface- AutoCloseable
- Throws:
- IOException
 
 
-