public final class Watch extends Object
static methods for configurating and creating a file system
watch service.
For example, a crude service that uploads to a remote location any file created in a directory could be implemented like this:
Watch.Listener listener = new SimpleWatchListener() {
final Uploaded uploader = createUploader();
@Override
public final void onRegularFileCreated(RegularFile file) {
// uploader must handle any exception
uploader.upload(file);
}
};
Watch.Service service = Watch.createService(
Watch.watchDirectory(
LocalFs.getDirectory("/srv/upload"),
listener,
Watch.CREATED
)
);
Services.start(service);
| Modifier and Type | Class and Description |
|---|---|
static class |
Watch.Event
The events available for watching.
|
static interface |
Watch.Listener
A listener for previously registered file system events.
|
static interface |
Watch.Option
Represents an option for configuring a watch service.
|
static interface |
Watch.Service
The watch service interface, allows for starting and stopping the watch
service.
|
static interface |
Watch.ServiceBuilder
A façade for configuring a watch service builder.
|
| Modifier and Type | Field and Description |
|---|---|
static Watch.Event |
CREATED
The
Watch.Event.CREATED constant (provided for convenience). |
static Watch.Event |
DELETED
The
Watch.Event.DELETED constant (provided for convenience). |
static Watch.Event |
MODIFIED
The
Watch.Event.MODIFIED constant (provided for convenience). |
| Modifier and Type | Method and Description |
|---|---|
static Watch.Service |
createService(Watch.Option... options)
Creates and returns a new watch service with the specified options.
|
static Watch.Option |
watchDirectory(Directory directory,
Watch.Listener listener,
Watch.Event event)
Returns a new configuration option to watch the specified directory with
the specified listener for the specified event.
|
public static final Watch.Event CREATED
Watch.Event.CREATED constant (provided for convenience).public static final Watch.Event DELETED
Watch.Event.DELETED constant (provided for convenience).public static final Watch.Event MODIFIED
Watch.Event.MODIFIED constant (provided for convenience).public static Watch.Service createService(Watch.Option... options) throws IOException
Once created, watch service instance cannot be modified. Therefore, all registrations must be supplied at creation time.
options - the options to use for creating the watch servcieIOException - if an I/O error occurspublic static Watch.Option watchDirectory(Directory directory, Watch.Listener listener, Watch.Event event)
directory - the directory to watch for eventslistener - the listener instance that will act upon the watched eventsevent - the event to watch forcreateService(Option...) service factory methodCopyright © 2021–2022 Objectos Software LTDA. All rights reserved.