|
| 1 | +/* |
| 2 | + * BSD 2-Clause License |
| 3 | + * |
| 4 | + * Copyright (c) 2023, Swat.engineering |
| 5 | + * |
| 6 | + * Redistribution and use in source and binary forms, with or without |
| 7 | + * modification, are permitted provided that the following conditions are met: |
| 8 | + * |
| 9 | + * 1. Redistributions of source code must retain the above copyright notice, this |
| 10 | + * list of conditions and the following disclaimer. |
| 11 | + * |
| 12 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer in the documentation |
| 14 | + * and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 20 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | + */ |
| 27 | +package engineering.swat.watch; |
| 28 | + |
| 29 | +/** |
| 30 | + * Constants to indicate for which regular files/directories in the scope of the |
| 31 | + * watch an <i>approximation</i> of synthetic events (of kinds |
| 32 | + * {@link WatchEvent.Kind#CREATED}, {@link WatchEvent.Kind#MODIFIED}, and/or |
| 33 | + * {@link WatchEvent.Kind#DELETED}) should be issued when an overflow event |
| 34 | + * happens. These synthetic events, as well as the overflow event itself, are |
| 35 | + * subsequently passed to the user-defined event handler of the watch. |
| 36 | + * Typically, the user-defined event handler can ignore the original overflow |
| 37 | + * event (i.e., handling the synthetic events is sufficient to address the |
| 38 | + * overflow issue), but it doesn't have to (e.g., it may carry out additional |
| 39 | + * overflow bookkeeping). |
| 40 | + */ |
| 41 | +public enum OnOverflow { |
| 42 | + |
| 43 | + /** |
| 44 | + * Synthetic events are issued for <b>no regular files/directories</b> in |
| 45 | + * the scope of the watch. Thus, the user-defined event handler is fully |
| 46 | + * responsible to handle overflow events. |
| 47 | + */ |
| 48 | + NONE, |
| 49 | + |
| 50 | + /** |
| 51 | + * <p> |
| 52 | + * Synthetic events of kinds {@link WatchEvent.Kind#CREATED} and |
| 53 | + * {@link WatchEvent.Kind#MODIFIED}, but not |
| 54 | + * {@link WatchEvent.Kind#DELETED}, are issued for all regular |
| 55 | + * files/directories in the scope of the watch. Specifically, when an |
| 56 | + * overflow event happens: |
| 57 | + * |
| 58 | + * <ul> |
| 59 | + * <li>CREATED events are issued for all regular files/directories |
| 60 | + * (overapproximation). |
| 61 | + * <li>MODIFIED events are issued for all non-empty, regular files |
| 62 | + * (overapproximation) but for no directories (underapproximation). |
| 63 | + * <li>DELETED events are issued for no regular files/directories |
| 64 | + * (underapproximation). |
| 65 | + * </ul> |
| 66 | + * |
| 67 | + * <p> |
| 68 | + * This approach is relatively cheap in terms of memory usage (cf. |
| 69 | + * {@link #DIRTY}), but it results in a large over/underapproximation of the |
| 70 | + * actual events (cf. DIRTY). |
| 71 | + */ |
| 72 | + ALL, |
| 73 | + |
| 74 | + |
| 75 | + /** |
| 76 | + * <p> |
| 77 | + * Synthetic events of kinds {@link WatchEvent.Kind#CREATED}, |
| 78 | + * {@link WatchEvent.Kind#MODIFIED}, and {@link WatchEvent.Kind#DELETED} are |
| 79 | + * issued for dirty regular files/directories in the scope of the watch, as |
| 80 | + * determined using <i>last-modified-times</i>. Specifically, when an |
| 81 | + * overflow event happens: |
| 82 | + * |
| 83 | + * <ul> |
| 84 | + * <li>CREATED events are issued for all regular files/directories when the |
| 85 | + * previous last-modified-time is unknown, but the current |
| 86 | + * last-modified-time is known (i.e., the file started existing). |
| 87 | + * <li>MODIFIED events are issued for all regular files/directories when the |
| 88 | + * previous last-modified-time is before the current last-modified-time. |
| 89 | + * <li>DELETED events are issued for all regular files/directories when the |
| 90 | + * previous last-modified-time is known, but the current |
| 91 | + * last-modified-time is unknown (i.e., the file stopped existing). |
| 92 | + * </ul> |
| 93 | + * |
| 94 | + * <p> |
| 95 | + * To keep track of last-modified-times, an internal <i>index</i> is |
| 96 | + * populated with last-modified-times of all regular files/directories in |
| 97 | + * the scope of the watch when the watch is started. Each time when any |
| 98 | + * event happens, the index is updated accordingly, so when an overflow |
| 99 | + * event happens, last-modified-times can be compared as described above. |
| 100 | + * |
| 101 | + * <p> |
| 102 | + * This approach results in a small overapproximation (cf. {@link #ALL}), |
| 103 | + * but it is relatively expensive in terms of memory usage (cf. ALL), as the |
| 104 | + * watch needs to keep track of last-modified-times. |
| 105 | + */ |
| 106 | + DIRTY |
| 107 | +} |
0 commit comments