1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
2 package org.opendaylight.openflowjava.protocol.impl.clients;
4 import io.netty.buffer.ByteBuf;
5 import io.netty.channel.ChannelHandlerContext;
7 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
12 * Class representing sending message event
14 * @author michal.polkorab
16 public class SendEvent implements ClientEvent {
18 protected static final Logger LOGGER = LoggerFactory.getLogger(SendEvent.class);
19 protected byte[] msgToSend;
20 protected ChannelHandlerContext ctx;
23 * @param msgToSend message to be sent
25 public SendEvent(byte[] msgToSend) {
26 this.msgToSend = msgToSend;
30 public boolean eventExecuted() {
31 LOGGER.debug("sending message");
32 Thread thread = new Thread(new Runnable() {
35 LOGGER.debug("start of run");
36 ByteBuf buffer = ctx.alloc().buffer();
37 buffer.writeBytes(msgToSend);
38 ctx.writeAndFlush(buffer);
39 LOGGER.debug(">> " + ByteBufUtils.bytesToHexString(msgToSend));
45 } catch (InterruptedException e) {
46 LOGGER.error(e.getMessage(), e);
48 LOGGER.debug("message sent");
53 * @param ctx context which will be used for sending messages (SendEvents)
55 public void setCtx(ChannelHandlerContext ctx) {