Repository: activemq-artemis
Updated Branches:
  refs/heads/master 004753cc5 -> 74349fd17


ARTEMIS-1271 FileSystemMonitor locking improvement


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/ce756d46
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/ce756d46
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/ce756d46

Branch: refs/heads/master
Commit: ce756d46f9c90e4d7d0eb0e0090384d6d646af3e
Parents: 004753c
Author: Martyn Taylor <[email protected]>
Authored: Tue Jul 4 14:50:59 2017 +0100
Committer: Clebert Suconic <[email protected]>
Committed: Fri Jul 7 13:58:53 2017 -0400

----------------------------------------------------------------------
 .../core/server/files/FileStoreMonitor.java     | 75 +++++++++++---------
 1 file changed, 42 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ce756d46/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/files/FileStoreMonitor.java
----------------------------------------------------------------------
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/files/FileStoreMonitor.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/files/FileStoreMonitor.java
index 0f2c1ae..0600687 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/files/FileStoreMonitor.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/files/FileStoreMonitor.java
@@ -44,6 +44,7 @@ public class FileStoreMonitor extends 
ActiveMQScheduledComponent {
    private final Set<Callback> callbackList = new HashSet<>();
    private final Set<FileStore> stores = new HashSet<>();
    private double maxUsage;
+   private final Object monitorLock = new Object();
 
    public FileStoreMonitor(ScheduledExecutorService scheduledExecutorService,
                            Executor executor,
@@ -54,22 +55,28 @@ public class FileStoreMonitor extends 
ActiveMQScheduledComponent {
       this.maxUsage = maxUsage;
    }
 
-   public synchronized FileStoreMonitor addCallback(Callback callback) {
-      callbackList.add(callback);
-      return this;
+   public FileStoreMonitor addCallback(Callback callback) {
+      synchronized (monitorLock) {
+         callbackList.add(callback);
+         return this;
+      }
    }
 
-   public synchronized FileStoreMonitor addStore(File file) throws IOException 
{
-      // JDBC storage may return this as null, and we may need to ignore it
-      if (file != null && file.exists()) {
-         addStore(Files.getFileStore(file.toPath()));
+   public FileStoreMonitor addStore(File file) throws IOException {
+      synchronized (monitorLock) {
+         // JDBC storage may return this as null, and we may need to ignore it
+         if (file != null && file.exists()) {
+            addStore(Files.getFileStore(file.toPath()));
+         }
+         return this;
       }
-      return this;
    }
 
-   public synchronized FileStoreMonitor addStore(FileStore store) {
-      stores.add(store);
-      return this;
+   public FileStoreMonitor addStore(FileStore store) {
+      synchronized (monitorLock) {
+         stores.add(store);
+         return this;
+      }
    }
 
    @Override
@@ -77,32 +84,34 @@ public class FileStoreMonitor extends 
ActiveMQScheduledComponent {
       tick();
    }
 
-   public synchronized void tick() {
-      boolean over = false;
-
-      FileStore lastStore = null;
-      double usage = 0;
-
-      for (FileStore store : stores) {
-         try {
-            lastStore = store;
-            usage = calculateUsage(store);
-            over = usage > maxUsage;
-            if (over) {
-               break;
+   public void tick() {
+      synchronized (monitorLock) {
+         boolean over = false;
+
+         FileStore lastStore = null;
+         double usage = 0;
+
+         for (FileStore store : stores) {
+            try {
+               lastStore = store;
+               usage = calculateUsage(store);
+               over = usage > maxUsage;
+               if (over) {
+                  break;
+               }
+            } catch (Exception e) {
+               logger.warn(e.getMessage(), e);
             }
-         } catch (Exception e) {
-            logger.warn(e.getMessage(), e);
          }
-      }
 
-      for (Callback callback : callbackList) {
-         callback.tick(lastStore, usage);
+         for (Callback callback : callbackList) {
+            callback.tick(lastStore, usage);
 
-         if (over) {
-            callback.over(lastStore, usage);
-         } else {
-            callback.under(lastStore, usage);
+            if (over) {
+               callback.over(lastStore, usage);
+            } else {
+               callback.under(lastStore, usage);
+            }
          }
       }
    }

Reply via email to