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