private void reportLeasOwnerShipAndDuration(Connection connection) throws SQLException { PreparedStatement statement = null; try { statement = connection.prepareStatement(getStatements().getLeaseOwnerStatement()); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { LOG.debug(getLeaseHolderId() + " Lease held by " + resultSet.getString(1) + " till " + new Date(resultSet.getLong(2))); } } finally { close(statement); } }
protected long determineTimeDifference(Connection connection) throws SQLException { PreparedStatement statement = connection.prepareStatement(getStatements().getCurrentDateTime()); ResultSet resultSet = statement.executeQuery(); long result = 0l; if (resultSet.next()) { Timestamp timestamp = resultSet.getTimestamp(1); long diff = System.currentTimeMillis() - timestamp.getTime(); if (Math.abs(diff) > maxAllowableDiffFromDBTime) { // off by more than maxAllowableDiffFromDBTime so lets adjust result = (-diff); } LOG.info(getLeaseHolderId() + " diff adjust from db: " + result + ", db time: " + timestamp); } return result; }
private void releaseLease() { Connection connection = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement(getStatements().getLeaseUpdateStatement()); statement.setString(1, null); statement.setLong(2, 0l); statement.setString(3, getLeaseHolderId()); if (statement.executeUpdate() == 1) { LOG.info(getLeaseHolderId() + ", released lease"); } } catch (Exception e) { LOG.error(getLeaseHolderId() + " failed to release lease: " + e, e); } finally { close(statement); close(connection); } }
boolean result = false; final String sql = getStatements().getLeaseUpdateStatement(); LOG.debug(getLeaseHolderId() + ", lease keepAlive Query is " + sql); statement.setString(1, getLeaseHolderId()); statement.setLong(2, now + lockAcquireSleepInterval); statement.setString(3, getLeaseHolderId()); LOG.warn(getLeaseHolderId() + ", failed to update lease: " + e, e); IOException ioe = IOExceptionSupport.create(e); lockable.getBrokerService().handleIOException(ioe);
LOG.info(getLeaseHolderId() + " attempting to acquire exclusive lease to become the master"); String sql = getStatements().getLeaseObtainStatement(); LOG.debug(getLeaseHolderId() + " locking Query is "+sql); statement.setString(1, getLeaseHolderId()); statement.setLong(2, now + lockAcquireSleepInterval); statement.setLong(3, now); LOG.warn(getLeaseHolderId() + " lease acquire failure: "+ e, e); if (isStopping()) { throw new Exception( LOG.debug(getLeaseHolderId() + " failed to acquire lease. Sleeping for " + lockAcquireSleepInterval + " milli(s) before trying again..."); TimeUnit.MILLISECONDS.sleep(lockAcquireSleepInterval); throw new RuntimeException(getLeaseHolderId() + " failing lease acquire due to stop"); LOG.info(getLeaseHolderId() + ", becoming master with lease expiry " + new Date(now + lockAcquireSleepInterval) + " on dataSource: " + dataSource);
protected long determineTimeDifference(Connection connection) throws SQLException { PreparedStatement statement = connection.prepareStatement(getStatements().getCurrentDateTime()); ResultSet resultSet = statement.executeQuery(); long result = 0l; if (resultSet.next()) { Timestamp timestamp = resultSet.getTimestamp(1); long diff = System.currentTimeMillis() - timestamp.getTime(); if (Math.abs(diff) > maxAllowableDiffFromDBTime) { // off by more than maxAllowableDiffFromDBTime so lets adjust result = (-diff); } LOG.info(getLeaseHolderId() + " diff adjust from db: " + result + ", db time: " + timestamp); } return result; }
private void reportLeasOwnerShipAndDuration(Connection connection) throws SQLException { PreparedStatement statement = null; try { statement = connection.prepareStatement(getStatements().getLeaseOwnerStatement()); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { LOG.debug(getLeaseHolderId() + " Lease held by " + resultSet.getString(1) + " till " + new Date(resultSet.getLong(2))); } } finally { close(statement); } }
protected long determineTimeDifference(Connection connection) throws SQLException { PreparedStatement statement = connection.prepareStatement(getStatements().getCurrentDateTime()); ResultSet resultSet = statement.executeQuery(); long result = 0l; if (resultSet.next()) { Timestamp timestamp = resultSet.getTimestamp(1); long diff = System.currentTimeMillis() - timestamp.getTime(); if (Math.abs(diff) > maxAllowableDiffFromDBTime) { // off by more than maxAllowableDiffFromDBTime so lets adjust result = (-diff); } LOG.info(getLeaseHolderId() + " diff adjust from db: " + result + ", db time: " + timestamp); } return result; }
private void reportLeasOwnerShipAndDuration(Connection connection) throws SQLException { PreparedStatement statement = null; try { statement = connection.prepareStatement(getStatements().getLeaseOwnerStatement()); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { LOG.debug(getLeaseHolderId() + " Lease held by " + resultSet.getString(1) + " till " + new Date(resultSet.getLong(2))); } } finally { close(statement); } }
private void reportLeasOwnerShipAndDuration(Connection connection) throws SQLException { PreparedStatement statement = null; try { statement = connection.prepareStatement(getStatements().getLeaseOwnerStatement()); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { LOG.debug(getLeaseHolderId() + " Lease held by " + resultSet.getString(1) + " till " + new Date(resultSet.getLong(2))); } } finally { close(statement); } }
protected long determineTimeDifference(Connection connection) throws SQLException { PreparedStatement statement = connection.prepareStatement(getStatements().getCurrentDateTime()); ResultSet resultSet = statement.executeQuery(); long result = 0l; if (resultSet.next()) { Timestamp timestamp = resultSet.getTimestamp(1); long diff = System.currentTimeMillis() - timestamp.getTime(); if (Math.abs(diff) > maxAllowableDiffFromDBTime) { // off by more than maxAllowableDiffFromDBTime so lets adjust result = (-diff); } LOG.info(getLeaseHolderId() + " diff adjust from db: " + result + ", db time: " + timestamp); } return result; }
private void releaseLease() { Connection connection = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement(getStatements().getLeaseUpdateStatement()); statement.setString(1, null); statement.setLong(2, 0l); statement.setString(3, getLeaseHolderId()); if (statement.executeUpdate() == 1) { LOG.info(getLeaseHolderId() + ", released lease"); } } catch (Exception e) { LOG.error(getLeaseHolderId() + " failed to release lease: " + e, e); } finally { close(statement); close(connection); } }
private void releaseLease() { Connection connection = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement(getStatements().getLeaseUpdateStatement()); statement.setString(1, null); statement.setLong(2, 0l); statement.setString(3, getLeaseHolderId()); if (statement.executeUpdate() == 1) { LOG.info(getLeaseHolderId() + ", released lease"); } } catch (Exception e) { LOG.error(getLeaseHolderId() + " failed to release lease: " + e, e); } finally { close(statement); close(connection); } }
private void releaseLease() { Connection connection = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement(getStatements().getLeaseUpdateStatement()); statement.setString(1, null); statement.setLong(2, 0l); statement.setString(3, getLeaseHolderId()); if (statement.executeUpdate() == 1) { LOG.info(getLeaseHolderId() + ", released lease"); } } catch (Exception e) { LOG.error(getLeaseHolderId() + " failed to release lease: " + e, e); } finally { close(statement); close(connection); } }
LOG.info(getLeaseHolderId() + " attempting to acquire exclusive lease to become the master"); String sql = getStatements().getLeaseObtainStatement(); LOG.debug(getLeaseHolderId() + " locking Query is "+sql); statement.setString(1, getLeaseHolderId()); statement.setLong(2, now + lockAcquireSleepInterval); statement.setLong(3, now); LOG.warn(getLeaseHolderId() + " lease acquire failure: "+ e, e); if (isStopping()) { throw new Exception( LOG.debug(getLeaseHolderId() + " failed to acquire lease. Sleeping for " + lockAcquireSleepInterval + " milli(s) before trying again..."); TimeUnit.MILLISECONDS.sleep(lockAcquireSleepInterval); throw new RuntimeException(getLeaseHolderId() + " failing lease acquire due to stop"); LOG.info(getLeaseHolderId() + ", becoming master with lease expiry " + new Date(now + lockAcquireSleepInterval) + " on dataSource: " + dataSource);
boolean result = false; final String sql = getStatements().getLeaseUpdateStatement(); LOG.debug(getLeaseHolderId() + ", lease keepAlive Query is " + sql); statement.setString(1, getLeaseHolderId()); statement.setLong(2, now + lockAcquireSleepInterval); statement.setString(3, getLeaseHolderId()); LOG.warn(getLeaseHolderId() + ", failed to update lease: " + e, e); IOException ioe = IOExceptionSupport.create(e); lockable.getBrokerService().handleIOException(ioe);
LOG.info(getLeaseHolderId() + " attempting to acquire exclusive lease to become the master"); String sql = getStatements().getLeaseObtainStatement(); LOG.debug(getLeaseHolderId() + " locking Query is "+sql); statement.setString(1, getLeaseHolderId()); statement.setLong(2, now + lockAcquireSleepInterval); statement.setLong(3, now); LOG.warn(getLeaseHolderId() + " lease acquire failure: "+ e, e); if (isStopping()) { throw new Exception( LOG.debug(getLeaseHolderId() + " failed to acquire lease. Sleeping for " + lockAcquireSleepInterval + " milli(s) before trying again..."); TimeUnit.MILLISECONDS.sleep(lockAcquireSleepInterval); throw new RuntimeException(getLeaseHolderId() + " failing lease acquire due to stop"); LOG.info(getLeaseHolderId() + ", becoming master with lease expiry " + new Date(now + lockAcquireSleepInterval) + " on dataSource: " + dataSource);
boolean result = false; final String sql = getStatements().getLeaseUpdateStatement(); LOG.debug(getLeaseHolderId() + ", lease keepAlive Query is " + sql); statement.setString(1, getLeaseHolderId()); statement.setLong(2, now + lockAcquireSleepInterval); statement.setString(3, getLeaseHolderId()); LOG.warn(getLeaseHolderId() + ", failed to update lease: " + e, e); IOException ioe = IOExceptionSupport.create(e); lockable.getBrokerService().handleIOException(ioe);
boolean result = false; final String sql = getStatements().getLeaseUpdateStatement(); LOG.debug(getLeaseHolderId() + ", lease keepAlive Query is " + sql); statement.setString(1, getLeaseHolderId()); statement.setLong(2, now + lockAcquireSleepInterval); statement.setString(3, getLeaseHolderId()); LOG.warn(getLeaseHolderId() + ", failed to update lease: " + e, e); IOException ioe = IOExceptionSupport.create(e); lockable.getBrokerService().handleIOException(ioe);
LOG.info(getLeaseHolderId() + " attempting to acquire exclusive lease to become the master"); String sql = getStatements().getLeaseObtainStatement(); LOG.debug(getLeaseHolderId() + " locking Query is "+sql); statement.setString(1, getLeaseHolderId()); statement.setLong(2, now + lockAcquireSleepInterval); statement.setLong(3, now); LOG.warn(getLeaseHolderId() + " lease acquire failure: "+ e, e); if (isStopping()) { throw new Exception( LOG.debug(getLeaseHolderId() + " failed to acquire lease. Sleeping for " + lockAcquireSleepInterval + " milli(s) before trying again..."); TimeUnit.MILLISECONDS.sleep(lockAcquireSleepInterval); throw new RuntimeException(getLeaseHolderId() + " failing lease acquire due to stop"); LOG.info(getLeaseHolderId() + ", becoming master with lease expiry " + new Date(now + lockAcquireSleepInterval) + " on dataSource: " + dataSource);