|
From: <mba...@us...> - 2006-12-30 09:42:37
|
Revision: 1744
http://svn.sourceforge.net/rubyeclipse/?rev=1744&view=rev
Author: mbarchfe
Date: 2006-12-30 01:42:35 -0800 (Sat, 30 Dec 2006)
Log Message:
-----------
next step for ruby debug integration
Modified Paths:
--------------
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/ClassicDebuggerCommandFactory.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/ICommandFactory.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebugCommandFactory.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebuggerProxy.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/model/RubyDebugTarget.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/model/RubyProcessingException.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/AbstractReadStrategy.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/MultiReaderStrategy.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/SingleReaderStrategy.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/VariableReader.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/XmlStreamReader.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/BreakpointAddedReader.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/EvalReader.java
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/ClassicDebuggerCommandFactory.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/ClassicDebuggerCommandFactory.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/ClassicDebuggerCommandFactory.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -48,16 +48,18 @@
return "th " + thread.getId() + ";cont";
}
- public String createSetBreakpoint(String mode, String file, int line) {
+ public String createAddBreakpoint(String file, int line) {
StringBuffer setBreakPointCommand = new StringBuffer();
- setBreakPointCommand.append("b ");
- setBreakPointCommand.append(mode);
- setBreakPointCommand.append(" ");
+ setBreakPointCommand.append("b ") ;
setBreakPointCommand.append(file);
setBreakPointCommand.append(":");
setBreakPointCommand.append(line);
return setBreakPointCommand.toString();
}
+
+ public String createRemoveBreakpoint(int index) {
+ return "delete " + index ;
+ }
public String createCatchOff() {
return "catch off";
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/ICommandFactory.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/ICommandFactory.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/ICommandFactory.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -26,7 +26,9 @@
public String createResume(RubyThread thread);
- public String createSetBreakpoint(String mode, String file, int line);
+ public String createAddBreakpoint(String file, int line);
+
+ public String createRemoveBreakpoint(int index);
public String createCatchOff();
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebugCommandFactory.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebugCommandFactory.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebugCommandFactory.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -48,16 +48,18 @@
return "cont";
}
- public String createSetBreakpoint(String mode, String file, int line) {
+ public String createAddBreakpoint(String file, int line) {
StringBuffer setBreakPointCommand = new StringBuffer();
- setBreakPointCommand.append("b ");
- setBreakPointCommand.append(mode);
- setBreakPointCommand.append(" ");
+ setBreakPointCommand.append("b ") ;
setBreakPointCommand.append(file);
setBreakPointCommand.append(":");
setBreakPointCommand.append(line);
return setBreakPointCommand.toString();
}
+
+ public String createRemoveBreakpoint(int index) {
+ return "delete " + index ;
+ }
public String createCatchOff() {
return "catch off";
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebuggerProxy.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebuggerProxy.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebuggerProxy.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -15,13 +15,16 @@
import org.rubypeople.rdt.internal.debug.core.model.RubyThread;
import org.rubypeople.rdt.internal.debug.core.model.RubyVariable;
import org.rubypeople.rdt.internal.debug.core.model.ThreadInfo;
+import org.rubypeople.rdt.internal.debug.core.parsing.BreakpointAddedReader;
import org.rubypeople.rdt.internal.debug.core.parsing.ErrorReader;
+import org.rubypeople.rdt.internal.debug.core.parsing.EvalReader;
import org.rubypeople.rdt.internal.debug.core.parsing.FramesReader;
import org.rubypeople.rdt.internal.debug.core.parsing.LoadResultReader;
import org.rubypeople.rdt.internal.debug.core.parsing.MultiReaderStrategy;
import org.rubypeople.rdt.internal.debug.core.parsing.SuspensionReader;
import org.rubypeople.rdt.internal.debug.core.parsing.ThreadInfoReader;
import org.rubypeople.rdt.internal.debug.core.parsing.VariableReader;
+import org.rubypeople.rdt.internal.debug.core.parsing.XmlStreamReaderException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
@@ -35,12 +38,14 @@
private RubyLoop rubyLoop;
private XmlPullParser xpp;
protected MultiReaderStrategy multiReaderStrategy;
- private ICommandFactory commandFactory ;
+ private ICommandFactory commandFactory;
+ private final boolean isRubyDebug;
public RubyDebuggerProxy(IRubyDebugTarget debugTarget, boolean isRubyDebug) {
this.debugTarget = debugTarget;
+ this.isRubyDebug = isRubyDebug;
debugTarget.setRubyDebuggerProxy(this);
- commandFactory = isRubyDebug ? new RubyDebugCommandFactory() : new ClassicDebuggerCommandFactory() ;
+ commandFactory = isRubyDebug ? new RubyDebugCommandFactory() : new ClassicDebuggerCommandFactory();
}
public boolean checkConnection() {
@@ -53,11 +58,31 @@
}
}
- public void start() {
+ public String registerRdebugExtension(String pathToRdebugExtension) throws IOException, RubyProcessingException {
+ // should be called before start
+ if (!isRubyDebug) {
+ return "false";
+ }
try {
+ // TODO: do not let the debugger stop on the first line
+ new SuspensionReader(getMultiReaderStrategy()).readSuspension();
+ } catch (Exception e) {
+ RdtDebugCorePlugin.log(e);
+ }
+ String expression = "eval require '" + pathToRdebugExtension + "'";
+ println(expression);
+ EvalReader reader = new EvalReader(getMultiReaderStrategy());
+ return reader.readEvalResult(); // throws
+ // RubyProcessingException
+ }
+
+ public void start() throws RubyProcessingException {
+ try {
this.setBreakPoints();
this.startRubyLoop();
- } catch (IOException e) {}
+ } catch (Exception e) {
+ RdtDebugCorePlugin.log(e);
+ }
}
public void stop() {
@@ -90,7 +115,9 @@
if (socket == null) {
socket = acquireSocket();
- if (socket == null) { throw new DebuggerNotFoundException(); }
+ if (socket == null) {
+ throw new DebuggerNotFoundException();
+ }
}
return socket;
}
@@ -144,8 +171,12 @@
if (breakpoint.isEnabled()) {
if (breakpoint instanceof RubyExceptionBreakpoint) {
this.println(commandFactory.createCatchOn(breakpoint));
- } else {
- this.printBreakpoint("", breakpoint.getMarker().getResource().getName(), breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, -1));
+ } else if (breakpoint instanceof RubyLineBreakpoint) {
+ RubyLineBreakpoint rubyLineBreakpoint = (RubyLineBreakpoint) breakpoint;
+ String command = commandFactory.createAddBreakpoint(rubyLineBreakpoint.getFileName(), rubyLineBreakpoint.getLineNumber());
+ this.println(command);
+ int index = readBreakpointIndex();
+ rubyLineBreakpoint.setIndex(index);
}
}
} catch (IOException e) {
@@ -158,9 +189,17 @@
public void removeBreakpoint(IBreakpoint breakpoint) {
try {
if (breakpoint instanceof RubyExceptionBreakpoint) {
+ // so far we allow only one catch exception
+ // catch off must be set in the case that the enablement has
+ // changed to disabled
this.println(commandFactory.createCatchOff());
- } else {
- this.printBreakpoint("remove", breakpoint.getMarker().getResource().getName(), breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, -1));
+ } else if (breakpoint instanceof RubyLineBreakpoint) {
+ RubyLineBreakpoint rubyLineBreakpoint = (RubyLineBreakpoint) breakpoint;
+ if (rubyLineBreakpoint.getIndex() != -1) {
+ String command = commandFactory.createRemoveBreakpoint(rubyLineBreakpoint.getIndex());
+ this.println(command);
+ rubyLineBreakpoint.setIndex(-1);
+ }
}
} catch (IOException e) {
RdtDebugCorePlugin.log(e);
@@ -169,29 +208,18 @@
}
public void updateBreakpoint(IBreakpoint breakpoint, IMarkerDelta markerDelta) {
- // line might have changed or enablement/disablement
- try {
- if (breakpoint instanceof RubyExceptionBreakpoint) {
- // so far we allow only one catch exception
- // catch off must be set in the case that the enablement has changed to disabled
- this.println(commandFactory.createCatchOff());
- } else {
- // remove is called even if it has not been added at program start
- // (happens if enablement changed from disabled at program start to
- // enabled)
- this.printBreakpoint("remove", breakpoint.getMarker().getResource().getName(), markerDelta.getAttribute(IMarker.LINE_NUMBER, -1));
+ int currentline = markerDelta.getAttribute(IMarker.LINE_NUMBER, -1);
+ try {
+ if (currentline == ((RubyLineBreakpoint) breakpoint).getLineNumber()) {
+ return;
}
+ this.removeBreakpoint(breakpoint);
this.addBreakpoint(breakpoint);
- } catch (IOException e) {
+ } catch (CoreException e) {
RdtDebugCorePlugin.log(e);
}
}
- protected void printBreakpoint(String mode, String file, int line) throws IOException {
- String command = commandFactory.createSetBreakpoint(mode, file, line);
- this.println(command);
- }
-
public void startRubyLoop() {
rubyLoop = new RubyLoop();
rubyLoop.start();
@@ -202,7 +230,7 @@
new ErrorReader(getMultiReaderStrategy()).read();
}
} catch (Exception e) {
- RdtDebugCorePlugin.log(e) ;
+ RdtDebugCorePlugin.log(e);
}
};
};
@@ -231,9 +259,18 @@
return debugTarget;
}
+ public int readBreakpointIndex() {
+ try {
+ return new BreakpointAddedReader(getMultiReaderStrategy()).readBreakpointNo();
+ } catch (Exception ioex) {
+ ioex.printStackTrace();
+ throw new RuntimeException(ioex.getMessage());
+ }
+ }
+
public RubyVariable[] readVariables(RubyStackFrame frame) {
try {
- this.println(commandFactory.createReadLocalVariables(frame)) ;
+ this.println(commandFactory.createReadLocalVariables(frame));
return new VariableReader(getMultiReaderStrategy()).readVariables(frame);
} catch (Exception ioex) {
ioex.printStackTrace();
@@ -243,7 +280,7 @@
public RubyVariable[] readInstanceVariables(RubyVariable variable) {
try {
- this.println(commandFactory.createReadInstanceVariable(variable)) ;
+ this.println(commandFactory.createReadInstanceVariable(variable));
return new VariableReader(getMultiReaderStrategy()).readVariables(variable);
} catch (Exception ioex) {
ioex.printStackTrace();
@@ -293,7 +330,7 @@
public RubyStackFrame[] readFrames(RubyThread thread) {
try {
- this.println(commandFactory.createReadFrames(thread)) ;
+ this.println(commandFactory.createReadFrames(thread));
return new FramesReader(getMultiReaderStrategy()).readFrames(thread);
} catch (IOException e) {
RdtDebugCorePlugin.log(e);
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -12,14 +12,17 @@
public class RubyLineBreakpoint extends LineBreakpoint {
protected static final String RUBY_BREAKPOINT_MARKER = "org.rubypeople.rdt.debug.core.RubyBreakpointMarker"; //$NON-NLS-1$
+ private int index = -1 ; // index of breakpoint on ruby debugger side
+
public RubyLineBreakpoint(final IResource resource, final int lineNumber) throws CoreException {
IWorkspaceRunnable wr = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
setMarker(resource.createMarker(RUBY_BREAKPOINT_MARKER));
getMarker().setAttribute(IMarker.LINE_NUMBER, lineNumber + 1);
getMarker().setAttribute(REGISTERED, false);
+ // setEnabled must be set before calling setRegistered
+ setEnabled(true);
setRegistered(true);
- setEnabled(true);
}
};
try {
@@ -29,6 +32,10 @@
}
}
+
+ public String getFileName() throws CoreException {
+ return ensureMarker().getResource().getName();
+ }
public int getLineNumber() throws CoreException {
return ensureMarker().getAttribute(IMarker.LINE_NUMBER, -1);
@@ -53,4 +60,12 @@
return "org.rubypeople.rdt.debug";
}
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
}
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/model/RubyDebugTarget.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/model/RubyDebugTarget.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/model/RubyDebugTarget.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -46,6 +46,7 @@
this.launch = launch;
this.process = process;
this.threads = new RubyThread[0] ;
+ this.isTerminated = false ;
IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager();
manager.addBreakpointListener(this);
}
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/model/RubyProcessingException.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/model/RubyProcessingException.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/model/RubyProcessingException.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -5,6 +5,11 @@
public class RubyProcessingException extends Exception {
private static final long serialVersionUID = -1651883905005341856L;
private String rubyExceptionType ;
+
+ public RubyProcessingException(String message) {
+ super(message) ;
+ }
+
public RubyProcessingException(String type, String message) {
super(message) ;
this.rubyExceptionType = type ;
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/AbstractReadStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/AbstractReadStrategy.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/AbstractReadStrategy.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -12,12 +12,8 @@
this.xpp = xpp ;
}
-
public abstract void readElement(XmlStreamReader streamReader) throws XmlPullParserException, IOException, XmlStreamReaderException ;
-
-
-
-
+ public abstract void readElement(XmlStreamReader streamReader, long maxWaitTime) throws XmlPullParserException, IOException, XmlStreamReaderException ;
}
Added: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/BreakpointAddedReader.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/BreakpointAddedReader.java (rev 0)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/BreakpointAddedReader.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -0,0 +1,48 @@
+package org.rubypeople.rdt.internal.debug.core.parsing;
+
+import org.rubypeople.rdt.internal.debug.core.RdtDebugCorePlugin;
+import org.rubypeople.rdt.internal.debug.core.model.RubyProcessingException;
+import org.xmlpull.v1.XmlPullParser;
+
+public class BreakpointAddedReader extends XmlStreamReader {
+
+ private String no;
+
+ public BreakpointAddedReader(XmlPullParser xpp) {
+ super(xpp);
+ }
+
+ public BreakpointAddedReader(AbstractReadStrategy readStrategy) {
+ super(readStrategy);
+ }
+
+ @Override
+ protected boolean processStartElement(XmlPullParser xpp) throws XmlStreamReaderException {
+ boolean result = false;
+ if (xpp.getName().equals("breakpointAdded")) {
+ no = xpp.getAttributeValue("", "no");
+ result = true;
+ }
+ return result;
+ }
+
+ public int readBreakpointNo() throws NumberFormatException {
+
+ try {
+ this.read();
+ } catch (Exception ex) {
+ RdtDebugCorePlugin.log(ex);
+ return -1;
+ }
+ return Integer.parseInt(no) ;
+ }
+
+ @Override
+ public void processContent(String text) {}
+
+ @Override
+ protected boolean processEndElement(XmlPullParser xpp) {
+ return xpp.getName().equals("breakpointAdded") ;
+ }
+
+}
Added: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/EvalReader.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/EvalReader.java (rev 0)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/EvalReader.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -0,0 +1,59 @@
+package org.rubypeople.rdt.internal.debug.core.parsing;
+
+import org.rubypeople.rdt.internal.debug.core.RdtDebugCorePlugin;
+import org.rubypeople.rdt.internal.debug.core.model.RubyProcessingException;
+import org.xmlpull.v1.XmlPullParser;
+
+public class EvalReader extends XmlStreamReader {
+
+ private String exceptionType;
+ private String exceptionMessage;
+ private String name;
+ private String value;
+
+ public EvalReader(XmlPullParser xpp) {
+ super(xpp);
+ }
+
+ public EvalReader(AbstractReadStrategy readStrategy) {
+ super(readStrategy);
+ }
+
+ @Override
+ protected boolean processStartElement(XmlPullParser xpp) throws XmlStreamReaderException {
+ boolean result = false;
+ if (xpp.getName().equals("processingException")) {
+ exceptionType = xpp.getAttributeValue("", "type");
+ exceptionMessage = xpp.getAttributeValue("", "message");
+ result = true;
+ } else if (xpp.getName().equals("eval")) {
+ name = xpp.getAttributeValue("", "name");
+ value = xpp.getAttributeValue("", "value");
+ result = true;
+ }
+ return result;
+ }
+
+ public String readEvalResult() throws RubyProcessingException {
+
+ try {
+ this.read();
+ } catch (Exception ex) {
+ RdtDebugCorePlugin.log(ex);
+ return null;
+ }
+ if (exceptionType != null) {
+ throw new RubyProcessingException(exceptionType, exceptionMessage);
+ }
+ return value;
+ }
+
+ @Override
+ public void processContent(String text) {}
+
+ @Override
+ protected boolean processEndElement(XmlPullParser xpp) {
+ return xpp.getName().equals("processingException") || xpp.getName().equals("eval");
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/MultiReaderStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/MultiReaderStrategy.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/MultiReaderStrategy.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -82,13 +82,7 @@
int missed = 0 ;
RdtDebugCorePlugin.debug("Searching reader for start tag " + xpp.getName());
do {
- for (Iterator iter = streamReaders.iterator(); iter.hasNext();) {
- XmlStreamReader streamReader = (XmlStreamReader) iter.next();
- if (streamReader.processStartElement(xpp)) {
- currentReader = streamReader;
- break;
- }
- }
+ findReaderForTag();
if (currentReader == null) {
missed += 1 ;
RdtDebugCorePlugin.debug("Missed Start Tag : " + xpp.getName());
@@ -100,9 +94,19 @@
} while (currentReader == null && missed < 10);
}
- protected void releaseAllReader() {
+ private synchronized void findReaderForTag() throws XmlStreamReaderException {
for (Iterator iter = streamReaders.iterator(); iter.hasNext();) {
XmlStreamReader streamReader = (XmlStreamReader) iter.next();
+ if (streamReader.processStartElement(xpp)) {
+ currentReader = streamReader;
+ break;
+ }
+ }
+ }
+
+ protected synchronized void releaseAllReader() {
+ for (Iterator iter = streamReaders.iterator(); iter.hasNext();) {
+ XmlStreamReader streamReader = (XmlStreamReader) iter.next();
((Thread) threads.get(streamReader)).interrupt();
iter.remove() ;
}
@@ -121,10 +125,15 @@
}
public void readElement(XmlStreamReader streamReader) {
+ readElement(streamReader, Long.MAX_VALUE) ;
+ }
+
+ public void readElement(XmlStreamReader streamReader, long maxWaitTime) {
this.addReader(streamReader);
try {
RdtDebugCorePlugin.debug("Thread is waiting for input: " + Thread.currentThread());
- Thread.sleep(Long.MAX_VALUE);
+ Thread.sleep(maxWaitTime);
+ streamReader.setWaitTimeExpired(true) ;
} catch (InterruptedException e) {
RdtDebugCorePlugin.debug("Thread has finished processing : " + Thread.currentThread());
}
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/SingleReaderStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/SingleReaderStrategy.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/SingleReaderStrategy.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -35,4 +35,9 @@
} while (true);
}
+ @Override
+ public void readElement(XmlStreamReader streamReader, long maxWaitTime) throws XmlPullParserException, IOException, XmlStreamReaderException {
+ readElement(streamReader) ;
+ }
+
}
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/VariableReader.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/VariableReader.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/VariableReader.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -38,13 +38,16 @@
this.parent = parent ;
this.variables = new ArrayList() ;
try {
- this.read();
+ // TODO: timeout should be configurable
+ this.read(10000);
} catch (Exception ex) {
RdtDebugCorePlugin.log(ex) ;
return new RubyVariable[0] ;
}
if (exceptionMessage != null) {
throw new RubyProcessingException(exceptionType, exceptionMessage) ;
+ } else if (isWaitTimeExpired()) {
+ throw new RubyProcessingException("Timeout: Could not read result.") ;
}
RubyVariable[] variablesArray = new RubyVariable[variables.size()];
variables.toArray(variablesArray);
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/XmlStreamReader.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/XmlStreamReader.java 2006-12-29 22:33:18 UTC (rev 1743)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/parsing/XmlStreamReader.java 2006-12-30 09:42:35 UTC (rev 1744)
@@ -8,6 +8,7 @@
public abstract class XmlStreamReader {
private AbstractReadStrategy readStrategy ;
+ private boolean isWaitTimeExpired ;
public XmlStreamReader(XmlPullParser xpp) {
this(new SingleReaderStrategy(xpp)) ;
@@ -15,11 +16,16 @@
public XmlStreamReader(AbstractReadStrategy readStrategy) {
this.readStrategy = readStrategy ;
+ this.isWaitTimeExpired = false ;
}
public void read() throws XmlPullParserException, IOException, XmlStreamReaderException{
this.readStrategy.readElement(this) ;
}
+
+ public void read(long maxWaitTime) throws XmlPullParserException, IOException, XmlStreamReaderException{
+ this.readStrategy.readElement(this, maxWaitTime) ;
+ }
protected abstract boolean processStartElement(XmlPullParser xpp) throws XmlStreamReaderException ;
protected boolean processEndElement(XmlPullParser xpp) {
@@ -32,4 +38,12 @@
public void processContent(String text) {
}
+ public boolean isWaitTimeExpired() {
+ return isWaitTimeExpired;
+ }
+
+ protected void setWaitTimeExpired(boolean isWaitTimeExpired) {
+ this.isWaitTimeExpired = isWaitTimeExpired;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|