Watchable
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
Path |
An object that may be used to locate a file in a file system. |
|
An object that may be registered with a watch service so that it can be
watched for changes and events.
This interface defines the register
method to register
the object with a WatchService
returning a WatchKey
to
represent the registration. An object may be registered with more than one
watch service. Registration with a watch service is cancelled by invoking the
key's cancel
method.
Public Methods
Registers an object with a watch service.
If the file system object identified by this object is currently
registered with the watch service then the watch key, representing that
registration, is returned after changing the event set or modifiers to
those specified by the events
and modifiers
parameters.
Changing the event set does not cause pending events for the object to be
discarded. Objects are automatically registered for the OVERFLOW
event. This event is not
required to be present in the array of events.
Otherwise the file system object has not yet been registered with the
given watch service, so it is registered and the resulting new key is
returned.
Implementations of this interface should specify the events they
support.
Parameters
watcher |
the watch service to which this object is to be registered |
events |
the events for which this object should be registered |
modifiers |
the modifiers, if any, that modify how the object is registered |
Returns
- a key representing the registration of this object with the
given watch service
Registers an object with a watch service.
An invocation of this method behaves in exactly the same way as the
invocation
watchable.register
(watcher, events, new WatchEvent.Modifier[0]);
Parameters
watcher |
the watch service to which this object is to be registered |
events |
the events for which this object should be registered |
Returns
- a key representing the registration of this object with the
given watch service
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eWatchable\u003c/code\u003e interface allows objects to be registered with a \u003ccode\u003eWatchService\u003c/code\u003e for monitoring changes and events.\u003c/p\u003e\n"],["\u003cp\u003eObjects can be registered with multiple watch services and registration is cancelled using the \u003ccode\u003eWatchKey\u003c/code\u003e's \u003ccode\u003ecancel\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eregister\u003c/code\u003e method registers the object with a \u003ccode\u003eWatchService\u003c/code\u003e and returns a \u003ccode\u003eWatchKey\u003c/code\u003e representing the registration, enabling event monitoring and modification.\u003c/p\u003e\n"],["\u003cp\u003eImplementations of the \u003ccode\u003eWatchable\u003c/code\u003e interface should specify the supported events and relevant permissions for security.\u003c/p\u003e\n"]]],["The `Watchable` interface allows objects to be monitored for changes and events by registering with a `WatchService`. Registration is done via the `register` method, which takes a `WatchService` and event `Kind` types as parameters, returning a `WatchKey`. A `Watchable` can register with multiple services, and the `register` method allows for optional `Modifier` parameters to modify registration behavior. Existing registrations can be updated or cancelled. Objects are automatically registered for the `OVERFLOW` event.\n"],null,["public interface **Watchable** \n\n|---|---|---|\n| Known Indirect Subclasses [Path](../../../../reference/java/nio/file/Path.html) |-------------------------------------------------------|---------------------------------------------------------------| | [Path](../../../../reference/java/nio/file/Path.html) | An object that may be used to locate a file in a file system. | |||\n\nAn object that may be registered with a watch service so that it can be\n*watched* for changes and events.\n\nThis interface defines the [register](../../../../reference/java/nio/file/Watchable.html#register(java.nio.file.WatchService,%20java.nio.file.WatchEvent.Kind\u003c?\u003e...)) method to register\nthe object with a [WatchService](../../../../reference/java/nio/file/WatchService.html) returning a [WatchKey](../../../../reference/java/nio/file/WatchKey.html) to\nrepresent the registration. An object may be registered with more than one\nwatch service. Registration with a watch service is cancelled by invoking the\nkey's [cancel](../../../../reference/java/nio/file/WatchKey.html#cancel()) method. \n\nSee Also\n\n- [Path.register(WatchService, WatchEvent.Kind...)](../../../../reference/java/nio/file/Path.html#register(java.nio.file.WatchService,%20java.nio.file.WatchEvent.Kind\u003c?\u003e...)) \n\nPublic Method Summary\n\n|------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [WatchKey](../../../../reference/java/nio/file/WatchKey.html) | [register](../../../../reference/java/nio/file/Watchable.html#register(java.nio.file.WatchService,%20java.nio.file.WatchEvent.Kind\u003c?\u003e[],%20java.nio.file.WatchEvent.Modifier...))([WatchService](../../../../reference/java/nio/file/WatchService.html) watcher, [Kind\\[\\]](../../../../reference/java/nio/file/WatchEvent.Kind.html)\\\u003c?\\\u003e events, [Modifier...](../../../../reference/java/nio/file/WatchEvent.Modifier.html) modifiers) Registers an object with a watch service. |\n| abstract [WatchKey](../../../../reference/java/nio/file/WatchKey.html) | [register](../../../../reference/java/nio/file/Watchable.html#register(java.nio.file.WatchService,%20java.nio.file.WatchEvent.Kind\u003c?\u003e...))([WatchService](../../../../reference/java/nio/file/WatchService.html) watcher, [Kind...](../../../../reference/java/nio/file/WatchEvent.Kind.html)\\\u003c?\\\u003e events) Registers an object with a watch service. |\n\nPublic Methods \n\npublic abstract [WatchKey](../../../../reference/java/nio/file/WatchKey.html)\n**register**\n([WatchService](../../../../reference/java/nio/file/WatchService.html) watcher, [Kind\\[\\]](../../../../reference/java/nio/file/WatchEvent.Kind.html)\\\u003c?\\\u003e events, [Modifier...](../../../../reference/java/nio/file/WatchEvent.Modifier.html) modifiers) \nRegisters an object with a watch service.\n\nIf the file system object identified by this object is currently\nregistered with the watch service then the watch key, representing that\nregistration, is returned after changing the event set or modifiers to\nthose specified by the `events` and `modifiers` parameters.\nChanging the event set does not cause pending events for the object to be\ndiscarded. Objects are automatically registered for the [OVERFLOW](../../../../reference/java/nio/file/StandardWatchEventKinds.html#OVERFLOW) event. This event is not\nrequired to be present in the array of events.\n\nOtherwise the file system object has not yet been registered with the\ngiven watch service, so it is registered and the resulting new key is\nreturned.\n\nImplementations of this interface should specify the events they\nsupport. \n\nParameters\n\n| watcher | the watch service to which this object is to be registered |\n| events | the events for which this object should be registered |\n| modifiers | the modifiers, if any, that modify how the object is registered |\n|-----------|-----------------------------------------------------------------|\n\nReturns\n\n- a key representing the registration of this object with the given watch service \n\nThrows\n\n| [UnsupportedOperationException](../../../../reference/java/lang/UnsupportedOperationException.html) | if unsupported events or modifiers are specified |\n| [IllegalArgumentException](../../../../reference/java/lang/IllegalArgumentException.html) | if an invalid of combination of events are modifiers are specified |\n| [ClosedWatchServiceException](../../../../reference/java/nio/file/ClosedWatchServiceException.html) | if the watch service is closed |\n| [IOException](../../../../reference/java/io/IOException.html) | if an I/O error occurs |\n| [SecurityException](../../../../reference/java/lang/SecurityException.html) | if a security manager is installed and it denies an unspecified permission required to monitor this object. Implementations of this interface should specify the permission checks. |\n|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\npublic abstract [WatchKey](../../../../reference/java/nio/file/WatchKey.html)\n**register**\n([WatchService](../../../../reference/java/nio/file/WatchService.html) watcher, [Kind...](../../../../reference/java/nio/file/WatchEvent.Kind.html)\\\u003c?\\\u003e events) \nRegisters an object with a watch service.\n\nAn invocation of this method behaves in exactly the same way as the\ninvocation \n\n watchable.../../../../reference/java/nio/file/Watchable.html#register(java.nio.file.WatchService,%20java.nio.file.WatchEvent.Kind\u003c?\u003e[],%20java.nio.file.WatchEvent.Modifier...)(watcher, events, new WatchEvent.Modifier[0]);\n \n\u003cbr /\u003e\n\nParameters\n\n| watcher | the watch service to which this object is to be registered |\n| events | the events for which this object should be registered |\n|---------|------------------------------------------------------------|\n\nReturns\n\n- a key representing the registration of this object with the given watch service \n\nThrows\n\n| [UnsupportedOperationException](../../../../reference/java/lang/UnsupportedOperationException.html) | if unsupported events are specified |\n| [IllegalArgumentException](../../../../reference/java/lang/IllegalArgumentException.html) | if an invalid of combination of events are specified |\n| [ClosedWatchServiceException](../../../../reference/java/nio/file/ClosedWatchServiceException.html) | if the watch service is closed |\n| [IOException](../../../../reference/java/io/IOException.html) | if an I/O error occurs |\n| [SecurityException](../../../../reference/java/lang/SecurityException.html) | if a security manager is installed and it denies an unspecified permission required to monitor this object. Implementations of this interface should specify the permission checks. |\n|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|"]]