Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 335415
Collapse All | Expand All

(-)src/org/eclipse/rse/internal/services/shells/TerminalServiceHostShell.java (-1 / +8 lines)
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 20-25 Link Here
20
 * Anna Dushistova  (MontaVista) - adapted from SshHostShell
20
 * Anna Dushistova  (MontaVista) - adapted from SshHostShell
21
 * Anna Dushistova  (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService
21
 * Anna Dushistova  (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService
22
 * Anna Dushistova  (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied
22
 * Anna Dushistova  (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied
23
 * Rob Stryker (JBoss) - [335059] TerminalServiceShellOutputReader logs error when hostShell.exit() is called
23
 *******************************************************************************/
24
 *******************************************************************************/
24
25
25
package org.eclipse.rse.internal.services.shells;
26
package org.eclipse.rse.internal.services.shells;
Lines 119-124 Link Here
119
		if (fShellWriter != null) {
120
		if (fShellWriter != null) {
120
			fShellWriter.stopThread();
121
			fShellWriter.stopThread();
121
		}
122
		}
123
		if( fStderrHandler != null ) {
124
			fStderrHandler.stopThread();
125
		}
126
		if( fStdoutHandler!= null ) {
127
			fStdoutHandler.stopThread();
128
		}
122
		fTerminalShell.exit();
129
		fTerminalShell.exit();
123
	}
130
	}
124
131
(-)src/org/eclipse/rse/internal/services/shells/TerminalServiceShellOutputReader.java (-6 / +33 lines)
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
}
(-)src/org/eclipse/rse/internal/services/shells/TerminalServiceShellWriterThread.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
2
 * Copyright (c) 2006, 2011 Wind River Systems, Inc. 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 9-14 Link Here
9
 * Martin Oberhuber (Wind River) - initial API and implementation
9
 * Martin Oberhuber (Wind River) - initial API and implementation
10
 * Anna Dushistova  (MontaVista) - adapted from SshShellWriterThread
10
 * Anna Dushistova  (MontaVista) - adapted from SshShellWriterThread
11
 * Anna Dushistova  (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService
11
 * Anna Dushistova  (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService
12
 * Rob Stryker (JBoss) - [335059] TerminalServiceShellOutputReader logs error when hostShell.exit() is called
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.rse.internal.services.shells;
14
package org.eclipse.rse.internal.services.shells;
14
15
Lines 20-26 Link Here
20
public class TerminalServiceShellWriterThread extends Thread {
21
public class TerminalServiceShellWriterThread extends Thread {
21
	private PrintWriter fOutputWriter;
22
	private PrintWriter fOutputWriter;
22
	private String fNextCommand;
23
	private String fNextCommand;
23
	private boolean fIsCancelled;
24
	private volatile boolean fIsCancelled;
24
25
25
	/**
26
	/**
26
	 * constructor for terminal service shell writer thread
27
	 * constructor for terminal service shell writer thread

Return to bug 335415