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 316404 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ptp/rm/pbs/jproxy/PBSProxyRuntimeServer.java (+12 lines)
Lines 195-200 Link Here
195
	 */
195
	 */
196
	@Override
196
	@Override
197
	protected void initServer() throws Exception {
197
	protected void initServer() throws Exception {
198
		Controller.ErrorHandler handler = new Controller.ErrorHandler() {
199
			public void handle(Level level, String msg) {
200
				try {
201
					sendEvent(getEventFactory().newProxyRuntimeMessageEvent(level, msg));
202
				} catch (IOException e) {
203
					e.printStackTrace(); // sendEvent failed - can't signal UI
204
				}
205
			}
206
		};
207
		nodeController.setErrorHandler(handler);
208
		queueController.setErrorHandler(handler);
209
		jobController.setErrorHandler(handler);
198
		// Test whether all programs and parser work
210
		// Test whether all programs and parser work
199
		nodeController.parse();
211
		nodeController.parse();
200
		queueController.parse();
212
		queueController.parse();
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 2-8 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.ptp.rm.proxy.core;singleton:=true
4
Bundle-SymbolicName: org.eclipse.ptp.rm.proxy.core;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
5
Bundle-Version: 1.1.0.qualifier
6
Export-Package: org.eclipse.ptp.rm.proxy.core,
6
Export-Package: org.eclipse.ptp.rm.proxy.core,
7
 org.eclipse.ptp.rm.proxy.core.attributes,
7
 org.eclipse.ptp.rm.proxy.core.attributes,
8
 org.eclipse.ptp.rm.proxy.core.element,
8
 org.eclipse.ptp.rm.proxy.core.element,
(-)src/org/eclipse/ptp/rm/proxy/core/Controller.java (-21 / +61 lines)
Lines 17-22 Link Here
17
import java.io.FileInputStream;
17
import java.io.FileInputStream;
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.io.InputStream;
19
import java.io.InputStream;
20
import java.text.MessageFormat;
20
import java.util.ArrayList;
21
import java.util.ArrayList;
21
import java.util.Arrays;
22
import java.util.Arrays;
22
import java.util.HashSet;
23
import java.util.HashSet;
Lines 24-36 Link Here
24
import java.util.List;
25
import java.util.List;
25
import java.util.Queue;
26
import java.util.Queue;
26
import java.util.Set;
27
import java.util.Set;
28
import java.util.concurrent.Callable;
29
import java.util.concurrent.ExecutorService;
30
import java.util.concurrent.Executors;
31
import java.util.concurrent.Future;
27
import java.util.regex.Pattern;
32
import java.util.regex.Pattern;
28
33
29
import org.eclipse.ptp.proxy.event.IProxyEvent;
34
import org.eclipse.ptp.proxy.event.IProxyEvent;
35
import org.eclipse.ptp.proxy.event.IProxyMessageEvent.Level;
30
import org.eclipse.ptp.rm.proxy.core.attributes.AttributeDefinition;
36
import org.eclipse.ptp.rm.proxy.core.attributes.AttributeDefinition;
31
import org.eclipse.ptp.rm.proxy.core.element.ElementManager;
37
import org.eclipse.ptp.rm.proxy.core.element.ElementManager;
32
import org.eclipse.ptp.rm.proxy.core.element.IElement;
38
import org.eclipse.ptp.rm.proxy.core.element.IElement;
33
import org.eclipse.ptp.rm.proxy.core.event.IEventFactory;
39
import org.eclipse.ptp.rm.proxy.core.event.IEventFactory;
40
import org.eclipse.ptp.rm.proxy.core.messages.Messages;
34
import org.eclipse.ptp.rm.proxy.core.parser.IParser;
41
import org.eclipse.ptp.rm.proxy.core.parser.IParser;
35
import org.eclipse.ptp.utils.core.RangeSet;
42
import org.eclipse.ptp.utils.core.RangeSet;
36
43
Lines 56-61 Link Here
56
 */
63
 */
57
public class Controller {
64
public class Controller {
58
65
66
	/**
67
	 * @since 1.1
68
	 */
69
	public static interface ErrorHandler {
70
		void handle(Level level, String msg);
71
	}
72
59
	class FilterData {
73
	class FilterData {
60
		String key;
74
		String key;
61
		Pattern pattern;
75
		Pattern pattern;
Lines 67-72 Link Here
67
	}
81
	}
68
82
69
	private Queue<String> debugFiles = null;
83
	private Queue<String> debugFiles = null;
84
	private ErrorHandler errorHandler = null;
70
	private final String command;
85
	private final String command;
71
	private final IEventFactory eventFactory;
86
	private final IEventFactory eventFactory;
72
	private final IParser parser;
87
	private final IParser parser;
Lines 77-82 Link Here
77
	private FilterData filter = null;
92
	private FilterData filter = null;
78
93
79
	private final AttributeDefinition attrDef;
94
	private final AttributeDefinition attrDef;
95
	private static ExecutorService fPool = Executors.newCachedThreadPool();
80
96
81
	/**
97
	/**
82
	 * Instantiates a new controller.
98
	 * Instantiates a new controller.
Lines 153-183 Link Here
153
	 * @throws Execption
169
	 * @throws Execption
154
	 */
170
	 */
155
	public Set<IElement> parse() throws Exception {
171
	public Set<IElement> parse() throws Exception {
156
		InputStream is = null;
157
		if (debugFiles != null) {
172
		if (debugFiles != null) {
158
			String file = debugFiles.poll();
173
			String file = debugFiles.poll();
159
			is = readFile(file);
174
			InputStream is = new BufferedInputStream(new FileInputStream(new File(file)));
160
			debugFiles.add(file);
175
			debugFiles.add(file);
161
		} else {
162
			is = readProgramOutput(command);
163
		}
164
		/*
165
		 * throws Exception to allow any Exception from different parsers
166
		 */
167
		return parser.parse(attrDef, is);
168
	}
169
170
	private InputStream readFile(String path) throws IOException {
171
		return new BufferedInputStream(new FileInputStream(new File(path)));
172
	}
173
174
	private InputStream readProgramOutput(String string) throws IOException {
175
		String[] args = string.split(" "); //$NON-NLS-1$
176
		Process p = Runtime.getRuntime().exec(args); // TODO read stderr for
177
														// potential errors
178
176
179
		// read the standard output of the command
177
			/*
180
		return new BufferedInputStream(p.getInputStream());
178
			 * throws Exception to allow any Exception from different parsers
179
			 */
180
			try {
181
				return parser.parse(attrDef, is);
182
			} finally {
183
				is.close();
184
			}
185
		}
186
		Process p = Runtime.getRuntime().exec(command);
187
		final InputStream is = new BufferedInputStream(p.getInputStream());
188
		final InputStream err = new BufferedInputStream(p.getInputStream());
189
		Callable<Set<IElement>> parseThread = new Callable<Set<IElement>>() {
190
			public Set<IElement> call() throws Exception {
191
				Set<IElement> ret = parser.parse(attrDef, is);
192
				try {
193
					while (is.read(new byte[1024]) > -1) {
194
					} /* read any additional unparsed output to prevent dead-lock */
195
				} catch (IOException e) {
196
					// ignore
197
				}
198
				return ret;
199
			}
200
		};
201
		Future<Set<IElement>> ret = fPool.submit(parseThread);
202
		byte buf[] = new byte[1024];
203
		int length;
204
		while ((length = err.read(buf)) > -1) {
205
			if (errorHandler != null)
206
				errorHandler.handle(Level.WARNING, new String(buf, 0, length));
207
		}
208
		p.waitFor();
209
		int exitValue = p.exitValue();
210
		if (exitValue != 0 && errorHandler != null) {
211
			errorHandler.handle(Level.ERROR, MessageFormat.format(Messages.getString("Controller.0"), command, exitValue)); //$NON-NLS-1$
212
		}
213
		return ret.get();
181
	}
214
	}
182
215
183
	/**
216
	/**
Lines 204-209 Link Here
204
	}
237
	}
205
238
206
	/**
239
	/**
240
	 * @since 1.1
241
	 */
242
	public void setErrorHandler(ErrorHandler errorHandler) {
243
		this.errorHandler = errorHandler;
244
	}
245
246
	/**
207
	 * Acctivate filters for the output to be sent to the client
247
	 * Acctivate filters for the output to be sent to the client
208
	 * 
248
	 * 
209
	 * @param key
249
	 * @param key
(-)src/org/eclipse/ptp/rm/proxy/core/messages.properties (+1 lines)
Added Link Here
1
Controller.0={0} finished with exit code {1}
(-)src/org/eclipse/ptp/rm/proxy/core/messages/Messages.java (+21 lines)
Added Link Here
1
package org.eclipse.ptp.rm.proxy.core.messages;
2
3
import java.util.MissingResourceException;
4
import java.util.ResourceBundle;
5
6
public class Messages {
7
	private static final String BUNDLE_NAME = "org.eclipse.ptp.rm.proxy.core.messages"; //$NON-NLS-1$
8
9
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
10
11
	private Messages() {
12
	}
13
14
	public static String getString(String key) {
15
		try {
16
			return RESOURCE_BUNDLE.getString(key);
17
		} catch (MissingResourceException e) {
18
			return '!' + key + '!';
19
		}
20
	}
21
}
(-)src/org/eclipse/ptp/rm/proxy/core/parser/XMLReader.java (-1 lines)
Lines 151-157 Link Here
151
		Set<IElement> elementList = null;
151
		Set<IElement> elementList = null;
152
		NodeList xmlNodes = null;
152
		NodeList xmlNodes = null;
153
		xmlNodes = getXMLChildren(in);
153
		xmlNodes = getXMLChildren(in);
154
		in.close();
155
		elementList = new HashSet<IElement>(xmlNodes.getLength());
154
		elementList = new HashSet<IElement>(xmlNodes.getLength());
156
		for (int i = 0; i < xmlNodes.getLength(); i++) {
155
		for (int i = 0; i < xmlNodes.getLength(); i++) {
157
			Node node = xmlNodes.item(i);
156
			Node node = xmlNodes.item(i);

Return to bug 316404