mirror of https://github.com/apache/activemq.git
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:
parent
ba740dca56
commit
19881e7799
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.store.jdbc;
|
package org.apache.activemq.store.jdbc;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -32,13 +33,19 @@ import org.apache.commons.logging.LogFactory;
|
||||||
* @version $Revision: $
|
* @version $Revision: $
|
||||||
*/
|
*/
|
||||||
public class DefaultDatabaseLocker implements DatabaseLocker {
|
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 static final Log LOG = LogFactory.getLog(DefaultDatabaseLocker.class);
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final Statements statements;
|
private final Statements statements;
|
||||||
private long sleepTime = 1000;
|
private long lockAcquireSleepInterval = DEFAULT_LOCK_ACQUIRE_SLEEP_INTERVAL;
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private boolean stopping;
|
private boolean stopping;
|
||||||
|
|
||||||
|
public DefaultDatabaseLocker(JDBCPersistenceAdapter persistenceAdapter) throws IOException {
|
||||||
|
this(persistenceAdapter.getLockDataSource(), persistenceAdapter.getStatements());
|
||||||
|
}
|
||||||
|
|
||||||
public DefaultDatabaseLocker(DataSource dataSource, Statements statements) {
|
public DefaultDatabaseLocker(DataSource dataSource, Statements statements) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.statements = statements;
|
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...");
|
LOG.debug("Sleeping for " + lockAcquireSleepInterval + " milli(s) before trying again to get the lock...");
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(lockAcquireSleepInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Becoming the master on dataSource: " + dataSource);
|
LOG.info("Becoming the master on dataSource: " + dataSource);
|
||||||
|
@ -118,4 +125,12 @@ public class DefaultDatabaseLocker implements DatabaseLocker {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLockAcquireSleepInterval() {
|
||||||
|
return lockAcquireSleepInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) {
|
||||||
|
this.lockAcquireSleepInterval = lockAcquireSleepInterval;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
|
||||||
private boolean useExternalMessageReferences;
|
private boolean useExternalMessageReferences;
|
||||||
private boolean useDatabaseLock = true;
|
private boolean useDatabaseLock = true;
|
||||||
private long lockKeepAlivePeriod = 1000*30;
|
private long lockKeepAlivePeriod = 1000*30;
|
||||||
|
private long lockAcquireSleepInterval = DefaultDatabaseLocker.DEFAULT_LOCK_ACQUIRE_SLEEP_INTERVAL;
|
||||||
private DatabaseLocker databaseLocker;
|
private DatabaseLocker databaseLocker;
|
||||||
private boolean createTablesOnStartup = true;
|
private boolean createTablesOnStartup = true;
|
||||||
private DataSource lockDataSource;
|
private DataSource lockDataSource;
|
||||||
|
@ -500,7 +501,9 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DatabaseLocker createDatabaseLocker() throws IOException {
|
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) {
|
public void setBrokerName(String brokerName) {
|
||||||
|
@ -527,4 +530,16 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
|
||||||
public void setLockKeepAlivePeriod(long lockKeepAlivePeriod) {
|
public void setLockKeepAlivePeriod(long lockKeepAlivePeriod) {
|
||||||
this.lockKeepAlivePeriod = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class JDBCQueueMasterSlaveTest extends QueueMasterSlaveTest {
|
||||||
JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
|
JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
|
||||||
persistenceAdapter.setDataSource(getExistingDataSource());
|
persistenceAdapter.setDataSource(getExistingDataSource());
|
||||||
persistenceAdapter.setLockKeepAlivePeriod(500);
|
persistenceAdapter.setLockKeepAlivePeriod(500);
|
||||||
|
persistenceAdapter.setLockAcquireSleepInterval(500);
|
||||||
master.setPersistenceAdapter(persistenceAdapter);
|
master.setPersistenceAdapter(persistenceAdapter);
|
||||||
master.start();
|
master.start();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue