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 sun.nio.fs;
27
28 import java.nio.file.*;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import java.io.IOException;
32 import java.util.*;
33 import sun.misc.ManagedLocalsThread;
34
35 /**
36 * Base implementation of background poller thread used in watch service
37 * implementations. A poller thread waits on events from the file system and
38 * also services "requests" from clients to register for new events or cancel
39 * existing registrations.
40 */
41
42 abstract class AbstractPoller implements Runnable {
43
44 // list of requests pending to the poller thread
45 private final LinkedList<Request> requestList;
46
47 // set to true when shutdown
48 private boolean shutdown;
49
50 protected AbstractPoller() {
51 this.requestList = new LinkedList<>();
52 this.shutdown = false;
53 }
54
55 /**
56 * Starts the poller thread
57 */
58 public void start() {
59 final Runnable thisRunnable = this;
60 AccessController.doPrivileged(new PrivilegedAction<>() {
61 @Override
62 public Object run() {
63 Thread thr = new ManagedLocalsThread(thisRunnable);
64 thr.setDaemon(true);
65 thr.start();
66 return null;
67 }
68 });
69 }
70
71 /**
72 * Wakeup poller thread so that it can service pending requests
73 */
74 abstract void wakeup() throws IOException;
75
76 /**
77 * Executed by poller thread to register directory for changes
78 */
79 abstract Object implRegister(Path path,
80 Set<? extends WatchEvent.Kind<?>> events,
81 WatchEvent.Modifier... modifiers);
82
83 /**
|
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 sun.nio.fs;
27
28 import java.nio.file.*;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import java.io.IOException;
32 import java.util.*;
33
34 /**
35 * Base implementation of background poller thread used in watch service
36 * implementations. A poller thread waits on events from the file system and
37 * also services "requests" from clients to register for new events or cancel
38 * existing registrations.
39 */
40
41 abstract class AbstractPoller implements Runnable {
42
43 // list of requests pending to the poller thread
44 private final LinkedList<Request> requestList;
45
46 // set to true when shutdown
47 private boolean shutdown;
48
49 protected AbstractPoller() {
50 this.requestList = new LinkedList<>();
51 this.shutdown = false;
52 }
53
54 /**
55 * Starts the poller thread
56 */
57 public void start() {
58 final Runnable thisRunnable = this;
59 AccessController.doPrivileged(new PrivilegedAction<>() {
60 @Override
61 public Object run() {
62 Thread thr = new Thread(null, thisRunnable, "FileSystemWatchService", 0, false);
63 thr.setDaemon(true);
64 thr.start();
65 return null;
66 }
67 });
68 }
69
70 /**
71 * Wakeup poller thread so that it can service pending requests
72 */
73 abstract void wakeup() throws IOException;
74
75 /**
76 * Executed by poller thread to register directory for changes
77 */
78 abstract Object implRegister(Path path,
79 Set<? extends WatchEvent.Kind<?>> events,
80 WatchEvent.Modifier... modifiers);
81
82 /**
|