Bug 2245 - Synchronized classes and data structures replaced by unsynchronized. 96/14496/3
authorMartin Uhlir <martin.uhlir@pantheon.sk>
Mon, 26 Jan 2015 14:18:17 +0000 (15:18 +0100)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Wed, 28 Jan 2015 15:58:33 +0000 (15:58 +0000)
Change-Id: Ie5aeeb28c74757d1a8bac21ce611a403a0fb6f57
Signed-off-by: Martin Uhlir <martin.uhlir@pantheon.sk>
openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java
simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java
simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java
util/src/main/java/org/opendaylight/openflowjava/util/ByteBufUtils.java

index 411bc5ea2c5cd23465fd68a2ca42bc65ea38bb6a..6464a62fbdc6686b337b24666e329cf49c1576b9 100644 (file)
@@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.it.integration;
 
 import java.net.InetAddress;
 import java.util.ArrayList;
+import java.util.Deque;
 import java.util.List;
-import java.util.Stack;
+
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
@@ -107,7 +108,7 @@ public class IntegrationTest {
     public void testHandshake() throws Exception {
         setUp(TransportProtocol.TCP);
         int amountOfCLients = 1;
-        Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+        Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
         ScenarioHandler handler = new ScenarioHandler(scenario);
         List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP);
         OFClient firstClient = clients.get(0);
@@ -125,7 +126,7 @@ public class IntegrationTest {
     public void testTlsHandshake() throws Exception {
         setUp(TransportProtocol.TLS);
         int amountOfCLients = 1;
-        Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+        Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
         ScenarioHandler handler = new ScenarioHandler(scenario);
         List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS);
         OFClient firstClient = clients.get(0);
@@ -143,11 +144,11 @@ public class IntegrationTest {
     public void testHandshakeAndEcho() throws Exception {
         setUp(TransportProtocol.TCP);
         int amountOfCLients = 1;
-        Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
-        scenario.add(0, new SleepEvent(1000));
-        scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
-        scenario.add(0, new SleepEvent(1000));
-        scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
+        Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+        scenario.addFirst(new SleepEvent(1000));
+        scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
+        scenario.addFirst(new SleepEvent(1000));
+        scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
         ScenarioHandler handler = new ScenarioHandler(scenario);
         List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP);
         OFClient firstClient = clients.get(0);
@@ -164,11 +165,11 @@ public class IntegrationTest {
     public void testTlsHandshakeAndEcho() throws Exception {
         setUp(TransportProtocol.TLS);
         int amountOfCLients = 1;
-        Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
-        scenario.add(0, new SleepEvent(1000));
-        scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
-        scenario.add(0, new SleepEvent(1000));
-        scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
+        Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+        scenario.addFirst(new SleepEvent(1000));
+        scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
+        scenario.addFirst(new SleepEvent(1000));
+        scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
         ScenarioHandler handler = new ScenarioHandler(scenario);
         List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS);
         OFClient firstClient = clients.get(0);
@@ -185,11 +186,11 @@ public class IntegrationTest {
     public void testUdpHandshakeAndEcho() throws Exception {
         setUp(TransportProtocol.UDP);
         int amountOfCLients = 1;
-        Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
-        scenario.add(0, new SleepEvent(1000));
-        scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
-        scenario.add(0, new SleepEvent(1000));
-        scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
+        Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+        scenario.addFirst(new SleepEvent(1000));
+        scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
+        scenario.addFirst(new SleepEvent(1000));
+        scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
         ScenarioHandler handler = new ScenarioHandler(scenario);
         List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.UDP);
         OFClient firstClient = clients.get(0);
index a6afb6a503a9dcce21aba53d2f7077f8f4122f53..f0e5b9cffbf958f7de182bcaf137beee038bbc39 100644 (file)
@@ -8,7 +8,8 @@
 
 package org.opendaylight.openflowjava.protocol.impl.clients;
 
-import java.util.Stack;
+import java.util.ArrayDeque;
+import java.util.Deque;
 
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 
@@ -33,12 +34,12 @@ public final class ScenarioFactory {
      * </ol>
      * @return stack filled with Handshake messages
      */
-    public static Stack<ClientEvent> createHandshakeScenario() {
-        Stack<ClientEvent> stack = new Stack<>();
-        stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
-        stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
-        stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
-        stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
+    public static Deque<ClientEvent> createHandshakeScenario() {
+        Deque<ClientEvent> stack = new ArrayDeque<>();
+        stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
+        stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
+        stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
+        stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
                 + "00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03")));
         return stack;
     }
@@ -54,14 +55,14 @@ public final class ScenarioFactory {
      * @param auxiliaryId auxiliaryId wanted in featuresReply message
      * @return stack filled with Handshake messages (featuresReply with auxiliaryId set)
      */
-    public static Stack<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
-        Stack<ClientEvent> stack = new Stack<>();
-        stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
-        stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
-        stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
-        stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
+    public static Deque<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
+        Deque<ClientEvent> queue = new ArrayDeque<>();
+        queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
+        queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
+        queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
+        queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
                 + "00 01 02 03 04 05 06 07 00 01 02 03 01 " + String.format("%02x ", auxiliaryId) + " 00 00 00 01 02 03 00 01 02 03")));
-        return stack;
+        return queue;
     }
 
 }
