mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8303413: (fs) Ignore polling interval sensitivity modifiers in PollingWatchService
Reviewed-by: alanb
This commit is contained in:
parent
99443142cc
commit
a04b1049ff
2 changed files with 31 additions and 107 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -62,8 +62,8 @@ import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
|
|||
class PollingWatchService
|
||||
extends AbstractWatchService
|
||||
{
|
||||
// default polling interval in seconds
|
||||
private static final int DEFAULT_POLLING_INTERVAL = 2;
|
||||
// polling interval in seconds
|
||||
private static final int POLLING_INTERVAL = 2;
|
||||
|
||||
// map of registrations
|
||||
private final Map<Object, PollingWatchKey> map = new HashMap<>();
|
||||
|
@ -118,19 +118,13 @@ class PollingWatchService
|
|||
if (eventSet.isEmpty())
|
||||
throw new IllegalArgumentException("No events to register");
|
||||
|
||||
// Extended modifiers may be used to specify the sensitivity level
|
||||
int sensitivity = DEFAULT_POLLING_INTERVAL;
|
||||
// no modifiers supported at this time
|
||||
for (WatchEvent.Modifier modifier : modifiers) {
|
||||
if (modifier == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) {
|
||||
sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter();
|
||||
} else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) {
|
||||
sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter();
|
||||
} else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
|
||||
sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter();
|
||||
} else {
|
||||
if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
|
||||
!ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
|
||||
!ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
|
||||
throw new UnsupportedOperationException("Modifier not supported");
|
||||
}
|
||||
}
|
||||
|
@ -142,12 +136,11 @@ class PollingWatchService
|
|||
// registration is done in privileged block as it requires the
|
||||
// attributes of the entries in the directory.
|
||||
try {
|
||||
int value = sensitivity;
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<PollingWatchKey>() {
|
||||
@Override
|
||||
public PollingWatchKey run() throws IOException {
|
||||
return doPrivilegedRegister(path, eventSet, value);
|
||||
return doPrivilegedRegister(path, eventSet);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException pae) {
|
||||
|
@ -161,8 +154,7 @@ class PollingWatchService
|
|||
// registers directory returning a new key if not already registered or
|
||||
// existing key if already registered
|
||||
private PollingWatchKey doPrivilegedRegister(Path path,
|
||||
Set<? extends WatchEvent.Kind<?>> events,
|
||||
int sensitivityInSeconds)
|
||||
Set<? extends WatchEvent.Kind<?>> events)
|
||||
throws IOException
|
||||
{
|
||||
// check file is a directory and get its file key if possible
|
||||
|
@ -191,7 +183,7 @@ class PollingWatchService
|
|||
watchKey.disable();
|
||||
}
|
||||
}
|
||||
watchKey.enable(events, sensitivityInSeconds);
|
||||
watchKey.enable(events);
|
||||
return watchKey;
|
||||
}
|
||||
|
||||
|
@ -300,8 +292,8 @@ class PollingWatchService
|
|||
valid = false;
|
||||
}
|
||||
|
||||
// enables periodic polling
|
||||
void enable(Set<? extends WatchEvent.Kind<?>> events, long period) {
|
||||
// enables periodic polling with interval POLLING_INTERVAL
|
||||
void enable(Set<? extends WatchEvent.Kind<?>> events) {
|
||||
synchronized (this) {
|
||||
// update the events
|
||||
this.events = events;
|
||||
|
@ -309,7 +301,8 @@ class PollingWatchService
|
|||
// create the periodic task to poll directories
|
||||
Runnable thunk = new Runnable() { public void run() { poll(); }};
|
||||
this.poller = scheduledExecutor
|
||||
.scheduleAtFixedRate(thunk, period, period, TimeUnit.SECONDS);
|
||||
.scheduleAtFixedRate(thunk, POLLING_INTERVAL,
|
||||
POLLING_INTERVAL, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue