Bug 1029: Remove dead code: sal-schema-repository-api
[controller.git] / opendaylight / netconf / netconf-netty-util / src / main / java / org / opendaylight / controller / netconf / nettyutil / AbstractChannelInitializer.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
9 package org.opendaylight.controller.netconf.nettyutil;
10
11 import io.netty.channel.socket.SocketChannel;
12 import io.netty.util.concurrent.Promise;
13 import org.opendaylight.controller.netconf.api.NetconfSession;
14 import org.opendaylight.controller.netconf.nettyutil.handler.FramingMechanismHandlerFactory;
15 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEOMAggregator;
16 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfHelloMessageToXMLEncoder;
17 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder;
18 import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
19
20 public abstract class AbstractChannelInitializer<S extends NetconfSession> {
21
22     public static final String NETCONF_MESSAGE_DECODER = "netconfMessageDecoder";
23     public static final String NETCONF_MESSAGE_AGGREGATOR = "aggregator";
24     public static final String NETCONF_MESSAGE_ENCODER = "netconfMessageEncoder";
25     public static final String NETCONF_MESSAGE_FRAME_ENCODER = "frameEncoder";
26     public static final String NETCONF_SESSION_NEGOTIATOR = "negotiator";
27
28     public void initialize(SocketChannel ch, Promise<S> promise) {
29         ch.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator());
30         initializeMessageDecoder(ch);
31         ch.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
32         initializeMessageEncoder(ch);
33
34         initializeSessionNegotiator(ch, promise);
35     }
36
37     protected void initializeMessageEncoder(SocketChannel ch) {
38         // Special encoding handler for hello message to include additional header if available,
39         // it is thrown away after successful negotiation
40         ch.pipeline().addLast(NETCONF_MESSAGE_ENCODER, new NetconfHelloMessageToXMLEncoder());
41     }
42
43     protected void initializeMessageDecoder(SocketChannel ch) {
44         // Special decoding handler for hello message to parse additional header if available,
45         // it is thrown away after successful negotiation
46         ch.pipeline().addLast(NETCONF_MESSAGE_DECODER, new NetconfXMLToHelloMessageDecoder());
47     }
48
49     /**
50      * Insert session negotiator into the pipeline. It must be inserted after message decoder
51      * identified by {@link AbstractChannelInitializer#NETCONF_MESSAGE_DECODER}, (or any other custom decoder processor)
52      */
53     protected abstract void initializeSessionNegotiator(SocketChannel ch, Promise<S> promise);
54
55 }