Merge "BUG-1568 Ssh Handler for netconf client Mina implementation"
[controller.git] / opendaylight / netconf / netconf-netty-util / src / main / java / org / opendaylight / controller / netconf / nettyutil / handler / ssh / client / SshSession.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.nettyutil.handler.ssh.client;
10
11 import ch.ethz.ssh2.Session;
12 import ch.ethz.ssh2.channel.Channel;
13 import java.io.Closeable;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.OutputStream;
17
18 /**
19  * Wrapper class for proprietary SSH sessions implementations
20  */
21 class SshSession implements Closeable {
22     private final Session session;
23
24     public SshSession(final Session session) {
25         this.session = session;
26     }
27
28     public void startSubSystem(final String name) throws IOException {
29         session.startSubSystem(name);
30     }
31
32     public InputStream getStdout() {
33         return session.getStdout();
34     }
35
36     // FIXME according to http://www.ganymed.ethz.ch/ssh2/FAQ.html#blocking you should read data from both stdout and stderr to prevent window filling up (since stdout and stderr share a window)
37     // FIXME stdErr is not used anywhere
38     public InputStream getStderr() {
39         return session.getStderr();
40     }
41
42     public OutputStream getStdin() {
43         return session.getStdin();
44     }
45
46     @Override
47     public void close() {
48         if (session.getState() == Channel.STATE_OPEN || session.getState() == Channel.STATE_OPENING) {
49             session.close();
50         }
51     }
52 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.