Search in sources :

Example 1 with DirectorySnapshot

use of org.jumpmind.symmetric.file.DirectorySnapshot 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);
    }
}
Also used : FileAlterationObserver(org.apache.commons.io.monitor.FileAlterationObserver) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) FileTriggerFileModifiedListener(org.jumpmind.symmetric.file.FileTriggerFileModifiedListener) FileModifiedCallback(org.jumpmind.symmetric.file.FileTriggerFileModifiedListener.FileModifiedCallback) FileConflictException(org.jumpmind.symmetric.file.FileConflictException) NoContentException(org.jumpmind.symmetric.transport.NoContentException) SymmetricException(org.jumpmind.symmetric.SymmetricException) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) Lock(org.jumpmind.symmetric.model.Lock) DirectorySnapshot(org.jumpmind.symmetric.file.DirectorySnapshot)

Example 2 with DirectorySnapshot

use of org.jumpmind.symmetric.file.DirectorySnapshot in project symmetric-ds by JumpMind.

the class FileSyncService method trackChanges.

protected void trackChanges(ProcessInfo processInfo, boolean useCrc) {
    List<FileTriggerRouter> fileTriggerRouters = getFileTriggerRoutersForCurrentNode();
    for (FileTriggerRouter fileTriggerRouter : fileTriggerRouters) {
        if (fileTriggerRouter.isEnabled()) {
            try {
                FileTriggerTracker tracker = new FileTriggerTracker(fileTriggerRouter, getDirectorySnapshot(fileTriggerRouter), processInfo, useCrc, engine);
                DirectorySnapshot dirSnapshot = tracker.trackChanges();
                saveDirectorySnapshot(fileTriggerRouter, dirSnapshot);
            } catch (Exception ex) {
                log.error("Failed to track changes for file trigger router: " + fileTriggerRouter.getFileTrigger().getTriggerId() + "::" + fileTriggerRouter.getRouter().getRouterId(), ex);
            }
        }
    }
}
Also used : FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) FileTriggerTracker(org.jumpmind.symmetric.file.FileTriggerTracker) FileConflictException(org.jumpmind.symmetric.file.FileConflictException) NoContentException(org.jumpmind.symmetric.transport.NoContentException) SymmetricException(org.jumpmind.symmetric.SymmetricException) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) DirectorySnapshot(org.jumpmind.symmetric.file.DirectorySnapshot)

Aggregations

IOException (java.io.IOException)2 IoException (org.jumpmind.exception.IoException)2 SymmetricException (org.jumpmind.symmetric.SymmetricException)2 DirectorySnapshot (org.jumpmind.symmetric.file.DirectorySnapshot)2 FileConflictException (org.jumpmind.symmetric.file.FileConflictException)2 FileTriggerRouter (org.jumpmind.symmetric.model.FileTriggerRouter)2 NoContentException (org.jumpmind.symmetric.transport.NoContentException)2 FileAlterationObserver (org.apache.commons.io.monitor.FileAlterationObserver)1 FileTriggerFileModifiedListener (org.jumpmind.symmetric.file.FileTriggerFileModifiedListener)1 FileModifiedCallback (org.jumpmind.symmetric.file.FileTriggerFileModifiedListener.FileModifiedCallback)1 FileTriggerTracker (org.jumpmind.symmetric.file.FileTriggerTracker)1 Lock (org.jumpmind.symmetric.model.Lock)1