2 * Copyright (c) 2013 Cisco Systems, Inc. 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
8 package org.opendaylight.protocol.framework;
10 import io.netty.channel.ChannelHandlerContext;
11 import io.netty.channel.SimpleChannelInboundHandler;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 public abstract class AbstractProtocolSession<M> extends SimpleChannelInboundHandler<Object> implements ProtocolSession<M> {
17 private static final Logger LOG = LoggerFactory.getLogger(AbstractProtocolSession.class);
20 * Handles incoming message (parsing, reacting if necessary).
22 * @param msg incoming message
24 protected abstract void handleMessage(final M msg);
27 * Called when reached the end of input stream while reading.
29 protected abstract void endOfInput();
32 * Called when the session is added to the pipeline.
34 protected abstract void sessionUp();
37 public final void channelInactive(final ChannelHandlerContext ctx) {
38 LOG.debug("Channel {} inactive.", ctx.channel());
43 @SuppressWarnings("unchecked")
44 protected final void channelRead0(final ChannelHandlerContext ctx, final Object msg) {
45 LOG.debug("Message was received: {}", msg);
46 handleMessage((M) msg);
50 public final void handlerAdded(final ChannelHandlerContext ctx) {