diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/watcher/FileWatcherLifecycleAdapter.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/watcher/FileWatcherLifecycleAdapter.java deleted file mode 100644 index 629a407e76da9..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/watcher/FileWatcherLifecycleAdapter.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.impl.util.watcher; - -import java.util.concurrent.ThreadFactory; - -import org.neo4j.io.fs.watcher.FileWatcher; -import org.neo4j.scheduler.JobScheduler; -import org.neo4j.kernel.lifecycle.LifecycleAdapter; - -/** - * Adapter that integrates file watching possibilities with platform lifecycle. - * Monitoring will be started when corresponding life will be started and stopped as soon as life will be stopped. - * - * In case of restart new monitoring thread will be started. - */ -public class FileWatcherLifecycleAdapter extends LifecycleAdapter -{ - private final JobScheduler jobScheduler; - private final FileWatcher fileWatcher; - private final FileSystemEventWatcher eventWatcher; - private ThreadFactory fileWatchers; - private Thread watcher; - - public FileWatcherLifecycleAdapter( JobScheduler jobScheduler, FileWatcher fileWatcher ) - { - this.jobScheduler = jobScheduler; - this.fileWatcher = fileWatcher; - this.eventWatcher = new FileSystemEventWatcher(); - } - - @Override - public void init() - { - fileWatchers = jobScheduler.threadFactory( JobScheduler.Groups.fileWatch ); - } - - @Override - public void start() - { - watcher = fileWatchers.newThread( eventWatcher ); - watcher.start(); - } - - @Override - public void stop() throws Throwable - { - eventWatcher.stopWatching(); - if ( watcher != null ) - { - watcher.interrupt(); - watcher.join(); - watcher = null; - } - } - - @Override - public void shutdown() throws Throwable - { - fileWatcher.close(); - } - - private class FileSystemEventWatcher implements Runnable - { - @Override - public void run() - { - try - { - fileWatcher.startWatching(); - } - catch ( InterruptedException ignored ) - { - } - } - - void stopWatching() - { - fileWatcher.stopWatching(); - } - } -} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/FileWatcherLifecycleAdapterTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/DefaultFileSystemWatcherServiceTest.java similarity index 75% rename from community/kernel/src/test/java/org/neo4j/kernel/impl/util/FileWatcherLifecycleAdapterTest.java rename to community/kernel/src/test/java/org/neo4j/kernel/impl/util/DefaultFileSystemWatcherServiceTest.java index 29a1cb129ca1b..9992cc07a62cf 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/FileWatcherLifecycleAdapterTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/DefaultFileSystemWatcherServiceTest.java @@ -29,11 +29,11 @@ import org.neo4j.io.fs.watcher.FileWatcher; import org.neo4j.io.fs.watcher.SilentFileWatcher; import org.neo4j.kernel.impl.scheduler.CentralJobScheduler; -import org.neo4j.kernel.impl.util.watcher.FileWatcherLifecycleAdapter; +import org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService; import static org.mockito.Mockito.verify; -public class FileWatcherLifecycleAdapterTest +public class DefaultFileSystemWatcherServiceTest { private static CentralJobScheduler jobScheduler; @@ -56,9 +56,9 @@ public void startMonitoringWhenLifecycleStarting() throws Throwable { CountDownLatch latch = new CountDownLatch( 1 ); FileWatcher watcher = new TestFileWatcher( latch ); - FileWatcherLifecycleAdapter watcherAdapter = new FileWatcherLifecycleAdapter( jobScheduler, watcher ); - watcherAdapter.init(); - watcherAdapter.start(); + DefaultFileSystemWatcherService service = new DefaultFileSystemWatcherService( jobScheduler, watcher ); + service.init(); + service.start(); latch.await(); } @@ -66,10 +66,10 @@ public void startMonitoringWhenLifecycleStarting() throws Throwable @Test public void stopMonitoringWhenLifecycleStops() throws Throwable { - FileWatcherLifecycleAdapter watcherAdapter = new FileWatcherLifecycleAdapter( jobScheduler, fileWatcher ); - watcherAdapter.init(); - watcherAdapter.start(); - watcherAdapter.stop(); + DefaultFileSystemWatcherService service = new DefaultFileSystemWatcherService( jobScheduler, fileWatcher ); + service.init(); + service.start(); + service.stop(); verify( fileWatcher ).stopWatching(); } @@ -77,11 +77,11 @@ public void stopMonitoringWhenLifecycleStops() throws Throwable @Test public void closeFileWatcherOnShutdown() throws Throwable { - FileWatcherLifecycleAdapter watcherAdapter = new FileWatcherLifecycleAdapter( jobScheduler, fileWatcher ); - watcherAdapter.init(); - watcherAdapter.start(); - watcherAdapter.stop(); - watcherAdapter.shutdown(); + DefaultFileSystemWatcherService service = new DefaultFileSystemWatcherService( jobScheduler, fileWatcher ); + service.init(); + service.start(); + service.stop(); + service.shutdown(); verify( fileWatcher ).close(); }