Search in sources :

Example 1 with DefaultFileSystemWatcherService

use of org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService in project neo4j by neo4j.

the class EditionModule method createFileSystemWatcherService.

protected FileSystemWatcherService createFileSystemWatcherService(FileSystemAbstraction fileSystem, File storeDir, LogService logging, JobScheduler jobScheduler, Predicate<String> fileNameFilter) {
    try {
        RestartableFileSystemWatcher watcher = new RestartableFileSystemWatcher(fileSystem.fileWatcher());
        watcher.addFileWatchEventListener(new DefaultFileDeletionEventListener(logging, fileNameFilter));
        watcher.watch(storeDir);
        // register to watch store dir parent folder to see when store dir removed
        watcher.watch(storeDir.getParentFile());
        return new DefaultFileSystemWatcherService(jobScheduler, watcher);
    } catch (Exception e) {
        Log log = logging.getInternalLog(getClass());
        log.warn("Can not create file watcher for current file system. File monitoring capabilities for store " + "files will be disabled.", e);
        return FileSystemWatcherService.EMPTY_WATCHER;
    }
}
Also used : DefaultFileDeletionEventListener(org.neo4j.kernel.impl.util.watcher.DefaultFileDeletionEventListener) Log(org.neo4j.logging.Log) DefaultFileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService) RestartableFileSystemWatcher(org.neo4j.io.fs.watcher.RestartableFileSystemWatcher) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

Example 2 with DefaultFileSystemWatcherService

use of org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService in project neo4j by neo4j.

the class GlobalModule method createFileSystemWatcherService.

private FileSystemWatcherService createFileSystemWatcherService(FileSystemAbstraction fileSystem, LogService logging, JobScheduler jobScheduler, Config config) {
    if (!config.get(filewatcher_enabled)) {
        Log log = logging.getInternalLog(getClass());
        log.info("File watcher disabled by configuration.");
        return FileSystemWatcherService.EMPTY_WATCHER;
    }
    try {
        return new DefaultFileSystemWatcherService(jobScheduler, fileSystem.fileWatcher());
    } catch (Exception e) {
        Log log = logging.getInternalLog(getClass());
        log.warn("Can not create file watcher for current file system. File monitoring capabilities for store files will be disabled.", e);
        return FileSystemWatcherService.EMPTY_WATCHER;
    }
}
Also used : Log(org.neo4j.logging.Log) DefaultFileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService)

Example 3 with DefaultFileSystemWatcherService

use of org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService in project neo4j by neo4j.

the class DefaultFileSystemWatcherServiceTest method stopMonitoringWhenLifecycleStops.

@Test
void stopMonitoringWhenLifecycleStops() throws Throwable {
    DefaultFileSystemWatcherService service = new DefaultFileSystemWatcherService(jobScheduler, fileWatcher);
    service.init();
    service.start();
    service.stop();
    verify(fileWatcher).stopWatching();
}
Also used : DefaultFileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultFileSystemWatcherService

use of org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService in project neo4j by neo4j.

the class DefaultFileSystemWatcherServiceTest method startMonitoringWhenLifecycleStarting.

@Test
void startMonitoringWhenLifecycleStarting() throws Throwable {
    CountDownLatch latch = new CountDownLatch(1);
    FileWatcher watcher = new TestFileWatcher(latch);
    DefaultFileSystemWatcherService service = new DefaultFileSystemWatcherService(jobScheduler, watcher);
    service.init();
    service.start();
    latch.await();
}
Also used : SilentFileWatcher(org.neo4j.io.fs.watcher.SilentFileWatcher) FileWatcher(org.neo4j.io.fs.watcher.FileWatcher) DefaultFileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultFileSystemWatcherService

use of org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService in project neo4j by neo4j.

the class DefaultFileSystemWatcherServiceTest method closeFileWatcherOnShutdown.

@Test
void closeFileWatcherOnShutdown() throws Throwable {
    DefaultFileSystemWatcherService service = new DefaultFileSystemWatcherService(jobScheduler, fileWatcher);
    service.init();
    service.start();
    service.stop();
    service.shutdown();
    verify(fileWatcher).close();
}
Also used : DefaultFileSystemWatcherService(org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultFileSystemWatcherService (org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService)5 Test (org.junit.jupiter.api.Test)3 Log (org.neo4j.logging.Log)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 FileWatcher (org.neo4j.io.fs.watcher.FileWatcher)1 RestartableFileSystemWatcher (org.neo4j.io.fs.watcher.RestartableFileSystemWatcher)1 SilentFileWatcher (org.neo4j.io.fs.watcher.SilentFileWatcher)1 KernelException (org.neo4j.kernel.api.exceptions.KernelException)1 DefaultFileDeletionEventListener (org.neo4j.kernel.impl.util.watcher.DefaultFileDeletionEventListener)1