activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r693449 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/store/jdbc/ test/java/org/apache/activemq/broker/ft/
Date Tue, 09 Sep 2008 12:37:25 GMT
Author: gtully
Date: Tue Sep  9 05:37:25 2008
New Revision: 693449

URL: http://svn.apache.org/viewvc?rev=693449&view=rev
Log:
AMQ-1931 - expose lockAcquireSleepInterval on DefaultDatabaseLocker and JDBCPersistenceAdapter

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java?rev=693449&r1=693448&r2=693449&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
Tue Sep  9 05:37:25 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.store.jdbc;
 
+import java.io.IOException;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
@@ -32,13 +33,19 @@
  * @version $Revision: $
  */
 public class DefaultDatabaseLocker implements DatabaseLocker {
+    public static final long DEFAULT_LOCK_ACQUIRE_SLEEP_INTERVAL = 1000;
     private static final Log LOG = LogFactory.getLog(DefaultDatabaseLocker.class);
     private final DataSource dataSource;
     private final Statements statements;
-    private long sleepTime = 1000;
+    private long lockAcquireSleepInterval = DEFAULT_LOCK_ACQUIRE_SLEEP_INTERVAL;
+
     private Connection connection;
     private boolean stopping;
 
+    public DefaultDatabaseLocker(JDBCPersistenceAdapter persistenceAdapter) throws IOException
{
+        this(persistenceAdapter.getLockDataSource(), persistenceAdapter.getStatements());
+    }
+
     public DefaultDatabaseLocker(DataSource dataSource, Statements statements) {
         this.dataSource = dataSource;
         this.statements = statements;
@@ -80,8 +87,8 @@
                 }
             }
 
-            LOG.debug("Sleeping for " + sleepTime + " milli(s) before trying again to get
the lock...");
-            Thread.sleep(sleepTime);
+            LOG.debug("Sleeping for " + lockAcquireSleepInterval + " milli(s) before trying
again to get the lock...");
+            Thread.sleep(lockAcquireSleepInterval);
         }
 
         LOG.info("Becoming the master on dataSource: " + dataSource);
@@ -118,4 +125,12 @@
         }
         return result;
     }
+ 
+    public long getLockAcquireSleepInterval() {
+        return lockAcquireSleepInterval;
+    }
+
+    public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) {
+        this.lockAcquireSleepInterval = lockAcquireSleepInterval;
+    }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java?rev=693449&r1=693448&r2=693449&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
Tue Sep  9 05:37:25 2008
@@ -78,6 +78,7 @@
     private boolean useExternalMessageReferences;
     private boolean useDatabaseLock = true;
     private long lockKeepAlivePeriod = 1000*30;
+    private long lockAcquireSleepInterval = DefaultDatabaseLocker.DEFAULT_LOCK_ACQUIRE_SLEEP_INTERVAL;
     private DatabaseLocker databaseLocker;
     private boolean createTablesOnStartup = true;
     private DataSource lockDataSource;
@@ -500,7 +501,9 @@
     }
 
     protected DatabaseLocker createDatabaseLocker() throws IOException {
-        return new DefaultDatabaseLocker(getLockDataSource(), getStatements());
+        DefaultDatabaseLocker locker = new DefaultDatabaseLocker(this);
+        locker.setLockAcquireSleepInterval(getLockAcquireSleepInterval());
+        return locker;
     }
 
     public void setBrokerName(String brokerName) {
@@ -527,4 +530,16 @@
     public void setLockKeepAlivePeriod(long lockKeepAlivePeriod) {
         this.lockKeepAlivePeriod = lockKeepAlivePeriod;
     }
+
+    public long getLockAcquireSleepInterval() {
+        return lockAcquireSleepInterval;
+    }
+
+    /*
+     * millisecond interval between lock acquire attempts, applied to newly created DefaultDatabaseLocker
+     * not applied if DataBaseLocker is injected.
+     */
+    public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) {
+        this.lockAcquireSleepInterval = lockAcquireSleepInterval;
+    }
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java?rev=693449&r1=693448&r2=693449&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java
Tue Sep  9 05:37:25 2008
@@ -25,6 +25,7 @@
         JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
         persistenceAdapter.setDataSource(getExistingDataSource());
         persistenceAdapter.setLockKeepAlivePeriod(500);
+        persistenceAdapter.setLockAcquireSleepInterval(500);
         master.setPersistenceAdapter(persistenceAdapter);
         master.start();
     }



Mime
View raw message