Merge "Bug 8153: Enforce check-style rules for netconf - client."
[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 io.netty.channel.Channel;
12 import io.netty.handler.codec.ByteToMessageDecoder;
13 import io.netty.handler.codec.MessageToByteEncoder;
14 import java.util.Collection;
15 import org.opendaylight.netconf.api.NetconfMessage;
16 import org.opendaylight.netconf.nettyutil.AbstractNetconfSession;
17 import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder;
18 import org.opendaylight.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    Netconf client session listener.
31      * @param channel    Channel.
32      * @param sessionId    Session Id.
33      * @param capabilities    Set of advertised capabilities. Expected to be immutable.
34      */
35     public NetconfClientSession(final NetconfClientSessionListener sessionListener, final Channel channel,
36                                 final long sessionId, final Collection<String> capabilities) {
37         super(sessionListener, channel, sessionId);
38         this.capabilities = capabilities;
39         LOG.debug("Client Session {} created", this);
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 ByteToMessageDecoder decoder,
53                                   final MessageToByteEncoder<NetconfMessage> encoder) {
54         // TODO used only in negotiator, client supports only auto start-exi
55         replaceMessageDecoder(decoder);
56         replaceMessageEncoder(encoder);
57     }
58
59     @Override
60     public void stopExiCommunication() {
61         // TODO never used, Netconf client does not support stop-exi
62         replaceMessageDecoder(new NetconfXMLToMessageDecoder());
63         replaceMessageEncoder(new NetconfMessageToXMLEncoder());
64     }
65 }