activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject activemq git commit: AMQ-6377: Storing JournalSyncStrategy as an enum
Date Tue, 07 Mar 2017 13:11:45 GMT
Repository: activemq
Updated Branches:
  refs/heads/activemq-5.14.x 7e3f344ea -> e124f1db6


AMQ-6377: Storing JournalSyncStrategy as an enum

Switching MessageDatabase to store JournalSyncStrategy as its enum value
instead of String to avoid the performance penalty of comparing Strings
everytime isEnableJournalDiskSyncs() is called which currently happens
on every write.

(cherry picked from commit 0d824a8e6832419cb952ef503504c5296b069ad9)


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

Branch: refs/heads/activemq-5.14.x
Commit: e124f1db69ff68366ab8f0c95be6fd693f71afe4
Parents: 7e3f344
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Mon Mar 6 07:53:04 2017 -0500
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Tue Mar 7 08:11:36 2017 -0500

----------------------------------------------------------------------
 .../store/kahadb/KahaDBPersistenceAdapter.java  |  5 +++++
 .../activemq/store/kahadb/MessageDatabase.java  | 22 +++++++++++---------
 .../store/kahadb/JournalSyncStrategyTest.java   |  3 +++
 3 files changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/e124f1db/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapter.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapter.java
b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapter.java
index 7732959..0e74e82 100644
--- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapter.java
+++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBPersistenceAdapter.java
@@ -52,6 +52,7 @@ import org.apache.activemq.store.TransactionStore;
 import org.apache.activemq.store.kahadb.data.KahaLocalTransactionId;
 import org.apache.activemq.store.kahadb.data.KahaTransactionInfo;
 import org.apache.activemq.store.kahadb.data.KahaXATransactionId;
+import org.apache.activemq.store.kahadb.disk.journal.Journal.JournalDiskSyncStrategy;
 import org.apache.activemq.usage.SystemUsage;
 import org.apache.activemq.util.ServiceStopper;
 
@@ -461,6 +462,10 @@ public class KahaDBPersistenceAdapter extends LockableServiceSupport
implements
         return letter.getJournalDiskSyncStrategy();
     }
 
+    public JournalDiskSyncStrategy getJournalDiskSyncStrategyEnum() {
+        return letter.getJournalDiskSyncStrategyEnum();
+    }
+
     /**
      * @param journalDiskSyncStrategy
      */

http://git-wip-us.apache.org/repos/asf/activemq/blob/e124f1db/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java
b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java
index 5ee6c4c..4fdaa01 100644
--- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java
+++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java
@@ -254,7 +254,7 @@ public abstract class MessageDatabase extends ServiceSupport implements
BrokerSe
     protected ScheduledExecutorService scheduler;
     private final Object schedulerLock = new Object();
 
-    protected String journalDiskSyncStrategy = JournalDiskSyncStrategy.ALWAYS.name();
+    protected JournalDiskSyncStrategy journalDiskSyncStrategy = JournalDiskSyncStrategy.ALWAYS;
     protected boolean archiveDataLogs;
     protected File directoryArchive;
     protected AtomicLong journalSize = new AtomicLong(0);
@@ -3141,8 +3141,7 @@ public abstract class MessageDatabase extends ServiceSupport implements
BrokerSe
         manager.setPreallocationScope(Journal.PreallocationScope.valueOf(preallocationScope.trim().toUpperCase()));
         manager.setPreallocationStrategy(
                 Journal.PreallocationStrategy.valueOf(preallocationStrategy.trim().toUpperCase()));
