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 final 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 System.arraycopy(msgToSend, 0, this.msgToSend, 0, msgToSend.length);
38 public boolean eventExecuted() {
39 LOGGER.debug("sending message");
40 LOGGER.debug("start of run");
41 ByteBuf buffer = ctx.alloc().buffer();
42 buffer.writeBytes(msgToSend);
43 ctx.writeAndFlush(buffer);
45 if (LOGGER.isDebugEnabled()) {
46 LOGGER.debug(">> {}", ByteBufUtils.bytesToHexString(msgToSend));
47 LOGGER.debug("message sent");
53 * @param ctx context which will be used for sending messages (SendEvents)
55 public void setCtx(ChannelHandlerContext ctx) {