本文整理匯總了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();
}
}