On Fri, May 21, 2010 at 10:49 AM, Angelo zerr <
angelo.zerr@xxxxxxxxx> wrote:
> Hi XQDT Team,
>
> At first, I would like thank you for your work.
>
> I have started to implements XHive XQDT plugin by studying Marklogic code
> and now I can Run my XQuery by using XHive server. That's very cool:)
> But I have noticed into Debug View that when I launch an XQuery, the process
> is never terminated and it's impossible to terminate it. Problem comes from
> into class
> org.eclipse.wst.xquery.internal.launching.marklogic.MarkLogicRunner into
> private class MarkLogicProcess. MarkLogicProcess implements IProcess and
> some methods (like isTerminated, terminate...) are not implemented.
>
> I have seen that you have implemented a lot of Eclipse Debug interface like
> MockStreamMonitor, MockStreamsProxy...and I have studied a solution to
> resolve that. My goal was :
>
> 1) fix terminate problem.
> 2) don't implements MockStreamMonitor, MockStreamsProxy but use Eclipse
> Debug implementation (org.eclipse.debug.internal.core.StreamsProxy instead
> of MockStreamsProxy, org.eclipse.debug.internal.core.OutputStreamMonitor
> instead of MockStreamMonitor )
> 3) use DLTK AbstractInterpreterRunner instead of implementing
> IInterpreterRunner (as you have done with MarkLogicRunner).
>
> And I have resolved this 3 points. The basic idea is that
> AbstractInterpreterRunner works only with Java process and in your case (my
> case too) we wish launch not a Java Process but a Java class in our plugin.
> I have studied the code of AbstractInterpreterRunner and DLTK use this code
>
> --------------------
> IProcess process = DebugPlugin.newProcess(launch, p, label, attributes);
> --------------------
>
> where p is java.lang.Process implementation.
>
> DebugPlugin.newProcess use internally the code
>
> --------------------
> return new org.eclipse.debug.core.model.RuntimeProcess(launch, process,
> label, attributes);
> --------------------
>
> IHMO I think we shoud use RuntimeProcess too in our case to use
> AbstractInterpreterRunner, and RuntimeProcess manage muti threading for the
> monitor (thread for message, for error..). The only problem is process
> (which implement java.lang.Process and which is Java lang Process). So to
> resolve that I have created a class RunnableProcess wich extends
> java.lang.Process by implementing the methods. This abstract class
> implements Runnable too. So the only thing to do is to extends this class
> and implement run method :
>
> --------------------
> public abstract class RunnableProcess extends java.lang.Process implements
> Runnable {
>
> public int waitFor() throws InterruptedException {
> ....
> run()
> ...
> }
> }
> --------------------
>
> I have done that into Freemarker Plugin which is based on DLTK too into
> class FreemarkerRunnableProcess: This class implements DLTKRunnableProcess
> (which implements RunnableProcess) because I need launch, install
> information to get the file content (like you) :
>
> --------------------
>
> public class FreemarkerRunnableProcess extends DLTKRunnableProcess {
>
> public FreemarkerRunnableProcess(IInterpreterInstall install,
> ILaunch launch, InterpreterConfig config) {
> super(install, launch, config);
> }
>
> public void run() {
> File templateFile = super.getFile();
> // do something...
>
> super.out("Write message into console");
> super.err("Write error into console");
> }
> }
> --------------------
>
> After you must extends my AbstractRunnableInterpreterRunner which extends
> DLTK AbstractInterpreterRunner and return instance of RunnableProcess (wich
> is java.lang.Process). I have done that into class
> FreemarkerInterpreterRunner
>
>
> --------------------
> public class FreemarkerInterpreterRunner extends
> AbstractRunnableInterpreterRunner {
>
> public FreemarkerInterpreterRunner(IInterpreterInstall install) {
> super(install);
> }
>
> @Override
> protected RunnableProcess createRunnableProcess(ILaunch launch,
> InterpreterConfig config) {
> return new FreemarkerRunnableProcess(super.getInstall(), launch,
> config);
> }
>
> }
> --------------------
>
> And that's all! You need not create another classes like Mock* you have
> done. Terminate (so the launch is terminated when run is done, you can
> terminate the process if you wish...) is managed with Eclipse Debug class
> RuntimeProcess.
>
> I have tried to clean my code and if you are interested you must get classes
> from the 2 packages :
>
> * /org/eclipse/dltk/launching/
> * /org/eclipse/dltk/internal/launching/
>
> from the folder
>
https://freemarker.svn.sourceforge.net/svnroot/freemarker/sandbox/org.eclipse.dltk.freemarker/org.eclipse.dltk.freemarker.launching/src/org/eclipse/dltk/
>
> If you wish use this code, in your case you must :
>
> 1) add org.eclipse.dltk.debug require bundle into the Marklogic launching
> plugin
> 2) add source of Freemarker SVN (as I have explained below)
> 3) create class MarklogicRunnableProcess like this :
>
> --------------------
>
> package org.eclipse.wst.xquery.internal.launching.marklogic;
>
> import java.io.File;
>
> import org.eclipse.debug.core.ILaunch;
> import org.eclipse.dltk.launching.DLTKRunnableProcess;
> import org.eclipse.dltk.launching.IInterpreterInstall;
> import org.eclipse.dltk.launching.InterpreterConfig;
>
> public class MarklogicRunnableProcess extends DLTKRunnableProcess {
>
> public MarklogicRunnableProcess(IInterpreterInstall install,
> ILaunch launch, InterpreterConfig config) {
> super(install, launch, config);
> }
>
> public void run() {
> File file = super.getFile();
> // copty paste your MarkLogicProcess#run code
>
> }
>
> }
> --------------------
>
> 4) Update your class MarkLogicRunner like this :
>
> --------------------
> package org.eclipse.wst.xquery.internal.launching.marklogic;
>
> import org.eclipse.debug.core.ILaunch;
> import org.eclipse.dltk.launching.AbstractRunnableInterpreterRunner;
> import org.eclipse.dltk.launching.IInterpreterInstall;
> import org.eclipse.dltk.launching.InterpreterConfig;
> import org.eclipse.dltk.launching.RunnableProcess;
>
> public class MarkLogicRunner extends AbstractRunnableInterpreterRunner {
>
> public MarkLogicRunner(IInterpreterInstall install) {
> super(install);
> }
>
> @Override
> protected RunnableProcess createRunnableProcess(ILaunch launch,
> InterpreterConfig config) {
> return new MarklogicRunnableProcess(super.getInstall(), launch,
> config);
> }
>
> }
> --------------------
>
> And that's all!
>
> I think it shoule be better to put AbstractRunnableInterpreterRunner.. into
> org.eclipse.wst.xquery.launching plugin (not sure if it exists) because
> Marklogic need this class but in my case XHive too.
>
> If you like this idea (and if it works for your case), I think it should be
> cool if DLTK could integrate this code.
>
> Don't hesitate to contact me, for more informations.
>
> Regards Angelo
>
>