1 /* 2 * Copyright (c) 2007, 2009, 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 StandardWatchEventKind 54 */ 55 public static interface Kind<T> { 56 /** 57 * Returns the name of the event kind. 58 */ 59 String name(); 60 61 /** 62 * Returns the type of the {@link WatchEvent#context context} value. 63 */ 64 Class<T> type(); 65 } 66 67 /** 68 * An event modifier that qualifies how a {@link Watchable} is registered 69 * with a {@link WatchService}. 70 * 71 * <p> This release does not define any <em>standard</em> modifiers. 72 * 73 * @since 1.7 74 * @see Watchable#register 75 */ 76 public static interface Modifier { 77 /** 78 * Returns the name of the modifier. 79 */ 80 String name(); 81 } 82 83 /** 84 * Returns the event kind. 85 * 86 * @return the event kind 87 */ 88 Kind<T> kind(); 89 90 /** 91 * Returns the event count. If the event count is greater than {@code 1} 92 * then this is a repeated event. 93 * 94 * @return the event count 95 */ 96 int count(); 97 98 /** 99 * Returns the context for the event. 100 * 101 * <p> In the case of {@link StandardWatchEventKind#ENTRY_CREATE ENTRY_CREATE}, 102 * {@link StandardWatchEventKind#ENTRY_DELETE ENTRY_DELETE}, and {@link 103 * StandardWatchEventKind#ENTRY_MODIFY ENTRY_MODIFY} events the context is 104 * a {@code Path} that is the {@link Path#relativize relative} path between 105 * the directory registered with the watch service, and the entry that is 106 * created, deleted, or modified. 107 * 108 * @return the event context; may be {@code null} 109 */ 110 T context(); 111 }