Move running the query into its own method.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 27 Mar 2014 16:12:23 +0000 (17:12 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 27 Mar 2014 16:12:23 +0000 (17:12 +0100)
src/main/java/net/pterodactylus/rhynodge/engine/Engine.java

index 91c5df9..bbca3af 100644 (file)
@@ -132,23 +132,7 @@ public class Engine extends AbstractExecutionThreadService {
                                continue;
                        }
 
-                       /* run reaction. */
-                       logger.info(format("Running Query for %s...", reactionName));
-                       Query query = nextReaction.get().getReaction().query();
-                       net.pterodactylus.rhynodge.State state;
-                       try {
-                               logger.debug("Querying system...");
-                               state = query.state();
-                               if (state == null) {
-                                       state = FailedState.INSTANCE;
-                               }
-                               logger.debug("System queried.");
-                       } catch (Throwable t1) {
-                               logger.warn("Querying system failed!", t1);
-                               state = new AbstractState(t1) {
-                                       /* no further state. */
-                               };
-                       }
+                       net.pterodactylus.rhynodge.State state = runReaction(nextReaction, reactionName);
                        logger.debug(format("State is %s.", state));
 
                        /* convert states. */
@@ -187,6 +171,25 @@ public class Engine extends AbstractExecutionThreadService {
                }
        }
 
+       private net.pterodactylus.rhynodge.State runReaction(Optional<NextReaction> nextReaction, String reactionName) {
+               logger.info(format("Running Query for %s...", reactionName));
+               Query query = nextReaction.get().getReaction().query();
+               net.pterodactylus.rhynodge.State state;
+               try {
+                       logger.debug("Querying system...");
+                       state = query.state();
+                       if (state == null) {
+                               state = FailedState.INSTANCE;
+                       }
+                       logger.debug("System queried.");
+               } catch (Throwable t1) {
+                       logger.warn("Querying system failed!", t1);
+                       state = new AbstractState(t1) {
+                       };
+               }
+               return state;
+       }
+
        private void waitForNextReactionToStart(Optional<NextReaction> nextReaction, long waitTime) {
                synchronized (reactions) {
                        try {