Search in sources :

Example 1 with ConcurrencySqlException

use of org.jumpmind.db.sql.ConcurrencySqlException in project symmetric-ds by JumpMind.

the class ClusterService method lockCluster.

protected boolean lockCluster(String action, Date timeToBreakLock, Date timeLockAcquired, String serverId) {
    if (isClusteringEnabled()) {
        try {
            return sqlTemplate.update(getSql("acquireClusterLockSql"), new Object[] { serverId, timeLockAcquired, action, TYPE_CLUSTER, timeToBreakLock, serverId }) == 1;
        } catch (ConcurrencySqlException ex) {
            log.debug("Ignoring concurrency error and reporting that we failed to get the cluster lock: {}", ex.getMessage());
        }
    } else {
        Lock lock = lockCache.get(action);
        if (lock != null) {
            synchronized (lock) {
                if (lock.getLockType().equals(TYPE_CLUSTER) && (lock.getLockTime() == null || lock.getLockTime().before(timeToBreakLock) || serverId.equals(lock.getLockingServerId()))) {
                    lock.setLockingServerId(serverId);
                    lock.setLockTime(timeLockAcquired);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ConcurrencySqlException(org.jumpmind.db.sql.ConcurrencySqlException) Lock(org.jumpmind.symmetric.model.Lock)

Aggregations

ConcurrencySqlException (org.jumpmind.db.sql.ConcurrencySqlException)1 Lock (org.jumpmind.symmetric.model.Lock)1