AMQ-1931 - expose lockAcquireSleepInterval on DefaultDatabaseLocker and JDBCPersistenceAdapter

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@693449 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2008-09-09 12:37:25 +00:00
parent ba740dca56
commit 19881e7799
3 changed files with 35 additions and 4 deletions

View File

@ -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 @@ import org.apache.commons.logging.LogFactory;
* @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 @@ public class DefaultDatabaseLocker implements DatabaseLocker {
}
}
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 @@ public class DefaultDatabaseLocker implements DatabaseLocker {
}
return result;
}
public long getLockAcquireSleepInterval() {
return lockAcquireSleepInterval;
}
public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) {
this.lockAcquireSleepInterval = lockAcquireSleepInterval;
}
}

View File

@ -78,6 +78,7 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
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 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
}
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 class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
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;
}
}

View File

@ -25,6 +25,7 @@ public class JDBCQueueMasterSlaveTest extends QueueMasterSlaveTest {
JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
persistenceAdapter.setDataSource(getExistingDataSource());
persistenceAdapter.setLockKeepAlivePeriod(500);
persistenceAdapter.setLockAcquireSleepInterval(500);
master.setPersistenceAdapter(persistenceAdapter);
master.start();
}