diff options
Diffstat (limited to 'src/main/java/soundchan')
-rw-r--r-- | src/main/java/soundchan/BotListener/BotListener.java | 22 |
1 files changed, 14 insertions, 8 deletions
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(); + } + } |