OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / samples / simple-client / src / main / java / org / opendaylight / openflowjava / protocol / impl / clients / ScenarioHandler.java
index 88fd9b64bcf0904cb49f9cb030e2dc17c3f42ba6..cae78d5d0eb62001e07c6c0dd21f07df8a43303d 100644 (file)
@@ -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<byte[]> 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<ClientEvent> scenario, int freeze, long sleepBetweenTries){
+    public ScenarioHandler(Deque<ClientEvent> 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<ClientEvent> getScenario() {
         return scenario;
     }
 
     /**
+     * Sets the scenario.
+     *
      * @param scenario scenario filled with desired events
      */
     public void setScenario(Deque<ClientEvent> 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;