/** {@inheritDoc} */ @Override public synchronized void stopApp() { super.stopApp(); println(" "); println("Remote shell session terminated."); println("type ~. to exit rsh"); println(" "); // Give a couple of seconds to help ensure that the message will be sent. try { Thread.sleep(2000); } catch (InterruptedException ie) { } getInputPipe().close(); getOutputPipe().close(); if (timerTask != null) { timerTask.cancel(); } if (cons != null) { cons.destroy(); } }
/** {@inheritDoc} */ public int startApp(String[] appArgs) { this.appArgs = appArgs; try { cons = new EndpointRemoteShellConsole(this, this, localAddress, remoteAddress, server.endpoint); } catch (IOException failed) { return ShellApp.appMiscError; } ShellEnv env = new ShellEnv(); setEnv(env); env.add("console", new ShellObject<ShellConsole>("console", cons)); env.add("stdgroup", new ShellObject<PeerGroup>("Default Group", getGroup())); // Create the default InputPipe inputPipe = new ShellInputPipe(getGroup(), cons); outputPipe = new ShellOutputPipe(getGroup(), cons); setInputPipe(inputPipe); setOutputPipe(outputPipe); setInputConsPipe(inputPipe); setOutputConsPipe(outputPipe); env.add("stdin", new ShellObject<InputPipe>("stdin", inputPipe)); env.add("stdout", new ShellObject<OutputPipe>("stdout", outputPipe)); env.add("consin", new ShellObject<InputPipe>("consin", inputPipe)); env.add("consout", new ShellObject<OutputPipe>("consout", outputPipe)); timerTask = new TimerTask() { @Override public void run() { long currentTime = System.currentTimeMillis(); if ((currentTime - lastActivity) > rshd.INACTIVITY_TIMEOUT) { consprintln(" "); consoleMessage("Inactivity timeout, your session has automatically shutdown."); stopApp(); } } }; try { server.timer.schedule(timerTask, rshd.INACTIVITY_TIMEOUT, rshd.INACTIVITY_TIMEOUT); } catch (Exception ez1) { printStackTrace("Cannot set inactivity timer: ", ez1); } Thread t = new Thread(getGroup().getHomeThreadGroup(), this, "Remote Shell Session"); t.setDaemon(true); // FIXME 20040421 jice Questionable t.start(); // As far as the invoker is concerned, we're finished here. return ShellApp.appSpawned; }