1 /*
2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package java.nio.file;
27 
28 /**
29  * An event or a repeated event for an object that is registered with a {@link
30  * WatchService}.
31  *
32  * <p> An event is classified by its {@link #kind() kind} and has a {@link
33  * #count() count} to indicate the number of times that the event has been
34  * observed. This allows for efficient representation of repeated events. The
35  * {@link #context() context} method returns any context associated with
36  * the event. In the case of a repeated event then the context is the same for
37  * all events.
38  *
39  * <p> Watch events are immutable and safe for use by multiple concurrent
40  * threads.
41  *
42  * @param   <T>     The type of the context object associated with the event
43  *
44  * @since 1.7
45  */
46 
47 public interface WatchEvent<T> {
48 
49     /**
50      * An event kind, for the purposes of identification.
51      *
52      * @since 1.7
53      * @see StandardWatchEventKinds
54      */
55     public static interface Kind<T> {
56         /**
57          * Returns the name of the event kind.
58          *
59          * @return the name of the event kind
60          */
name()61         String name();
62 
63         /**
64          * Returns the type of the {@link WatchEvent#context context} value.
65          *
66          *
67          * @return the type of the context value
68          */
type()69         Class<T> type();
70     }
71 
72     /**
73      * An event modifier that qualifies how a {@link Watchable} is registered
74      * with a {@link WatchService}.
75      *
76      * <p> This release does not define any <em>standard</em> modifiers.
77      *
78      * @since 1.7
79      * @see Watchable#register
80      */
81     public static interface Modifier {
82         /**
83          * Returns the name of the modifier.
84          *
85          * @return the name of the modifier
86          */
name()87         String name();
88     }
89 
90     /**
91      * Returns the event kind.
92      *
93      * @return  the event kind
94      */
kind()95     Kind<T> kind();
96 
97     /**
98      * Returns the event count. If the event count is greater than {@code 1}
99      * then this is a repeated event.
100      *
101      * @return  the event count
102      */
count()103     int count();
104 
105     /**
106      * Returns the context for the event.
107      *
108      * <p> In the case of {@link StandardWatchEventKinds#ENTRY_CREATE ENTRY_CREATE},
109      * {@link StandardWatchEventKinds#ENTRY_DELETE ENTRY_DELETE}, and {@link
110      * StandardWatchEventKinds#ENTRY_MODIFY ENTRY_MODIFY} events the context is
111      * a {@code Path} that is the {@link Path#relativize relative} path between
112      * the directory registered with the watch service, and the entry that is
113      * created, deleted, or modified.
114      *
115      * @return  the event context; may be {@code null}
116      */
context()117     T context();
118 }
119