|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2006, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2006, 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 16-21
Link Here
|
| 16 |
* Martin Oberhuber (Wind River) - Added vt100 escape sequence ignoring. |
16 |
* Martin Oberhuber (Wind River) - Added vt100 escape sequence ignoring. |
| 17 |
* Anna Dushistova (MontaVista) - adapted from SshShellOutputReader |
17 |
* Anna Dushistova (MontaVista) - adapted from SshShellOutputReader |
| 18 |
* Anna Dushistova (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService |
18 |
* Anna Dushistova (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService |
|
|
19 |
* Rob Stryker (JBoss) - [335059] TerminalServiceShellOutputReader logs error when hostShell.exit() is called |
| 19 |
*******************************************************************************/ |
20 |
*******************************************************************************/ |
| 20 |
|
21 |
|
| 21 |
package org.eclipse.rse.internal.services.shells; |
22 |
package org.eclipse.rse.internal.services.shells; |
|
Lines 35-40
Link Here
|
| 35 |
public class TerminalServiceShellOutputReader extends |
36 |
public class TerminalServiceShellOutputReader extends |
| 36 |
AbstractHostShellOutputReader { |
37 |
AbstractHostShellOutputReader { |
| 37 |
protected BufferedReader fReader; |
38 |
protected BufferedReader fReader; |
|
|
39 |
private volatile Thread fReaderThread = null; |
| 40 |
private volatile boolean isCanceled = false; |
| 38 |
private String fPromptChars = ">$%#]"; //Characters we accept as the end of a prompt //$NON-NLS-1$; |
41 |
private String fPromptChars = ">$%#]"; //Characters we accept as the end of a prompt //$NON-NLS-1$; |
| 39 |
|
42 |
|
| 40 |
public TerminalServiceShellOutputReader(IHostShell hostShell, |
43 |
public TerminalServiceShellOutputReader(IHostShell hostShell, |
|
Lines 50-61
Link Here
|
| 50 |
//TODO Check if ssh supports some method of having separate stdout and stderr streams |
53 |
//TODO Check if ssh supports some method of having separate stdout and stderr streams |
| 51 |
return null; |
54 |
return null; |
| 52 |
} |
55 |
} |
|
|
56 |
fReaderThread = Thread.currentThread(); |
| 57 |
try { |
| 58 |
return interruptableReadLine(); |
| 59 |
} finally { |
| 60 |
fReaderThread = null; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
private IHostOutput interruptableReadLine() { |
| 53 |
StringBuffer theLine = new StringBuffer(); |
65 |
StringBuffer theLine = new StringBuffer(); |
| 54 |
StringBuffer theDebugLine = null; |
66 |
StringBuffer theDebugLine = null; |
| 55 |
theDebugLine = new StringBuffer(); |
67 |
theDebugLine = new StringBuffer(); |
| 56 |
int ch; |
68 |
int ch; |
| 57 |
boolean done = false; |
69 |
boolean done = false; |
| 58 |
while (!done && !isFinished()) { |
70 |
while (!done && !isFinished() && !isCanceled) { |
| 59 |
try { |
71 |
try { |
| 60 |
ch = fReader.read(); |
72 |
ch = fReader.read(); |
| 61 |
switch (ch) { |
73 |
switch (ch) { |
|
Lines 125-133
Link Here
|
| 125 |
if (len>=0 && fPromptChars.indexOf(theLine.charAt(len))>=0) { |
137 |
if (len>=0 && fPromptChars.indexOf(theLine.charAt(len))>=0) { |
| 126 |
waitIncrement = 5; //wait only 5 msec if we think it's a prompt |
138 |
waitIncrement = 5; //wait only 5 msec if we think it's a prompt |
| 127 |
} |
139 |
} |
| 128 |
try { |
140 |
if (!isCanceled) { |
| 129 |
Thread.sleep(waitIncrement); |
141 |
try { |
| 130 |
} catch (InterruptedException e) { |
142 |
Thread.sleep(waitIncrement); |
|
|
143 |
} catch (InterruptedException e) { /*ignore*/ } |
| 131 |
} |
144 |
} |
| 132 |
if (!fReader.ready()) { |
145 |
if (!fReader.ready()) { |
| 133 |
done = true; |
146 |
done = true; |
|
Lines 137-143
Link Here
|
| 137 |
//FIXME it's dangerous to return null here since this will end |
150 |
//FIXME it's dangerous to return null here since this will end |
| 138 |
//our reader thread completely... the exception could just be |
151 |
//our reader thread completely... the exception could just be |
| 139 |
//temporary, and we should keep running! |
152 |
//temporary, and we should keep running! |
| 140 |
Activator.getDefault().logException(e); |
153 |
if( !this.isCanceled ) { |
|
|
154 |
/* 335059: Don't log IOException on close due to cancellation */ |
| 155 |
Activator.getDefault().logException(e); |
| 156 |
} |
| 141 |
return null; |
157 |
return null; |
| 142 |
} |
158 |
} |
| 143 |
} |
159 |
} |
|
Lines 147-150
Link Here
|
| 147 |
} |
163 |
} |
| 148 |
return new SimpleHostOutput(theLine.toString()); |
164 |
return new SimpleHostOutput(theLine.toString()); |
| 149 |
} |
165 |
} |
|
|
166 |
|
| 167 |
/** |
| 168 |
* Stop the reader Thread, forcing internalReadLine() to return. |
| 169 |
* Does not close the Stream. |
| 170 |
*/ |
| 171 |
public void stopThread() { |
| 172 |
this.isCanceled = true; |
| 173 |
if (fReaderThread != null) { |
| 174 |
fReaderThread.interrupt(); |
| 175 |
} |
| 176 |
} |
| 150 |
} |
177 |
} |