Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
Jan Bartel 2021-01-12 11:39:17 +01:00
commit 798337a3f6
1 changed files with 5 additions and 62 deletions

View File

@ -15,7 +15,6 @@ package org.eclipse.jetty.util;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.ClosedWatchServiceException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
@ -26,7 +25,6 @@ import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EventListener;
@ -722,8 +720,6 @@ public class PathWatcher extends AbstractLifeCycle implements Runnable
private static final WatchEvent.Kind<?>[] WATCH_DIR_KINDS = {ENTRY_CREATE, ENTRY_DELETE};
private WatchService watchService;
private WatchEvent.Modifier[] watchModifiers;
private boolean nativeWatchService;
private final List<Config> configs = new ArrayList<>();
private final Map<WatchKey, Config> keys = new ConcurrentHashMap<>();
@ -854,7 +850,7 @@ public class PathWatcher extends AbstractLifeCycle implements Runnable
protected void doStart() throws Exception
{
//create a new watchservice
createWatchService();
this.watchService = FileSystems.getDefault().newWatchService();
//ensure setting of quiet time is appropriate now we have a watcher
setUpdateQuietTime(getUpdateQuietTimeMillis(), TimeUnit.MILLISECONDS);
@ -904,42 +900,6 @@ public class PathWatcher extends AbstractLifeCycle implements Runnable
listeners.clear();
}
/**
* Create a fresh WatchService and determine if it is a
* native implementation or not.
*/
private void createWatchService() throws IOException
{
//create a watch service
this.watchService = FileSystems.getDefault().newWatchService();
WatchEvent.Modifier[] modifiers = null;
boolean nativeService = true;
// Try to determine native behavior
// See http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else
try
{
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<?> pollingWatchServiceClass = Class.forName("sun.nio.fs.PollingWatchService", false, cl);
if (pollingWatchServiceClass.isAssignableFrom(this.watchService.getClass()))
{
nativeService = false;
LOG.info("Using Non-Native Java {}", pollingWatchServiceClass.getName());
Class<?> c = Class.forName("com.sun.nio.file.SensitivityWatchEventModifier");
Field f = c.getField("HIGH");
modifiers = new WatchEvent.Modifier[]{(WatchEvent.Modifier)f.get(c)};
}
}
catch (Throwable t)
{
// Unknown JVM environment, assuming native.
LOG.trace("IGNORED", t);
}
this.watchModifiers = modifiers;
this.nativeWatchService = nativeService;
}
/**
* Check to see if the watcher is in a state where it should generate
* watch events to the listeners. Used to determine if watcher should generate
@ -1042,25 +1002,16 @@ public class PathWatcher extends AbstractLifeCycle implements Runnable
protected void register(Path path, Config config) throws IOException
{
if (LOG.isDebugEnabled())
LOG.debug("Registering watch on {} {}", path, watchModifiers == null ? null : Arrays.asList(watchModifiers));
LOG.debug("Registering watch on {}", path);
register(path, config, WATCH_EVENT_KINDS);
}
private void register(Path path, Config config, WatchEvent.Kind<?>[] kinds) throws IOException
{
if (watchModifiers != null)
{
// Java Watcher
WatchKey key = path.register(watchService, kinds, watchModifiers);
keys.put(key, config);
}
else
{
// Native Watcher
WatchKey key = path.register(watchService, kinds);
keys.put(key, config);
}
// Native Watcher
WatchKey key = path.register(watchService, kinds);
keys.put(key, config);
}
/**
@ -1380,14 +1331,6 @@ public class PathWatcher extends AbstractLifeCycle implements Runnable
{
long desiredMillis = unit.toMillis(duration);
if (watchService != null && !this.nativeWatchService && (desiredMillis < 5000))
{
LOG.warn("Quiet Time is too low for non-native WatchService [{}]: {} < 5000 ms (defaulting to 5000 ms)", watchService.getClass().getName(), desiredMillis);
this.updateQuietTimeDuration = 5000;
this.updateQuietTimeUnit = TimeUnit.MILLISECONDS;
return;
}
if (IS_WINDOWS && (desiredMillis < 1000))
{
LOG.warn("Quiet Time is too low for Microsoft Windows: {} < 1000 ms (defaulting to 1000 ms)", desiredMillis);