X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=samples%2Fsimple-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fclients%2FScenarioHandler.java;h=cae78d5d0eb62001e07c6c0dd21f07df8a43303d;hb=refs%2Fchanges%2F36%2F76236%2F27;hp=88fd9b64bcf0904cb49f9cb030e2dc17c3f42ba6;hpb=9688b3b10ee4113753705f0080b29cd30e61a85d;p=openflowplugin.git diff --git a/samples/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java b/samples/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java index 88fd9b64bc..cae78d5d0e 100644 --- a/samples/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java +++ b/samples/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java @@ -9,19 +9,17 @@ package org.opendaylight.openflowjava.protocol.impl.clients; import io.netty.channel.ChannelHandlerContext; - import java.util.Deque; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** + * Scenario handler thread. * * @author michal.polkorab - * */ public class ScenarioHandler extends Thread { @@ -30,12 +28,13 @@ public class ScenarioHandler extends Thread { private final BlockingQueue ofMsg; private ChannelHandlerContext ctx; private int eventNumber; - private boolean scenarioFinished = false; + private volatile boolean scenarioFinished = false; private int freeze = 2; private long sleepBetweenTries = 100L; private boolean finishedOK = true; /** + * Constructor. * * @param scenario {@link Deque} */ @@ -44,7 +43,7 @@ public class ScenarioHandler extends Thread { ofMsg = new LinkedBlockingQueue<>(); } - public ScenarioHandler(Deque scenario, int freeze, long sleepBetweenTries){ + public ScenarioHandler(Deque scenario, int freeze, long sleepBetweenTries) { this.scenario = scenario; ofMsg = new LinkedBlockingQueue<>(); this.sleepBetweenTries = sleepBetweenTries; @@ -63,7 +62,7 @@ public class ScenarioHandler extends Thread { WaitForMessageEvent event = (WaitForMessageEvent) peek; event.setHeaderReceived(ofMsg.poll(2000, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { - LOG.error(e.getMessage(), e); + LOG.error("Error {}", e); break; } } else if (peek instanceof SendEvent) { @@ -82,38 +81,40 @@ public class ScenarioHandler extends Thread { } if (freezeCounter > freeze) { LOG.warn("Scenario frozen: {}", freezeCounter); - LOG.warn("Scenario step not finished NOT OK!", freezeCounter); + LOG.warn("Scenario step not finished NOT OK! {}", freezeCounter); this.finishedOK = false; break; } try { sleep(sleepBetweenTries); } catch (InterruptedException e) { - LOG.error(e.getMessage(), e); + LOG.error("Error {}", e); } } LOG.debug("Scenario finished"); synchronized (this) { scenarioFinished = true; - this.notify(); + this.notifyAll(); } } /** - * @return true if scenario is done / empty + * Returns true if scenario is done / empty. */ public boolean isEmpty() { return scenario.isEmpty(); } /** - * @return scenario + * Returns the scenario. */ public Deque getScenario() { return scenario; } /** + * Sets the scenario. + * * @param scenario scenario filled with desired events */ public void setScenario(Deque scenario) { @@ -121,6 +122,8 @@ public class ScenarioHandler extends Thread { } /** + * Sets the ChannelHandlerContext. + * * @param ctx context which will be used for sending messages (SendEvents) */ public void setCtx(ChannelHandlerContext ctx) { @@ -128,6 +131,8 @@ public class ScenarioHandler extends Thread { } /** + * Adds a message. + * * @param message received message that is compared to expected message */ public void addOfMsg(byte[] message) { @@ -135,7 +140,7 @@ public class ScenarioHandler extends Thread { } /** - * @return true is scenario is finished + * Returns true is scenario is finished. */ public boolean isScenarioFinished() { return scenarioFinished;