Do not require NetconfSessionImpl
[netconf.git] / netconf / callhome-protocol / src / main / java / org / opendaylight / netconf / callhome / protocol / CallHomeSessionContext.java
index f517d8a64c9aded40634f46dbc1467071dbe2a1a..4e7bf41b2b4f6b1df9cccb94d453bc16e3a92de4 100644 (file)
@@ -23,7 +23,6 @@ import org.apache.sshd.client.channel.ClientChannel;
 import org.apache.sshd.client.future.AuthFuture;
 import org.apache.sshd.client.future.OpenFuture;
 import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionImpl;
 import org.apache.sshd.common.future.SshFutureListener;
 import org.apache.sshd.common.session.Session;
 import org.checkerframework.checker.lock.qual.Holding;
@@ -41,7 +40,7 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
 
     private static final String NETCONF = "netconf";
 
-    private final ClientSessionImpl sshSession;
+    private final ClientSession sshSession;
     private final CallHomeAuthorization authorization;
     private final Factory factory;
 
@@ -55,10 +54,8 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
                            final SocketAddress remoteAddress, final Factory factory) {
         this.authorization = requireNonNull(authorization, "authorization");
         checkArgument(this.authorization.isServerAllowed(), "Server was not allowed.");
-        checkArgument(sshSession instanceof ClientSessionImpl,
-                "sshSession must implement ClientSessionImpl");
         this.factory = requireNonNull(factory, "factory");
-        this.sshSession = (ClientSessionImpl) sshSession;
+        this.sshSession = requireNonNull(sshSession, "sshSession");
         this.sshSession.setAttribute(SESSION_KEY, this);
         this.remoteAddress = (InetSocketAddress) this.sshSession.getIoSession().getRemoteAddress();
         this.serverKey = this.sshSession.getKex().getServerKey();
@@ -94,6 +91,12 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
         };
     }
 
+    @Override
+    public void terminate() {
+        sshSession.close(false);
+        removeSelf();
+    }
+
     private void channelOpenFailed(final Throwable throwable) {
         LOG.error("Unable to open netconf subsystem, disconnecting.", throwable);
         sshSession.close(false);