Path: blob/master/src/java.base/share/classes/java/nio/file/Watchable.java
41159 views
/*1* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio.file;2627import java.io.IOException;2829/**30* An object that may be registered with a watch service so that it can be31* <em>watched</em> for changes and events.32*33* <p> This interface defines the {@link #register register} method to register34* the object with a {@link WatchService} returning a {@link WatchKey} to35* represent the registration. An object may be registered with more than one36* watch service. Registration with a watch service is cancelled by invoking the37* key's {@link WatchKey#cancel cancel} method.38*39* @since 1.740*41* @see Path#register42*/4344public interface Watchable {4546/**47* Registers an object with a watch service.48*49* <p> If the file system object identified by this object is currently50* registered with the watch service then the watch key, representing that51* registration, is returned after changing the event set or modifiers to52* those specified by the {@code events} and {@code modifiers} parameters.53* Changing the event set does not cause pending events for the object to be54* discarded. Objects are automatically registered for the {@link55* StandardWatchEventKinds#OVERFLOW OVERFLOW} event. This event is not56* required to be present in the array of events.57*58* <p> Otherwise the file system object has not yet been registered with the59* given watch service, so it is registered and the resulting new key is60* returned.61*62* <p> Implementations of this interface should specify the events they63* support.64*65* @param watcher66* the watch service to which this object is to be registered67* @param events68* the events for which this object should be registered69* @param modifiers70* the modifiers, if any, that modify how the object is registered71*72* @return a key representing the registration of this object with the73* given watch service74*75* @throws UnsupportedOperationException76* if unsupported events or modifiers are specified77* @throws IllegalArgumentException78* if an invalid of combination of events are modifiers are specified79* @throws ClosedWatchServiceException80* if the watch service is closed81* @throws IOException82* if an I/O error occurs83* @throws SecurityException84* if a security manager is installed and it denies an unspecified85* permission required to monitor this object. Implementations of86* this interface should specify the permission checks.87*/88WatchKey register(WatchService watcher,89WatchEvent.Kind<?>[] events,90WatchEvent.Modifier... modifiers)91throws IOException;929394/**95* Registers an object with a watch service.96*97* <p> An invocation of this method behaves in exactly the same way as the98* invocation99* <pre>100* watchable.{@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) register}(watcher, events, new WatchEvent.Modifier[0]);101* </pre>102*103* @param watcher104* the watch service to which this object is to be registered105* @param events106* the events for which this object should be registered107*108* @return a key representing the registration of this object with the109* given watch service110*111* @throws UnsupportedOperationException112* if unsupported events are specified113* @throws IllegalArgumentException114* if an invalid of combination of events are specified115* @throws ClosedWatchServiceException116* if the watch service is closed117* @throws IOException118* if an I/O error occurs119* @throws SecurityException120* if a security manager is installed and it denies an unspecified121* permission required to monitor this object. Implementations of122* this interface should specify the permission checks.123*/124WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events)125throws IOException;126}127128129