Move waiting for next reaction to start into its own method.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 27 Mar 2014 16:09:41 +0000 (17:09 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 27 Mar 2014 16:09:41 +0000 (17:09 +0100)
src/main/java/net/pterodactylus/rhynodge/engine/Engine.java

index 2ff7666..bb42289 100644 (file)
@@ -126,14 +126,7 @@ public class Engine extends AbstractExecutionThreadService {
                        long waitTime = nextReaction.get().getNextTime() - System.currentTimeMillis();
                        logger.debug(format("Time to wait for next Reaction: %d millseconds.", waitTime));
                        if (waitTime > 0) {
-                               synchronized (reactions) {
-                                       try {
-                                               logger.info(format("Waiting until %tc.", nextReaction.get().getNextTime()));
-                                               reactions.wait(waitTime);
-                                       } catch (InterruptedException ie1) {
-                                               /* we’re looping! */
-                                       }
-                               }
+                               waitForNextReactionToStart(nextReaction, waitTime);
 
                                /* re-start loop to check for new reactions. */
                                continue;
@@ -196,6 +189,17 @@ public class Engine extends AbstractExecutionThreadService {
                }
        }
 
+       private void waitForNextReactionToStart(Optional<NextReaction> nextReaction, long waitTime) {
+               synchronized (reactions) {
+                       try {
+                               logger.info(format("Waiting until %tc.", nextReaction.get().getNextTime()));
+                               reactions.wait(waitTime);
+                       } catch (InterruptedException ie1) {
+                               /* we’re looping! */
+                       }
+               }
+       }
+
        private Optional<NextReaction> getNextReaction() {
                while (isRunning()) {
                        synchronized (reactions) {