Integration test, SimpleClient bundle
[openflowjava.git] / simple-client / src / main / java / org / opendaylight / openflowjava / protocol / impl / clients / SendEvent.java
diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java
new file mode 100644 (file)
index 0000000..57445bd
--- /dev/null
@@ -0,0 +1,49 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
+package org.opendaylight.openflowjava.protocol.impl.clients;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class SendEvent implements ClientEvent {
+
+    protected static final Logger LOGGER = LoggerFactory.getLogger(SendEvent.class);
+    protected byte[] msgToSend;
+    protected ChannelHandlerContext ctx;
+
+    public SendEvent(byte[] msgToSend) {
+        this.msgToSend = msgToSend;
+    }
+
+    @Override
+    public boolean eventExecuted() {
+        LOGGER.debug("sending message");
+        Thread thread = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                LOGGER.debug("start of run");
+                ByteBuf buffer = ctx.alloc().buffer();
+                buffer.writeBytes(msgToSend);
+                ctx.writeAndFlush(buffer);
+                LOGGER.debug(">> " + ByteBufUtils.bytesToHexString(msgToSend));
+            }
+        });
+        thread.start();
+        try {
+            thread.join();
+        } catch (InterruptedException e) {
+            LOGGER.error(e.getMessage(), e);
+        }
+        LOGGER.debug("message sent");
+        return true;
+    }
+
+    public void setCtx(ChannelHandlerContext ctx) {
+        this.ctx = ctx;
+    }
+
+}