mirror of https://github.com/apache/activemq.git
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@652302 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9341f16442
commit
b35bc797ec
|
@ -37,7 +37,6 @@ public class DefaultDatabaseLocker implements DatabaseLocker {
|
||||||
private final Statements statements;
|
private final Statements statements;
|
||||||
private long sleepTime = 1000;
|
private long sleepTime = 1000;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private PreparedStatement statement;
|
|
||||||
private boolean stopping;
|
private boolean stopping;
|
||||||
|
|
||||||
public DefaultDatabaseLocker(DataSource dataSource, Statements statements) {
|
public DefaultDatabaseLocker(DataSource dataSource, Statements statements) {
|
||||||
|
@ -49,7 +48,7 @@ public class DefaultDatabaseLocker implements DatabaseLocker {
|
||||||
stopping = false;
|
stopping = false;
|
||||||
|
|
||||||
LOG.info("Attempting to acquire the exclusive lock to become the Master broker");
|
LOG.info("Attempting to acquire the exclusive lock to become the Master broker");
|
||||||
|
PreparedStatement statement = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
connection = dataSource.getConnection();
|
connection = dataSource.getConnection();
|
||||||
|
@ -97,16 +96,26 @@ public class DefaultDatabaseLocker implements DatabaseLocker {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean keepAlive() {
|
public boolean keepAlive() {
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
boolean result = false;
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = connection.prepareStatement(statements.getLockUpdateStatement());
|
statement = connection.prepareStatement(statements.getLockUpdateStatement());
|
||||||
statement.setLong(1, System.currentTimeMillis());
|
statement.setLong(1, System.currentTimeMillis());
|
||||||
int rows = statement.executeUpdate();
|
int rows = statement.executeUpdate();
|
||||||
if (rows == 1) {
|
if (rows == 1) {
|
||||||
return true;
|
result=true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Failed to update database lock: " + e, e);
|
LOG.error("Failed to update database lock: " + e, e);
|
||||||
|
}finally {
|
||||||
|
if (statement != null) {
|
||||||
|
try {
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOG.error("Failed to close statement",e);
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue