You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/12/20 13:30:30 UTC

camel git commit: CAMEL-10599: Speedup on mac

Repository: camel
Updated Branches:
  refs/heads/master 919744af9 -> 51506f9c5


CAMEL-10599: Speedup on mac


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/51506f9c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/51506f9c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/51506f9c

Branch: refs/heads/master
Commit: 51506f9c5918e83a3b39b275765868daa00dfe5f
Parents: 919744a
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Dec 20 14:30:24 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Dec 20 14:30:24 2016 +0100

----------------------------------------------------------------------
 .../camel/impl/FileWatcherReloadStrategy.java   | 24 ++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/51506f9c/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java b/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java
index 0393044..f11e018 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java
@@ -86,17 +86,34 @@ public class FileWatcherReloadStrategy extends ReloadStrategySupport {
         if (dir.exists() && dir.isDirectory()) {
             log.info("Starting ReloadStrategy to watch directory: {}", dir);
 
-            // if its mac OSX then warn its slower
+            WatchEvent.Modifier modifier = null;
+
+            // if its mac OSX then attempt to apply workaround or warn its slower
             String os = ObjectHelper.getSystemProperty("os.name", "");
             if (os.toLowerCase(Locale.US).startsWith("mac")) {
-                log.warn("On Mac OS X the JDK WatchService is slow and it may take up till 5 seconds to notice file changes");
+                // this modifier can speedup the scanner on mac osx (as java on mac has no native file notification integration)
+                Class<WatchEvent.Modifier> clazz = getCamelContext().getClassResolver().resolveClass("com.sun.nio.file.SensitivityWatchEventModifier", WatchEvent.Modifier.class);
+                if (clazz != null) {
+                    WatchEvent.Modifier[] modifiers = clazz.getEnumConstants();
+                    for (WatchEvent.Modifier mod : modifiers) {
+                        if ("HIGH".equals(mod.name())) {
+                            modifier = mod;
+                            break;
+                        }
+                    }
+                }
+                if (modifier != null) {
+                    log.info("On Mac OS X the JDK WatchService is slow by default so enabling SensitivityWatchEventModifier.HIGH as workaround");
+                } else {
+                    log.warn("On Mac OS X the JDK WatchService is slow and it may take up till 10 seconds to notice file changes");
+                }
             }
 
             try {
                 Path path = dir.toPath();
                 WatchService watcher = path.getFileSystem().newWatchService();
                 // we cannot support deleting files as we don't know which routes that would be
-                path.register(watcher, ENTRY_CREATE, ENTRY_MODIFY);
+                path.register(watcher, new WatchEvent.Kind<?>[]{ENTRY_CREATE, ENTRY_MODIFY}, modifier);
 
                 task = new WatchFileChangesTask(watcher, path);
 
@@ -108,7 +125,6 @@ public class FileWatcherReloadStrategy extends ReloadStrategySupport {
         }
     }
 
-
     @Override
     protected void doStop() throws Exception {
         super.doStop();