index 075c65681930f2d20f76601783b5e51ceaadf0fb..b7cf3de0b44051b00521ac3fa3d92694bed1f4fb 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.openflowjava.protocol.impl.clients;
 
 import io.netty.channel.ChannelHandlerContext;
 
-import java.util.Stack;
+import java.util.Deque;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
@@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
 public class ScenarioHandler extends Thread {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ScenarioHandler.class);
-    private Stack<ClientEvent> scenario;
+    private Deque<ClientEvent> scenario;
     private BlockingQueue<byte[]> ofMsg;
     private ChannelHandlerContext ctx;
     private int eventNumber;
@@ -36,7 +36,7 @@ public class ScenarioHandler extends Thread {
      *
      * @param scenario
      */
-    public ScenarioHandler(Stack<ClientEvent> scenario) {
+    public ScenarioHandler(Deque<ClientEvent> scenario) {
         this.scenario = scenario;
         ofMsg = new LinkedBlockingQueue<>();
     }
@@ -46,7 +46,7 @@ public class ScenarioHandler extends Thread {
         int freezeCounter = 0;
         while (!scenario.isEmpty()) {
             LOGGER.debug("Running event #" + eventNumber);
-            ClientEvent peek = scenario.peek();
+            ClientEvent peek = scenario.peekLast();
             if (peek instanceof WaitForMessageEvent) {
                 LOGGER.debug("WaitForMessageEvent");
                 try {
@@ -62,7 +62,7 @@ public class ScenarioHandler extends Thread {
                 event.setCtx(ctx);
             }
             if (peek.eventExecuted()) {
-                scenario.pop();
+                scenario.removeLast();
                 eventNumber++;
                 freezeCounter = 0;
             } else {
@@ -95,14 +95,14 @@ public class ScenarioHandler extends Thread {
     /**
      * @return scenario
      */
-    public Stack<ClientEvent> getScenario() {
+    public Deque<ClientEvent> getScenario() {
         return scenario;
     }
 
     /**
      * @param scenario scenario filled with desired events
      */
-    public void setScenario(Stack<ClientEvent> scenario) {
+    public void setScenario(Deque<ClientEvent> scenario) {
         this.scenario = scenario;
     }
 
index 4ac43f65322a7b05a7e2291d22571015fe043682..c4446f28d8ae605897420dcf9131ac13662271ba 100644 (file)
@@ -45,7 +45,7 @@ public abstract class ByteBufUtils {
      * @return String
      */
     public static String byteBufToHexString(final ByteBuf bb) {
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         for (int i = bb.readerIndex(); i < (bb.readerIndex() + bb.readableBytes()); i++) {
             sb.append(String.format(" %02x", bb.getUnsignedByte(i)));
         }
@@ -204,7 +204,7 @@ public abstract class ByteBufUtils {
      * @return String
      */
     public static String bytesToHexString(final byte[] array) {
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         for (byte element : array) {
             sb.append(String.format(" %02x", element));
         }