PCEP sucessfull connection now implemented. Fixed minor bug in parsing.
[bgpcep.git] / framework / src / main / java / org / opendaylight / protocol / framework / ProtocolSessionInboundHandler.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.framework;
9
10 import io.netty.channel.ChannelHandlerContext;
11 import io.netty.channel.SimpleChannelInboundHandler;
12
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 final class ProtocolSessionInboundHandler extends SimpleChannelInboundHandler<ProtocolMessage> {
17
18         private final static Logger logger = LoggerFactory.getLogger(ProtocolSessionInboundHandler.class);
19
20         private final ProtocolSession session;
21
22         public ProtocolSessionInboundHandler(final ProtocolSession session) {
23                 this.session = session;
24         }
25
26         @Override
27         public void channelActive(final ChannelHandlerContext ctx) throws Exception {
28                 logger.debug("Channel active.");
29                 this.session.startSession();
30         }
31
32         @Override
33         public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
34                 logger.debug("Channel inactive.");
35                 this.session.endOfInput();
36         }
37
38         @Override
39         protected void channelRead0(final ChannelHandlerContext ctx, final ProtocolMessage msg) throws Exception {
40                 logger.debug("Message was received: {}", msg);
41                 this.session.handleMessage(msg);
42         }
43
44         public ProtocolSession getSession() {
45                 return this.session;
46         }
47 }