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 {
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}
*/
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;
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) {
}
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) {
}
/**
+ * Sets the ChannelHandlerContext.
+ *
* @param ctx context which will be used for sending messages (SendEvents)
*/
public void setCtx(ChannelHandlerContext ctx) {
}
/**
+ * Adds a message.
+ *
* @param message received message that is compared to expected message
*/
public void addOfMsg(byte[] message) {
}
/**
- * @return true is scenario is finished
+ * Returns true is scenario is finished.
*/
public boolean isScenarioFinished() {
return scenarioFinished;