From 5a9b34156a69a0293235aaa764a3cf86cfb20f0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 27 Mar 2014 17:12:23 +0100 Subject: [PATCH] Move running the query into its own method. --- .../net/pterodactylus/rhynodge/engine/Engine.java | 37 ++++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java b/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java index 91c5df9..bbca3af 100644 --- a/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java +++ b/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java @@ -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, 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, long waitTime) { synchronized (reactions) { try { -- 2.7.4