Remove unnecessary casting
[netconf.git] / protocol / 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.messages.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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
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 LOG = LoggerFactory.getLogger(NetconfClientSession.class);
27     private final Collection<String> capabilities;
28
29     /**
30      * Construct a new session.
31      *
32      * @param sessionListener    Netconf client session listener.
33      * @param channel    Channel.
34      * @param sessionId    Session Id.
35      * @param capabilities    Set of advertised capabilities. Expected to be immutable.
36      */
37     @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "'this' passed to logger")
38     public NetconfClientSession(final NetconfClientSessionListener sessionListener, final Channel channel,
39                                 final SessionIdType sessionId, final Collection<String> capabilities) {
40         super(sessionListener, channel, sessionId);
41         this.capabilities = capabilities;
42         LOG.debug("Client Session {} created", this);
43     }
44
45     public Collection<String> getServerCapabilities() {
46         return capabilities;
47     }
48
49     @Override
50     protected NetconfClientSession thisInstance() {
51         return this;
52     }
53
54     @Override
55     protected void addExiHandlers(final ByteToMessageDecoder decoder,
56                                   final MessageToByteEncoder<NetconfMessage> encoder) {
57         // TODO used only in negotiator, client supports only auto start-exi
58         replaceMessageDecoder(decoder);
59         replaceMessageEncoder(encoder);
60     }
61
62     @Override
63     public void stopExiCommunication() {
64         // TODO never used, Netconf client does not support stop-exi
65         replaceMessageDecoder(new NetconfXMLToMessageDecoder());
66         replaceMessageEncoder(new NetconfMessageToXMLEncoder());
67     }
68 }