1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.core;
\r
4 import io.netty.channel.ChannelHandlerContext;
\r
5 import io.netty.channel.ChannelInboundHandlerAdapter;
\r
7 import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterImpl;
\r
8 import org.opendaylight.openflowjava.protocol.impl.connection.MessageConsumer;
\r
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder;
\r
10 import org.opendaylight.yangtools.yang.binding.DataObject;
\r
11 import org.slf4j.Logger;
\r
12 import org.slf4j.LoggerFactory;
\r
15 * Holds reference to {@link ConnectionAdapterImpl} and passes messages for further processing.
\r
16 * Also informs on switch disconnection.
\r
17 * @author michal.polkorab
\r
19 public class DelegatingInboundHandler extends ChannelInboundHandlerAdapter {
\r
21 private static final Logger LOGGER = LoggerFactory.getLogger(DelegatingInboundHandler.class);
\r
23 protected MessageConsumer consumer;
\r
24 private boolean inactiveMessageSent = false;
\r
27 * Constructs class + creates and sets MessageConsumer
\r
28 * @param connectionAdapter reference for adapter communicating with upper layers outside library
\r
30 public DelegatingInboundHandler(MessageConsumer connectionAdapter) {
\r
31 LOGGER.debug("Creating DelegatingInboundHandler");
\r
32 consumer = connectionAdapter;
\r
36 public void channelRead(ChannelHandlerContext ctx, final Object msg)
\r
38 LOGGER.debug("Reading");
\r
39 consumer.consume((DataObject) msg);
\r
43 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
\r
44 LOGGER.info("Channel inactive");
\r
45 if (!inactiveMessageSent) {
\r
46 DisconnectEventBuilder builder = new DisconnectEventBuilder();
\r
47 builder.setInfo("Channel inactive");
\r
48 consumer.consume(builder.build());
\r
49 inactiveMessageSent = true;
\r
54 public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
\r
55 LOGGER.info("Channel unregistered");
\r
56 if (!inactiveMessageSent) {
\r
57 DisconnectEventBuilder builder = new DisconnectEventBuilder();
\r
58 builder.setInfo("Channel unregistered");
\r
59 consumer.consume(builder.build());
\r
60 inactiveMessageSent = true;
\r