# HG changeset patch # Parent 9cc5573b56622121448393a78dc4e01f77614826 #255757: Use NIO2 Notifier by default diff -r 9cc5573b5662 -r 92306ec7fbc9 masterfs.nio2/src/org/netbeans/modules/masterfs/watcher/nio2/NioNotifier.java --- a/masterfs.nio2/src/org/netbeans/modules/masterfs/watcher/nio2/NioNotifier.java Fri Oct 23 06:14:14 2015 +0000 +++ b/masterfs.nio2/src/org/netbeans/modules/masterfs/watcher/nio2/NioNotifier.java Fri Oct 23 17:16:05 2015 +0200 @@ -60,12 +60,18 @@ * * @author Egor Ushakov */ -@ServiceProvider(service=Notifier.class, position=1010) +@ServiceProvider(service=Notifier.class, position=400) public class NioNotifier extends Notifier { private final WatchService watcher; + private final boolean DISABLED = Boolean.getBoolean("org.netbeans" //NOI18N + + ".modules.masterfs.watcher.enforceNativeNotifier"); //NOI18N public NioNotifier() throws IOException { - this.watcher = FileSystems.getDefault().newWatchService(); + if (!DISABLED) { + this.watcher = FileSystems.getDefault().newWatchService(); + } else { + this.watcher = null; + } } @Override @@ -113,6 +119,9 @@ @Override protected void start() throws IOException { + if (DISABLED) { + throw new IOException("Native notifier is enforced."); //NOI18N + } } @Override diff -r 9cc5573b5662 -r 92306ec7fbc9 masterfs.windows/src/org/netbeans/modules/masterfs/watcher/windows/WindowsNotifier.java --- a/masterfs.windows/src/org/netbeans/modules/masterfs/watcher/windows/WindowsNotifier.java Fri Oct 23 06:14:14 2015 +0000 +++ b/masterfs.windows/src/org/netbeans/modules/masterfs/watcher/windows/WindowsNotifier.java Fri Oct 23 17:16:05 2015 +0200 @@ -73,7 +73,7 @@ * * @author nenik */ -@ServiceProvider(service=Notifier.class, position=100) +@ServiceProvider(service=Notifier.class, position=600) public final class WindowsNotifier extends Notifier { static final Logger LOG = Logger.getLogger(WindowsNotifier.class.getName()); diff -r 9cc5573b5662 -r 92306ec7fbc9 masterfs/src/org/netbeans/modules/masterfs/watcher/Watcher.java --- a/masterfs/src/org/netbeans/modules/masterfs/watcher/Watcher.java Fri Oct 23 06:14:14 2015 +0000 +++ b/masterfs/src/org/netbeans/modules/masterfs/watcher/Watcher.java Fri Oct 23 17:16:05 2015 +0200 @@ -77,6 +77,12 @@ private static final Map MODIFIED = new WeakHashMap(); private final Ext ext; + private static long regCount = 0; + private static long regTime = 0; + + private static long unregCount = 0; + private static long unregTime = 0; + public Watcher() { // Watcher disabled manually or for some tests if (Boolean.getBoolean("org.netbeans.modules.masterfs.watcher.disable")) { @@ -114,7 +120,18 @@ if (fo.isData()) { fo = fo.getParent(); } + // TODO remove new lines for time measurement + long start = System.currentTimeMillis(); ext.register(fo); + long end = System.currentTimeMillis(); + + regCount ++; + regTime += (end - start); + + if (regCount % 100 == 0) { + LOG.log(Level.INFO, "Registered {0} watchers in average time {1} ms", + new Object[] {regCount, (double) regTime / regCount}); + } } public static void unregister(FileObject fo) { @@ -128,7 +145,18 @@ return; } } + // TODO remove new lines for time measurement + long start = System.currentTimeMillis(); ext.unregister(fo); + long end = System.currentTimeMillis(); + + unregCount ++; + unregTime += (end - start); + + if (unregCount % 100 == 0) { + LOG.log(Level.INFO, "Unregistered {0} watchers in average time {1} ms", + new Object[] {unregCount, (double) unregTime / unregCount}); + } } public static File wrap(File f, FileObject fo) {