2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.clients;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.channel.ChannelHandlerContext;
14 import org.opendaylight.openflowjava.util.ByteBufUtils;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Class representing sending message event
21 * @author michal.polkorab
23 public class SendEvent implements ClientEvent {
25 protected static final Logger LOGGER = LoggerFactory.getLogger(SendEvent.class);
26 protected byte[] msgToSend;
27 protected ChannelHandlerContext ctx;
30 * @param msgToSend message to be sent
32 public SendEvent(byte[] msgToSend) {
33 this.msgToSend = new byte[msgToSend.length];
34 for (int i = 0; i < msgToSend.length; i++) {
35 this.msgToSend[i] = msgToSend[i];
40 public boolean eventExecuted() {
41 LOGGER.debug("sending message");
42 LOGGER.debug("start of run");
43 ByteBuf buffer = ctx.alloc().buffer();
44 buffer.writeBytes(msgToSend);
45 ctx.writeAndFlush(buffer);
46 LOGGER.debug(">> " + ByteBufUtils.bytesToHexString(msgToSend));
47 LOGGER.debug("message sent");
52 * @param ctx context which will be used for sending messages (SendEvents)
54 public void setCtx(ChannelHandlerContext ctx) {