Merge "add basic lib - plugin communication"
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / openflow / lib / clients / SimpleClientHandler.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 \r
3 package org.openflow.lib.clients;\r
4 \r
5 import io.netty.buffer.ByteBuf;\r
6 import io.netty.channel.ChannelHandlerContext;\r
7 import io.netty.channel.ChannelInboundHandlerAdapter;\r
8 \r
9 import org.openflow.util.ByteBufUtils;\r
10 import org.slf4j.Logger;\r
11 import org.slf4j.LoggerFactory;\r
12 \r
13 import com.google.common.util.concurrent.SettableFuture;\r
14 \r
15 /**\r
16  *\r
17  * @author michal.polkorab\r
18  */\r
19 public class SimpleClientHandler extends ChannelInboundHandlerAdapter {\r
20 \r
21     private static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientHandler.class);\r
22     private SettableFuture<Boolean> sf;\r
23 \r
24     /**\r
25      * @param sf future notifier of connected channel\r
26      */\r
27     public SimpleClientHandler(SettableFuture<Boolean> sf) {\r
28         this.sf = sf;\r
29     }\r
30     \r
31     @Override\r
32     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\r
33         LOGGER.info("SimpleClientHandler - start of read");\r
34         if (sf != null) {\r
35             sf.set(true);\r
36             sf = null;\r
37         }\r
38         ByteBuf bb = (ByteBuf) msg;\r
39         if (LOGGER.isDebugEnabled()) {\r
40             LOGGER.debug(ByteBufUtils.byteBufToHexString(bb));\r
41         }\r
42         LOGGER.info(msg.toString());\r
43         LOGGER.info("SimpleClientHandler - end of read");\r
44     }\r
45     \r
46 /* (non-Javadoc)\r
47      * @see io.netty.channel.ChannelInboundHandlerAdapter#channelActive(io.netty.channel.ChannelHandlerContext)\r
48      */\r
49     @Override\r
50     public void channelActive(ChannelHandlerContext ctx) throws Exception {\r
51         System.out.println("CLIENT IS ACTIVE");\r
52         //super.channelActive(ctx);\r
53     }\r
54     \r
55     \r
56 }\r