當前位置: 首頁>>代碼示例>>Java>>正文


Java OnSessionExecuteListener類代碼示例

本文整理匯總了Java中com.sonelli.juicessh.pluginlibrary.listeners.OnSessionExecuteListener的典型用法代碼示例。如果您正苦於以下問題:Java OnSessionExecuteListener類的具體用法?Java OnSessionExecuteListener怎麽用?Java OnSessionExecuteListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OnSessionExecuteListener類屬於com.sonelli.juicessh.pluginlibrary.listeners包,在下文中一共展示了OnSessionExecuteListener類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeCommandOnSession

import com.sonelli.juicessh.pluginlibrary.listeners.OnSessionExecuteListener; //導入依賴的package包/類
/**
 * Opens a new exec channel on an existing SSH connection and executes a command.
 * Returns the output to the plugin via an {@link com.sonelli.juicessh.pluginlibrary.listeners.OnSessionExecuteListener }.
 * @param sessionId The integer session ID returned when the session was started
 * @param sessionKey The session key returned when the session was started
 * @param command The command to run
 * @param listener The callback listener
 * @throws ServiceNotConnectedException
 */
public void executeCommandOnSession(int sessionId, String sessionKey, String command, final OnSessionExecuteListener listener)  throws ServiceNotConnectedException {

    if(!isConnected())
        throw new ServiceNotConnectedException();

    try {
        service.executeCommandOnSession(sessionId, sessionKey, command, new ISessionExecuteListener.Stub() {

            @Override
            public void onError(final int reason, final String error) throws RemoteException {
                if(reason == Errors.WRONG_CONNECTION_TYPE){
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            if(listener != null)
                                listener.onError(Errors.WRONG_CONNECTION_TYPE, error);
                        }
                    });
                }
            }

            @Override
            public void onCompleted(final int returnCode) throws RemoteException {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        if(listener != null)
                            listener.onCompleted(returnCode);
                    }
                });
            }

            @Override
            public void onOutputLine(final String line) throws RemoteException {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        if(listener != null)
                            listener.onOutputLine(line);
                    }
                });
            }
        });
    } catch (RemoteException e){
        throw new ServiceNotConnectedException();
    }
}
 
開發者ID:Sonelli,項目名稱:juicessh-pluginlibrary,代碼行數:57,代碼來源:PluginClient.java


注:本文中的com.sonelli.juicessh.pluginlibrary.listeners.OnSessionExecuteListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。