aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2018-11-12 16:52:07 -0500
committerMatt Kohls <mattkohls13@gmail.com>2018-11-12 16:52:07 -0500
commit2265b16d8b3bcf74a1681838cefc8e81ea6e9eab (patch)
tree8458908288b0163a4b5c8f614038220c6653a1dc
parentede0d1d78371f7980b98beaf94d2dd642077a762 (diff)
downloadSoundChan-2265b16d8b3bcf74a1681838cefc8e81ea6e9eab.tar.gz
SoundChan-2265b16d8b3bcf74a1681838cefc8e81ea6e9eab.tar.bz2
SoundChan-2265b16d8b3bcf74a1681838cefc8e81ea6e9eab.zip
Breaking out creation of MediaWatcher tasks to separate function
-rw-r--r--src/main/java/soundchan/BotListener/BotListener.java22
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();
+ }
+
}