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
9 package org.opendaylight.controller.netconf.util;
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.util.handler.FramingMechanismHandlerFactory;
15 import org.opendaylight.controller.netconf.util.handler.NetconfHandlerFactory;
16 import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator;
17 import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
18 import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
20 public abstract class AbstractChannelInitializer {
22 public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise){
23 NetconfHandlerFactory handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory());
24 ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM));
25 ch.pipeline().addLast(handlerFactory.getDecoders());
26 initializeAfterDecoder(ch, promise);
27 ch.pipeline().addLast("frameEncoder", FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
28 ch.pipeline().addLast(handlerFactory.getEncoders());
31 protected abstract void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise);