Subversion Repositories Programming Utils

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
86 rm5248 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
package org.apache.sshd.server;
20
 
21
import java.io.IOException;
22
import java.io.InputStream;
23
import java.io.OutputStream;
24
 
25
/**
26
 * Represents a command, shell or subsystem that can be used to send command.
27
 *
28
 * This command have direct streams, meaning those streams will be provided by the ssh server
29
 * for the shell to use directy. This interface is suitable for implementing commands in java,
30
 * rather than using external processes.  For wrapping such processes or using inverted streams,
31
 * see {@link org.apache.sshd.server.shell.InvertedShellWrapper}.
32
 */
33
public interface Command {
34
 
35
    /**
36
     * Set the input stream that can be used by the shell to read input.
37
     * @param in
38
     */
39
    void setInputStream(InputStream in);
40
 
41
    /**
42
     * Set the output stream that can be used by the shell to write its output.
43
     * @param out
44
     */
45
    void setOutputStream(OutputStream out);
46
 
47
    /**
48
     * Set the error stream that can be used by the shell to write its errors.
49
     * @param err
50
     */
51
    void setErrorStream(OutputStream err);
52
 
53
    /**
54
     * Set the callback that the shell has to call when it is closed.
55
     * @param callback
56
     */
57
    void setExitCallback(ExitCallback callback);
58
 
59
    /**
60
     * Starts the shell.
61
     * All streams must have been set before calling this method.
62
     * The command should implement Runnable, and this method
63
     * should spawn a new thread like:
64
     * <pre>
65
     * {@code
66
     * Thread(this).start();
67
     * }
68
     * </pre>
69
     *
70
     * @param env
71
     * @throws java.io.IOException
72
     */
73
    void start(Environment env) throws IOException;
74
 
75
    /**
76
     * Destroy the shell.
77
     * This method can be called by the SSH server to destroy the shell because
78
     * the client has disconnected somehow.
79
     */
80
    void destroy();
81
 
82
}