From 2265b16d8b3bcf74a1681838cefc8e81ea6e9eab Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Mon, 12 Nov 2018 16:52:07 -0500 Subject: Breaking out creation of MediaWatcher tasks to separate function --- .../java/soundchan/BotListener/BotListener.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index 799b547..c7740c0 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -69,20 +69,14 @@ public class BotListener extends ListenerAdapter{ localManager = new LocalAudioManager(localFilePath, userAudioPath); if(settingEnableCheck(properties.getProperty("watchUserSoundFile"))) { - ExecutorService executorService = Executors.newSingleThreadExecutor(); - UserSoundWatcher userSoundWatcher = new UserSoundWatcher(localManager, userAudioPath); - otherTasks.put("watchUserSoundFile", executorService.submit(userSoundWatcher)); - executorService.shutdown(); + addWatcherTask(userAudioPath, "watchUserSoundFile"); } } else localManager = new LocalAudioManager(localFilePath); if(settingEnableCheck(properties.getProperty("watchLocalFilePath"))) { - ExecutorService executorService = Executors.newSingleThreadExecutor(); - DirectoryWatcher directoryWatcher = new DirectoryWatcher(localManager, localFilePath); - otherTasks.put("watchLocalFilePath", executorService.submit(directoryWatcher)); - executorService.shutdown(); + addWatcherTask(localFilePath, "watchLocalFilePath"); } } @@ -395,4 +389,16 @@ public class BotListener extends ListenerAdapter{ return false; } + /** + * Adds a new MediaWatcher to the list of running tasks + * @param filepath Path to either directory or file + * @param taskName Thing to name task as + */ + private void addWatcherTask(String filepath, String taskName) { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + MediaWatcher directoryWatcher = new MediaWatcher(localManager, filepath); + otherTasks.put(taskName, executorService.submit(directoryWatcher)); + executorService.shutdown(); + } + } -- cgit v1.2.3