Search in sources :

Example 1 with FileAlterationObserver

use of org.apache.commons.io.monitor.FileAlterationObserver 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 FileAlterationObserver

use of org.apache.commons.io.monitor.FileAlterationObserver in project ddf by codice.

the class PollingPolicyFinderModule method initialize.

private void initialize(long pollingInterval) {
    LOGGER.debug("initializing polling: {}, every {}", xacmlPolicyDirectories, pollingInterval);
    monitor = new FileAlterationMonitor(pollingInterval * MULTIPLIER);
    for (String xacmlPolicyDirectory : xacmlPolicyDirectories) {
        File directoryToMonitor = new File(xacmlPolicyDirectory);
        FileAlterationObserver observer = new FileAlterationObserver(directoryToMonitor, getXmlFileFilter());
        observer.addListener(this);
        monitor.addObserver(observer);
        LOGGER.debug("Monitoring directory: {}", directoryToMonitor);
    }
}
Also used : FileAlterationObserver(org.apache.commons.io.monitor.FileAlterationObserver) FileAlterationMonitor(org.apache.commons.io.monitor.FileAlterationMonitor) File(java.io.File)

Example 3 with FileAlterationObserver

use of org.apache.commons.io.monitor.FileAlterationObserver in project moco by dreamhead.

the class FileMocoRunnerWatcher method monitorFile.

private FileAlterationMonitor monitorFile(final File file, final FileAlterationListener listener) {
    File parentFile = file.getParentFile();
    File directory = toDirectory(parentFile);
    FileAlterationObserver observer = new FileAlterationObserver(directory, sameFile(file));
    observer.addListener(listener);
    return new FileAlterationMonitor(INTERVAL, observer);
}
Also used : FileAlterationObserver(org.apache.commons.io.monitor.FileAlterationObserver) FileAlterationMonitor(org.apache.commons.io.monitor.FileAlterationMonitor) File(java.io.File)

Example 4 with FileAlterationObserver

use of org.apache.commons.io.monitor.FileAlterationObserver in project symmetric-ds by JumpMind.

the class FileTriggerTracker method takeFullSnapshot.

protected synchronized void takeFullSnapshot(DirectorySnapshot snapshot) {
    // update the snapshot with every file in the directory spec
    FileAlterationObserver observer = new FileAlterationObserver(fileTriggerRouter.getFileTrigger().getBaseDir(), fileTriggerRouter.getFileTrigger().createIOFileFilter());
    observer.addListener(new SnapshotUpdater(snapshot));
    observer.checkAndNotify();
}
Also used : FileAlterationObserver(org.apache.commons.io.monitor.FileAlterationObserver)

Example 5 with FileAlterationObserver

use of org.apache.commons.io.monitor.FileAlterationObserver in project ddf by codice.

the class ConfigurationFilesPoller method register.

public void register(ChangeListener listener) {
    notNull(listener, "ChangeListener cannot be null");
    changeListener = listener;
    fileAlterationObserver = new FileAlterationObserver(configurationDirectoryPath.toAbsolutePath().toString(), new SuffixFileFilter(fileExtension));
    fileAlterationObserver.addListener(this);
    watchService = new FileAlterationMonitor(POLLING_INTERVAL, fileAlterationObserver);
    try {
        watchService.start();
    } catch (Exception e) {
        logStackAndMessageSeparately(e, "Failed to start, 'Platform :: Migration' must be restarted: ");
    }
}
Also used : FileAlterationObserver(org.apache.commons.io.monitor.FileAlterationObserver) FileAlterationMonitor(org.apache.commons.io.monitor.FileAlterationMonitor) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter)

Aggregations

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