X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2FAbstractChannelInitializer.java;h=48a45845a4a6fe7f57a722bc5678d8fc8447b54d;hb=b925756421ea8565637d8575d8143dbf46db5a86;hp=aeee2fb04baea1c4bd1535d7b677fb1f50957d8e;hpb=3f83be2d86dfe0aea7d9f1392c75939ee678324e;p=controller.git diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java index aeee2fb04b..48a45845a4 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java @@ -10,24 +10,47 @@ package org.opendaylight.controller.netconf.util; import io.netty.channel.socket.SocketChannel; import io.netty.util.concurrent.Promise; + import org.opendaylight.controller.netconf.api.NetconfSession; import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory; -import org.opendaylight.controller.netconf.util.handler.NetconfHandlerFactory; -import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator; +import org.opendaylight.controller.netconf.util.handler.NetconfEOMAggregator; +import org.opendaylight.controller.netconf.util.handler.NetconfHelloMessageToXMLEncoder; +import org.opendaylight.controller.netconf.util.handler.NetconfXMLToHelloMessageDecoder; import org.opendaylight.controller.netconf.util.messages.FramingMechanism; -import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory; -public abstract class AbstractChannelInitializer { +public abstract class AbstractChannelInitializer { + + public static final String NETCONF_MESSAGE_DECODER = "netconfMessageDecoder"; + public static final String NETCONF_MESSAGE_AGGREGATOR = "aggregator"; + public static final String NETCONF_MESSAGE_ENCODER = "netconfMessageEncoder"; + public static final String NETCONF_MESSAGE_FRAME_ENCODER = "frameEncoder"; + public static final String NETCONF_SESSION_NEGOTIATOR = "negotiator"; + + public void initialize(SocketChannel ch, Promise promise) { + ch.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator()); + initializeMessageDecoder(ch); + ch.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM)); + initializeMessageEncoder(ch); + + initializeSessionNegotiator(ch, promise); + } + + protected void initializeMessageEncoder(SocketChannel ch) { + // Special encoding handler for hello message to include additional header if available, + // it is thrown away after successful negotiation + ch.pipeline().addLast(NETCONF_MESSAGE_ENCODER, new NetconfHelloMessageToXMLEncoder()); + } - public void initialize(SocketChannel ch, Promise promise){ - NetconfHandlerFactory handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory()); - ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM)); - ch.pipeline().addLast(handlerFactory.getDecoders()); - initializeAfterDecoder(ch, promise); - ch.pipeline().addLast("frameEncoder", FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM)); - ch.pipeline().addLast(handlerFactory.getEncoders()); + protected void initializeMessageDecoder(SocketChannel ch) { + // Special decoding handler for hello message to parse additional header if available, + // it is thrown away after successful negotiation + ch.pipeline().addLast(NETCONF_MESSAGE_DECODER, new NetconfXMLToHelloMessageDecoder()); } - protected abstract void initializeAfterDecoder(SocketChannel ch, Promise promise); + /** + * Insert session negotiator into the pipeline. It must be inserted after message decoder + * identified by {@link AbstractChannelInitializer#NETCONF_MESSAGE_DECODER}, (or any other custom decoder processor) + */ + protected abstract void initializeSessionNegotiator(SocketChannel ch, Promise promise); }