use of org.jumpmind.symmetric.model.Lock in project symmetric-ds by JumpMind.
the class FileSyncService method trackChangesFastScan.
protected void trackChangesFastScan(ProcessInfo processInfo, boolean useCrc) {
boolean isLocked = engine.getClusterService().lock(ClusterConstants.FILE_SYNC_SCAN);
Lock lock = engine.getClusterService().findLocks().get(ClusterConstants.FILE_SYNC_SCAN);
log.debug("File tracker range of " + lock.getLastLockTime() + " to " + lock.getLockTime() + ", isLocked=" + isLocked);
int maxRowsBeforeCommit = engine.getParameterService().getInt(ParameterConstants.DATA_LOADER_MAX_ROWS_BEFORE_COMMIT);
try {
List<FileTriggerRouter> fileTriggerRouters = getFileTriggerRoutersForCurrentNode();
for (final FileTriggerRouter fileTriggerRouter : fileTriggerRouters) {
if (fileTriggerRouter.isEnabled()) {
FileAlterationObserver observer = new FileAlterationObserver(fileTriggerRouter.getFileTrigger().getBaseDir(), fileTriggerRouter.getFileTrigger().createIOFileFilter());
FileTriggerFileModifiedListener listener = new FileTriggerFileModifiedListener(fileTriggerRouter, lock.getLastLockTime(), lock.getLockTime(), processInfo, useCrc, new FileModifiedCallback(maxRowsBeforeCommit) {
public void commit(DirectorySnapshot dirSnapshot) {
saveDirectorySnapshot(fileTriggerRouter, dirSnapshot);
}
public DirectorySnapshot getLastDirectorySnapshot(String relativeDir) {
return getDirectorySnapshot(fileTriggerRouter, relativeDir);
}
}, engine);
observer.addListener(listener);
observer.checkAndNotify();
}
}
engine.getClusterService().unlock(ClusterConstants.FILE_SYNC_SCAN);
} catch (Exception ex) {
log.error("Failed to track changes", ex);
}
}
use of org.jumpmind.symmetric.model.Lock in project symmetric-ds by JumpMind.
the class ClusterService method unlockExclusive.
protected boolean unlockExclusive(final String action) {
if (isClusteringEnabled()) {
return sqlTemplate.update(getSql("releaseExclusiveLockSql"), new Object[] { action, TYPE_EXCLUSIVE }) == 1;
} else {
Lock lock = lockCache.get(action);
if (lock != null) {
synchronized (lock) {
if (lock.getLockType().equals(TYPE_EXCLUSIVE)) {
lock.setLastLockingServerId(lock.getLockingServerId());
lock.setLockingServerId(null);
lock.setLastLockTime(lock.getLockTime());
lock.setLockTime(null);
return true;
}
}
}
}
return false;
}
use of org.jumpmind.symmetric.model.Lock in project symmetric-ds by JumpMind.
the class ClusterService method lockShared.
protected boolean lockShared(final String action) {
final Date timeout = DateUtils.addMilliseconds(new Date(), (int) -parameterService.getLong(ParameterConstants.LOCK_TIMEOUT_MS));
if (isClusteringEnabled()) {
return sqlTemplate.update(getSql("acquireSharedLockSql"), new Object[] { TYPE_SHARED, getServerId(), new Date(), action, TYPE_SHARED, timeout }) == 1;
} else {
Lock lock = lockCache.get(action);
if (lock != null) {
synchronized (lock) {
if ((lock.getLockType().equals(TYPE_SHARED) || lock.getLockTime() == null || lock.getLockTime().before(timeout)) && (lock.isSharedEnable() || lock.getSharedCount() == 0)) {
lock.setLockType(TYPE_SHARED);
lock.setLockingServerId(getServerId());
lock.setLockTime(new Date());
if (lock.getSharedCount() == 0) {
lock.setSharedEnable(true);
}
lock.setSharedCount(lock.getSharedCount() + 1);
return true;
}
}
}
}
return false;
}
use of org.jumpmind.symmetric.model.Lock in project symmetric-ds by JumpMind.
the class ClusterService method unlockCluster.
protected boolean unlockCluster(String action, String serverId) {
if (isClusteringEnabled()) {
return sqlTemplate.update(getSql("releaseClusterLockSql"), new Object[] { action, TYPE_CLUSTER, serverId }) > 0;
} else {
Lock lock = lockCache.get(action);
if (lock != null) {
synchronized (lock) {
if (lock.getLockType().equals(TYPE_CLUSTER) && serverId.equals(lock.getLockingServerId())) {
lock.setLastLockingServerId(lock.getLockingServerId());
lock.setLockingServerId(null);
lock.setLastLockTime(lock.getLockTime());
lock.setLockTime(null);
return true;
}
}
}
}
return false;
}
use of org.jumpmind.symmetric.model.Lock in project symmetric-ds by JumpMind.
the class ClusterService method unlockShared.
protected boolean unlockShared(final String action) {
if (isClusteringEnabled()) {
return sqlTemplate.update(getSql("releaseSharedLockSql"), new Object[] { action, TYPE_SHARED }) == 1;
} else {
Lock lock = lockCache.get(action);
if (lock != null) {
synchronized (lock) {
if (lock.getLockType().equals(TYPE_SHARED)) {
lock.setLastLockTime(lock.getLockTime());
lock.setLastLockingServerId(lock.getLockingServerId());
if (lock.getSharedCount() == 1) {
lock.setSharedEnable(false);
lock.setLockingServerId(null);
lock.setLockTime(null);
}
if (lock.getSharedCount() > 1) {
lock.setSharedCount(lock.getSharedCount() - 1);
} else {
lock.setSharedCount(0);
}
return true;
}
}
}
}
return false;
}
Aggregations