X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=simple-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fclients%2FSimpleClientHandler.java;h=01e114bf15aabbbd5281e1131a121c464af9b6c6;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=e9453b58437ada987f4763909aee3742c7881f81;hpb=5b05fc8e7dd2b61a076dfd1864a205b0995c7722;p=openflowjava.git diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java index e9453b58..01e114bf 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java @@ -1,68 +1,75 @@ -/* 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 io.netty.channel.ChannelInboundHandlerAdapter; - -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.util.concurrent.SettableFuture; - -/** - * - * @author michal.polkorab - */ -public class SimpleClientHandler extends ChannelInboundHandlerAdapter { - - protected static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientHandler.class); - private static final int LENGTH_INDEX_IN_HEADER = 2; - private SettableFuture isOnlineFuture; - protected ScenarioHandler scenarioHandler; - - /** - * @param isOnlineFuture future notifier of connected channel - * @param scenarioHandler handler of scenario events - */ - public SimpleClientHandler(SettableFuture isOnlineFuture, ScenarioHandler scenarioHandler) { - this.isOnlineFuture = isOnlineFuture; - this.scenarioHandler = scenarioHandler; - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - ByteBuf bb = (ByteBuf) msg; - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(bb)); - } - int length = bb.getUnsignedShort(LENGTH_INDEX_IN_HEADER); - LOGGER.info("SimpleClientHandler - start of read"); - byte[] message = new byte[length]; - bb.readBytes(message); - scenarioHandler.addOfMsg(message); - LOGGER.info("end of read"); - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - LOGGER.info("Client is active"); - if (isOnlineFuture != null) { - isOnlineFuture.set(true); - isOnlineFuture = null; - } - scenarioHandler.setCtx(ctx); - scenarioHandler.start(); - - } - - /** - * @param scenarioHandler handler of scenario events - */ - public void setScenario(ScenarioHandler scenarioHandler) { - this.scenarioHandler = scenarioHandler; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + + +package org.opendaylight.openflowjava.protocol.impl.clients; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.SettableFuture; + +/** + * + * @author michal.polkorab + */ +public class SimpleClientHandler extends ChannelInboundHandlerAdapter { + + protected static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientHandler.class); + private static final int LENGTH_INDEX_IN_HEADER = 2; + private SettableFuture isOnlineFuture; + protected ScenarioHandler scenarioHandler; + + /** + * @param isOnlineFuture future notifier of connected channel + * @param scenarioHandler handler of scenario events + */ + public SimpleClientHandler(SettableFuture isOnlineFuture, ScenarioHandler scenarioHandler) { + this.isOnlineFuture = isOnlineFuture; + this.scenarioHandler = scenarioHandler; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + ByteBuf bb = (ByteBuf) msg; + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(bb)); + } + int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER); + LOGGER.trace("SimpleClientHandler - start of read"); + byte[] message = new byte[length]; + bb.readBytes(message); + scenarioHandler.addOfMsg(message); + LOGGER.trace("end of read"); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + LOGGER.debug("Client is active"); + if (isOnlineFuture != null) { + isOnlineFuture.set(true); + isOnlineFuture = null; + } + scenarioHandler.setCtx(ctx); + scenarioHandler.start(); + + } + + /** + * @param scenarioHandler handler of scenario events + */ + public void setScenario(ScenarioHandler scenarioHandler) { + this.scenarioHandler = scenarioHandler; + } + +}