-        manager.setJournalDiskSyncStrategy(
-                Journal.JournalDiskSyncStrategy.valueOf(journalDiskSyncStrategy.trim().toUpperCase()));
+        manager.setJournalDiskSyncStrategy(journalDiskSyncStrategy);
         if (getDirectoryArchive() != null) {
             IOHelper.mkdirs(getDirectoryArchive());
             manager.setDirectoryArchive(getDirectoryArchive());
@@ -3200,13 +3199,12 @@ public abstract class MessageDatabase extends ServiceSupport implements
BrokerSe
     }
 
     /**
-     * @deprecated use {@link #getJournalDiskSyncStrategy} instead
+     * @deprecated use {@link #getJournalDiskSyncStrategyEnum} or {@link #getJournalDiskSyncStrategy}
instead
      * @return
      */
     @Deprecated
     public boolean isEnableJournalDiskSyncs() {
-        return journalDiskSyncStrategy != null && JournalDiskSyncStrategy.ALWAYS.name().equals(
-                journalDiskSyncStrategy.trim().toUpperCase());
+        return journalDiskSyncStrategy == JournalDiskSyncStrategy.ALWAYS;
     }
 
     /**
@@ -3216,18 +3214,22 @@ public abstract class MessageDatabase extends ServiceSupport implements
BrokerSe
     @Deprecated
     public void setEnableJournalDiskSyncs(boolean syncWrites) {
         if (syncWrites) {
-            journalDiskSyncStrategy = JournalDiskSyncStrategy.ALWAYS.name();
+            journalDiskSyncStrategy = JournalDiskSyncStrategy.ALWAYS;
         } else {
-            journalDiskSyncStrategy = JournalDiskSyncStrategy.NEVER.name();
+            journalDiskSyncStrategy = JournalDiskSyncStrategy.NEVER;
         }
     }
 
-    public String getJournalDiskSyncStrategy() {
+    public JournalDiskSyncStrategy getJournalDiskSyncStrategyEnum() {
         return journalDiskSyncStrategy;
     }
 
+    public String getJournalDiskSyncStrategy() {
+        return journalDiskSyncStrategy.name();
+    }
+
     public void setJournalDiskSyncStrategy(String journalDiskSyncStrategy) {
-        this.journalDiskSyncStrategy = journalDiskSyncStrategy;
+        this.journalDiskSyncStrategy = JournalDiskSyncStrategy.valueOf(journalDiskSyncStrategy.trim().toUpperCase());
     }
 
     public long getJournalDiskSyncInterval() {

http://git-wip-us.apache.org/repos/asf/activemq/blob/e124f1db/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalSyncStrategyTest.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalSyncStrategyTest.java
b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalSyncStrategyTest.java
index c22339f..33810cb 100644
--- a/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalSyncStrategyTest.java
+++ b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalSyncStrategyTest.java
@@ -67,6 +67,7 @@ public class JournalSyncStrategyTest  {
         assertTrue(journal.isJournalDiskSyncPeriodic());
         assertFalse(store.isEnableJournalDiskSyncs());
         assertEquals(store.getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.PERIODIC.name());
+        assertEquals(store.getJournalDiskSyncStrategyEnum(), JournalDiskSyncStrategy.PERIODIC);
         assertEquals(store.getJournal().getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.PERIODIC);
         assertEquals(store.getJournalDiskSyncInterval(), 800);
 
@@ -87,6 +88,7 @@ public class JournalSyncStrategyTest  {
         assertFalse(store.getJournal().isJournalDiskSyncPeriodic());
         assertTrue(store.isEnableJournalDiskSyncs());
         assertEquals(store.getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.ALWAYS.name());
+        assertEquals(store.getJournalDiskSyncStrategyEnum(), JournalDiskSyncStrategy.ALWAYS);
         assertEquals(store.getJournal().getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.ALWAYS);
 
         MessageStore messageStore = store.createQueueMessageStore(new ActiveMQQueue("test"));
@@ -101,6 +103,7 @@ public class JournalSyncStrategyTest  {
         assertFalse(store.getJournal().isJournalDiskSyncPeriodic());
         assertFalse(store.isEnableJournalDiskSyncs());
         assertEquals(store.getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.NEVER.name());
+        assertEquals(store.getJournalDiskSyncStrategyEnum(), JournalDiskSyncStrategy.NEVER);
         assertEquals(store.getJournal().getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.NEVER);
 
         MessageStore messageStore = store.createQueueMessageStore(new ActiveMQQueue("test"));


Mime
View raw message