activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject activemq-artemis git commit: ARTEMIS-1271 FileSystemMonitor locking improvement
Date Tue, 25 Jul 2017 16:20:11 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/1.x 004c86804 -> c3eeea491


ARTEMIS-1271 FileSystemMonitor locking improvement

(cherry picked from commit ce756d46f9c90e4d7d0eb0e0090384d6d646af3e)


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

Branch: refs/heads/1.x
Commit: c3eeea491053eff396ed4d5b55b1fdb3c8568639
Parents: 004c868
Author: Martyn Taylor <mtaylor@redhat.com>
Authored: Tue Jul 4 14:50:59 2017 +0100
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Tue Jul 25 12:19:59 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/c3eeea49/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);
+            }
          }
       }
    }


Mime
View raw message