Merge "Converted Inventory Manager to use Transaction Chaining"
[controller.git] / opendaylight / netconf / netconf-client / src / main / java / org / opendaylight / controller / netconf / client / NetconfClientSession.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.client;
10
11 import io.netty.channel.Channel;
12
13 import java.util.Collection;
14
15 import org.opendaylight.controller.netconf.nettyutil.AbstractNetconfSession;
16 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXICodec;
17 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXIToMessageDecoder;
18 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfMessageToEXIEncoder;
19 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfMessageToXMLEncoder;
20 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToMessageDecoder;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class NetconfClientSession extends AbstractNetconfSession<NetconfClientSession, NetconfClientSessionListener> {
25
26     private static final Logger logger = LoggerFactory.getLogger(NetconfClientSession.class);
27     private final Collection<String> capabilities;
28
29     /**
30      * Construct a new session.
31      *
32      * @param sessionListener
33      * @param channel
34      * @param sessionId
35      * @param capabilities set of advertised capabilities. Expected to be immutable.
36      */
37     public NetconfClientSession(final NetconfClientSessionListener sessionListener, final Channel channel, final long sessionId,
38             final Collection<String> capabilities) {
39         super(sessionListener, channel, sessionId);
40         this.capabilities = capabilities;
41         logger.debug("Client Session {} created", toString());
42     }
43
44     public Collection<String> getServerCapabilities() {
45         return capabilities;
46     }
47
48     @Override
49     protected NetconfClientSession thisInstance() {
50         return this;
51     }
52
53     @Override
54     protected void addExiHandlers(final NetconfEXICodec exiCodec) {
55         // TODO used only in negotiator, client supports only auto start-exi
56         replaceMessageDecoder(new NetconfEXIToMessageDecoder(exiCodec));
57         replaceMessageEncoder(new NetconfMessageToEXIEncoder(exiCodec));
58     }
59
60     @Override
61     public void stopExiCommunication() {
62         // TODO never used, Netconf client does not support stop-exi
63         replaceMessageDecoder(new NetconfXMLToMessageDecoder());
64         replaceMessageEncoder(new NetconfMessageToXMLEncoder());
65     }
66 }