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;
13 import org.opendaylight.openflowjava.util.ByteBufUtils;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Class representing sending message event.
20 * @author michal.polkorab
22 public class SendEvent implements ClientEvent {
24 private static final Logger LOG = LoggerFactory.getLogger(SendEvent.class);
25 protected byte[] msgToSend;
26 protected ChannelHandlerContext ctx;
31 * @param msgToSend message to be sent
33 public SendEvent(byte[] msgToSend) {
34 this.msgToSend = new byte[msgToSend.length];
35 System.arraycopy(msgToSend, 0, this.msgToSend, 0, msgToSend.length);
39 public boolean eventExecuted() {
40 LOG.debug("sending message");
41 LOG.debug("start of run");
42 ByteBuf buffer = ctx.alloc().buffer();
43 buffer.writeBytes(msgToSend);
44 ctx.writeAndFlush(buffer);
46 if (LOG.isDebugEnabled()) {
47 LOG.debug("Message to send {}", ByteBufUtils.bytesToHexString(msgToSend));
48 LOG.debug("message sent");
54 * Sets the ChannelHandlerContext.
56 * @param ctx context which will be used for sending messages (SendEvents)
58 public void setCtx(ChannelHandlerContext ctx) {