Merge changes I34a6851c,I046e6272,I169f6b40,Iec24bf37,I89933b0c
[openflowjava.git] / simple-client / src / main / java / org / opendaylight / openflowjava / protocol / impl / clients / ScenarioHandler.java
index 44abb36d0ab1a3595966ff1ed0bb144e8c84c884..88fd9b64bcf0904cb49f9cb030e2dc17c3f42ba6 100644 (file)
@@ -27,20 +27,30 @@ public class ScenarioHandler extends Thread {
 
     private static final Logger LOG = LoggerFactory.getLogger(ScenarioHandler.class);
     private Deque<ClientEvent> scenario;
-    private BlockingQueue<byte[]> ofMsg;
+    private final BlockingQueue<byte[]> ofMsg;
     private ChannelHandlerContext ctx;
     private int eventNumber;
     private boolean scenarioFinished = false;
+    private int freeze = 2;
+    private long sleepBetweenTries = 100L;
+    private boolean finishedOK = true;
 
     /**
      *
-     * @param scenario
+     * @param scenario {@link Deque}
      */
     public ScenarioHandler(Deque<ClientEvent> scenario) {
         this.scenario = scenario;
         ofMsg = new LinkedBlockingQueue<>();
     }
 
+    public ScenarioHandler(Deque<ClientEvent> scenario, int freeze, long sleepBetweenTries){
+        this.scenario = scenario;
+        ofMsg = new LinkedBlockingQueue<>();
+        this.sleepBetweenTries = sleepBetweenTries;
+        this.freeze = freeze;
+    }
+
     @Override
     public void run() {
         int freezeCounter = 0;
@@ -62,18 +72,22 @@ public class ScenarioHandler extends Thread {
                 event.setCtx(ctx);
             }
             if (peek.eventExecuted()) {
+                LOG.info("Scenario step finished OK, moving to next step.");
                 scenario.removeLast();
                 eventNumber++;
                 freezeCounter = 0;
+                finishedOK = true;
             } else {
                 freezeCounter++;
             }
-            if (freezeCounter > 2) {
+            if (freezeCounter > freeze) {
                 LOG.warn("Scenario frozen: {}", freezeCounter);
+                LOG.warn("Scenario step not finished NOT OK!", freezeCounter);
+                this.finishedOK = false;
                 break;
             }
             try {
-                sleep(100);
+                sleep(sleepBetweenTries);
             } catch (InterruptedException e) {
                 LOG.error(e.getMessage(), e);
             }
@@ -126,4 +140,8 @@ public class ScenarioHandler extends Thread {
     public boolean isScenarioFinished() {
         return scenarioFinished;
     }
+
+    public boolean isFinishedOK() {
+        return finishedOK;
+    }
 }