public void cleanupThisServer() { cleanupForServer(_msId); }
public static synchronized Merovingian2 createLockMaster(long msId) { assert s_instance == null : "No lock can serve two masters. Either he will hate the one and love the other, or he will be devoted to the one and despise the other."; s_instance = new Merovingian2(msId); s_instance.cleanupThisServer(); try { JmxUtil.registerMBean("Locks", "Locks", s_instance); } catch (Exception e) { s_logger.error("Unable to register for JMX", e); } return s_instance; }
public boolean lock(final String name, final int timeoutSeconds) { Merovingian2 lockMaster = Merovingian2.getLockMaster(); if (lockMaster == null) { throw new CloudRuntimeException("There's no support for locking yet"); } return lockMaster.acquire(name, timeoutSeconds); }
public boolean release(final String name) { Merovingian2 lockMaster = Merovingian2.getLockMaster(); if (lockMaster == null) { throw new CloudRuntimeException("There's no support for locking yet"); } return lockMaster.release(name); }
public void cleanup() { closePreviousStatement(); removeUpTo(null, null); if (_txn) { rollbackTransaction(); } _txn = false; _name = null; closeConnection(); _stack.clear(); Merovingian2 lockMaster = Merovingian2.getLockMaster(); if (lockMaster != null) { lockMaster.cleanupThread(); } }
@Override public List<Map<String, String>> getAllLocks() { return getLocks(SELECT_SQL, null); }
protected boolean increment(String key, String threadName, int threadId) { try (PreparedStatement pstmt = _concierge.conn().prepareStatement(INCREMENT_SQL);){ pstmt.setString(1, key); pstmt.setLong(2, _msId); pstmt.setString(3, threadName); pstmt.setInt(4, threadId); int rows = pstmt.executeUpdate(); assert (rows <= 1) : "hmm...non unique key? " + pstmt; if (s_logger.isTraceEnabled()) { s_logger.trace("lck-" + key + (rows == 1 ? " acquired again" : " failed to acquire again")); } if (rows == 1) { incrCount(); return true; } return false; } catch (Exception e) { s_logger.error("increment:Exception:"+e.getMessage()); throw new CloudRuntimeException("increment:Exception:"+e.getMessage(), e); } }
s_logger.trace("lck-" + key + " removed"); decrCount(); }catch (Exception e) { s_logger.error("release:Exception:"+ e.getMessage());
public boolean release(final String name) { final Merovingian2 lockMaster = Merovingian2.getLockMaster(); if (lockMaster == null) { throw new CloudRuntimeException("There's no support for locking yet"); } return lockMaster.release(name); }
public void cleanup() { closePreviousStatement(); removeUpTo(null, null); if (_txn) { rollbackTransaction(); } _txn = false; _name = null; closeConnection(); _stack.clear(); final Merovingian2 lockMaster = Merovingian2.getLockMaster(); if (lockMaster != null) { lockMaster.cleanupThread(); } }
@Override public List<Map<String, String>> getLocksAcquiredByThisServer() { return getLocks(SELECT_MGMT_LOCKS_SQL, _msId); }
protected boolean doAcquire(String key, String threadName, int threadId) { long startTime = InaccurateClock.getTime(); try(PreparedStatement pstmt = _concierge.conn().prepareStatement(ACQUIRE_SQL);) { pstmt.setString(1, key); pstmt.setLong(2, _msId); pstmt.setString(3, threadName); pstmt.setInt(4, threadId); pstmt.setString(5, DateUtil.getDateDisplayString(_gmtTimeZone, new Date())); try { int rows = pstmt.executeUpdate(); if (rows == 1) { if (s_logger.isTraceEnabled()) { s_logger.trace("Acquired for lck-" + key); } incrCount(); return true; } } catch (SQLException e) { if (!(e.getSQLState().equals("23000") && e.getErrorCode() == 1062)) { throw new CloudRuntimeException("Unable to lock " + key + ". Waited " + (InaccurateClock.getTime() - startTime), e); } } } catch (SQLException e) { s_logger.error("doAcquire:Exception:"+e.getMessage()); throw new CloudRuntimeException("Unable to lock " + key + ". Waited " + (InaccurateClock.getTime() - startTime), e); } s_logger.trace("Unable to acquire lck-" + key); return false; }
s_logger.trace("lck-" + key + " removed"); decrCount(); } catch (final Exception e) { s_logger.error("release:Exception:" + e.getMessage());
public static synchronized Merovingian2 createLockMaster(final long msId) { assert s_instance == null : "No lock can serve two masters. Either he will hate the one and love the other, or he will be devoted to the one and despise the other."; s_instance = new Merovingian2(msId); s_instance.cleanupThisServer(); try { JmxUtil.registerMBean("Locks", "Locks", s_instance); } catch (final Exception e) { s_logger.error("Unable to register for JMX", e); } return s_instance; }
public boolean lock(final String name, final int timeoutSeconds) { final Merovingian2 lockMaster = Merovingian2.getLockMaster(); if (lockMaster == null) { throw new CloudRuntimeException("There's no support for locking yet"); } return lockMaster.acquire(name, timeoutSeconds); }
@Override public void onManagementNodeLeft(List<? extends ManagementServerHost> nodeList, long selfNodeId) { for (ManagementServerHost node : nodeList) { _lockMaster.cleanupForServer(node.getMsid()); } }
@Override public List<Map<String, String>> getAllLocks() { return getLocks(SELECT_SQL, null); }
protected boolean increment(final String key, final String threadName, final int threadId) { try (PreparedStatement pstmt = _concierge.conn().prepareStatement(INCREMENT_SQL)) { pstmt.setString(1, key); pstmt.setLong(2, _msId); pstmt.setString(3, threadName); pstmt.setInt(4, threadId); final int rows = pstmt.executeUpdate(); assert (rows <= 1) : "hmm...non unique key? " + pstmt; if (s_logger.isTraceEnabled()) { s_logger.trace("lck-" + key + (rows == 1 ? " acquired again" : " failed to acquire again")); } if (rows == 1) { incrCount(); return true; } return false; } catch (final Exception e) { s_logger.error("increment:Exception:" + e.getMessage()); throw new CloudRuntimeException("increment:Exception:" + e.getMessage(), e); } }