Bump upstreams to SNAPSHOTs
[netconf.git] / netconf / netconf-client / src / main / java / org / opendaylight / 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.netconf.client;
10
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import io.netty.channel.Channel;
13 import io.netty.handler.codec.ByteToMessageDecoder;
14 import io.netty.handler.codec.MessageToByteEncoder;
15 import java.util.Collection;
16 import org.opendaylight.netconf.api.NetconfMessage;
17 import org.opendaylight.netconf.nettyutil.AbstractNetconfSession;
18 import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder;
19 import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class NetconfClientSession extends AbstractNetconfSession<NetconfClientSession, NetconfClientSessionListener> {
24
25     private static final Logger LOG = LoggerFactory.getLogger(NetconfClientSession.class);
26     private final Collection<String> capabilities;
27
28     /**
29      * Construct a new session.
30      *
31      * @param sessionListener    Netconf client session listener.
32      * @param channel    Channel.
33      * @param sessionId    Session Id.
34      * @param capabilities    Set of advertised capabilities. Expected to be immutable.
35      */
36     @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "'this' passed to logger")
37     public NetconfClientSession(final NetconfClientSessionListener sessionListener, final Channel channel,
38                                 final long sessionId, final Collection<String> capabilities) {
39         super(sessionListener, channel, sessionId);
40         this.capabilities = capabilities;
41         LOG.debug("Client Session {} created", this);
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 ByteToMessageDecoder decoder,
55                                   final MessageToByteEncoder<NetconfMessage> encoder) {
56         // TODO used only in negotiator, client supports only auto start-exi
57         replaceMessageDecoder(decoder);
58         replaceMessageEncoder(encoder);
59     }
60
61     @Override
62     public void stopExiCommunication() {
63         // TODO never used, Netconf client does not support stop-exi
64         replaceMessageDecoder(new NetconfXMLToMessageDecoder());
65         replaceMessageEncoder(new NetconfMessageToXMLEncoder());
66     }
67 }