From: <sha...@us...> - 2009-09-27 13:37:41
|
Revision: 10157 http://exist.svn.sourceforge.net/exist/?rev=10157&view=rev Author: shabanovd Date: 2009-09-27 13:37:34 +0000 (Sun, 27 Sep 2009) Log Message: ----------- [ignore] refactoring, now init message send on first expression. Fix problem "... after first debugger connection ...". Modified Paths: -------------- trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeConnectionTCP.java trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeImpl.java trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeJointImpl.java trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/DGBPProtocolHandler.java trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/AbstractCommandContinuation.java trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/Command.java trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/Init.java trunk/eXist/src/org/exist/debuggee/CommandContinuation.java trunk/eXist/src/org/exist/debuggee/Debuggee.java trunk/eXist/src/org/exist/debuggee/DebuggeeJoint.java trunk/eXist/src/org/exist/debuggee/DummyDebuggee.java Modified: trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeConnectionTCP.java =================================================================== --- trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeConnectionTCP.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeConnectionTCP.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -30,7 +30,6 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector; import org.exist.debuggee.dgbp.DGBPCodecFactory; import org.exist.debuggee.dgbp.DGBPProtocolHandler; -import org.exist.security.xacml.XACMLSource; /** * @author <a href="mailto:sha...@gm...">Dmitriy Shabanov</a> @@ -42,16 +41,8 @@ private int port = 9000; private NioSocketConnector connector; - private IoSession session; - private int status = 0; - private Object lock = new Object(); - - private DebuggeeJoint joint; - - public DebuggeeConnectionTCP(DebuggeeJoint joint, XACMLSource source) { - this.joint = joint; - + public DebuggeeConnectionTCP(Debuggee debuggee) { // Create TCP/IP connector. connector = new NioSocketConnector(); @@ -63,41 +54,19 @@ "protocol", new ProtocolCodecFilter(new DGBPCodecFactory())); // Start communication. - connector.setHandler(new DGBPProtocolHandler(joint, source)); + connector.setHandler(new DGBPProtocolHandler(debuggee)); } - public boolean connect() { - synchronized (lock) { - if (isConnected()) - return true; - - //TODO: should we close session? - - status = 0; - + public IoSession connect() { + synchronized (connector) { try { ConnectFuture future = connector.connect(new InetSocketAddress(host, port)); future.awaitUninterruptibly(); - session = future.getSession(); + return future.getSession(); } catch (RuntimeIoException e) { System.err.println("Failed to connect."); - status = 0; - return false; + return null; } - - joint.reset(); - status = 1; - - return true; } } - - public boolean isConnected() { - //XXX: resolve concurrency problem here!!! - return (status == 2 && connector.isActive()); - } - - public DebuggeeJoint getJoint() { - return joint; - } } Modified: trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeImpl.java =================================================================== --- trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeImpl.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeImpl.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -25,6 +25,8 @@ import java.util.Map; import org.apache.log4j.Logger; +import org.apache.mina.core.session.IoSession; +import org.exist.debuggee.dgbp.packets.Init; import org.exist.xquery.CompiledXQuery; /** @@ -56,31 +58,21 @@ DebuggeeConnectionTCP connection = null; public DebuggeeImpl() { + connection = new DebuggeeConnectionTCP(this); } - public DebuggeeJoint joint(CompiledXQuery compiledXQuery) { - DebuggeeJoint joint = null; - + public void joint(CompiledXQuery compiledXQuery) { synchronized (this) { - if (connection == null) { - joint = new DebuggeeJointImpl(); - connection = new DebuggeeConnectionTCP(joint, compiledXQuery.getSource()); - } + IoSession session = connection.connect(); + + //link debugger session & script + DebuggeeJointImpl joint = new DebuggeeJointImpl(); + + joint.setCompiledScript(compiledXQuery); + compiledXQuery.getContext().setDebuggeeJoint(joint); - if (connection.isConnected()) { - //debugging session is active, for now only one debugging session possible - joint = null; - } else if (!connection.connect()) { - joint = null; - } else { - joint = connection.getJoint(); - } - - + joint.continuation(new Init(session)); } - compiledXQuery.getContext().setDebuggeeJoint(joint); - - return joint; } } Modified: trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeJointImpl.java =================================================================== --- trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeJointImpl.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/extensions/debuggee/src/org/exist/debuggee/DebuggeeJointImpl.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -26,9 +26,10 @@ import java.util.List; import java.util.Map; -import org.exist.debuggee.dgbp.packets.Run; +import org.exist.debuggee.dgbp.packets.Init; import org.exist.debugger.model.Breakpoint; import org.exist.dom.QName; +import org.exist.xquery.CompiledXQuery; import org.exist.xquery.Expression; import org.exist.xquery.TerminatedException; import org.exist.xquery.Variable; @@ -58,9 +59,15 @@ //id, breakpoint private Map<Integer, Breakpoint> breakpoints = new HashMap<Integer, Breakpoint>(); + private CompiledXQuery compiledXQuery; + public DebuggeeJointImpl() { } + protected void setCompiledScript(CompiledXQuery compiledXQuery) { + this.compiledXQuery = compiledXQuery; + } + public void stackEnter(Expression expr) { stack.add(expr); @@ -76,6 +83,9 @@ public void expressionStart(Expression expr) throws TerminatedException { System.out.println("expressionStart " + expr.getLine() + " expr = "+ expr.toString()); + if (compiledXQuery == null) + return; + if (firstExpression == null) firstExpression = expr; @@ -91,17 +101,27 @@ while (true) { //didn't receive any command, wait for any - if (command == null) { + if (command == null && + //the status is break, wait for changes + command.isStatus(BREAK)) { waitCommand(); continue; } + + //wait for connection + if (command.is(CommandContinuation.INIT) && command.isStatus(STARTING)) { + Init init = (Init)command; + init.getSession().setAttribute("joint", this); + init.setFileURI(compiledXQuery.getSource()); + + //break on first line + command.setStatus(BREAK); + } - //the status is break, wait for changes - if (command.isStatus(BREAK)) { - waitCommand(); - continue; - } - + //disconnected + if (compiledXQuery == null) + return; + //stop command, terminate if (command.is(CommandContinuation.STOP) && !command.isStatus(STOPPED)) { command.setStatus(STOPPED); @@ -124,12 +144,8 @@ } } - //break on first line - if (command.is(CommandContinuation.STEP_INTO) && command.isStatus(FIRST_RUN)) - ; - //step-into is done - else if (command.is(CommandContinuation.STEP_INTO) && command.isStatus(RUNNING)) + if (command.is(CommandContinuation.STEP_INTO) && command.isStatus(RUNNING)) command.setStatus(BREAK); //RUS command with status RUNNING can be break only on breakpoints @@ -154,7 +170,10 @@ if (firstExpression == expr) { firstExpression = null; + command.setStatus(STOPPED); + + sessionClosed(true); } } @@ -191,10 +210,7 @@ } public synchronized void continuation(CommandContinuation command) { - if (this.command == null) - command.setStatus(FIRST_RUN); - - else if (firstExpression == null) + if (firstExpression == null && !command.is(CommandContinuation.INIT)) command.setStatus(STOPPED); else @@ -222,7 +238,14 @@ return features.get(name); } - public List<Expression> stackGet() { + public synchronized List<Expression> stackGet() { + //wait, script didn't started + while (stack.size() == 0) + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + return stack; } @@ -307,8 +330,22 @@ return breakpoints; } - public void sessionClosed() { - continuation(new Run(null, "")); + public synchronized void sessionClosed(boolean disconnect) { + System.out.println("sessionClosed"); + + //disconnected already + if (compiledXQuery == null) + return; + + //disconnect debuggee & compiled source + XQueryContext context = compiledXQuery.getContext(); + context.setDebugMode(false); + context.setDebuggeeJoint(null); + compiledXQuery = null; + + if (command != null && disconnect) + command.disconnect(); + + notifyAll(); } - } Modified: trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/DGBPProtocolHandler.java =================================================================== --- trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/DGBPProtocolHandler.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/DGBPProtocolHandler.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -24,10 +24,10 @@ import org.apache.mina.core.service.IoHandlerAdapter; import org.apache.mina.core.session.IdleStatus; import org.apache.mina.core.session.IoSession; +import org.exist.debuggee.Debuggee; import org.exist.debuggee.DebuggeeJoint; import org.exist.debuggee.dgbp.packets.Command; import org.exist.debuggee.dgbp.packets.Init; -import org.exist.debuggee.dgbp.packets.Stop; import org.exist.security.xacml.XACMLSource; /** @@ -36,30 +36,25 @@ */ public class DGBPProtocolHandler extends IoHandlerAdapter { - private DebuggeeJoint joint; - private XACMLSource source; + private Debuggee debuggee; - public DGBPProtocolHandler(DebuggeeJoint joint, XACMLSource source) { + public DGBPProtocolHandler(Debuggee debuggee) { super(); - this.joint = joint; - this.source = source; + this.debuggee = debuggee; } @Override public void sessionOpened(IoSession session) { // Set reader idle time to 10 minutes. session.getConfig().setIdleTime(IdleStatus.READER_IDLE, 10 * 60 * 1000); - - session.setAttribute("joint", joint); - - session.write(new Init(source)); } @Override public void sessionClosed(IoSession session) { DebuggeeJoint joint = (DebuggeeJoint) session.getAttribute("joint"); - joint.sessionClosed(); + if (joint != null) + joint.sessionClosed(false); // Print out total number of bytes read from the remote peer. System.err.println("Total " + session.getReadBytes() + " byte(s)"); Modified: trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/AbstractCommandContinuation.java =================================================================== --- trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/AbstractCommandContinuation.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/AbstractCommandContinuation.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -30,7 +30,7 @@ */ public abstract class AbstractCommandContinuation extends Command implements CommandContinuation { - private String status; + private String status = null; public AbstractCommandContinuation(IoSession session, String args) { super(session, args); @@ -47,7 +47,8 @@ public void setStatus(String status) { this.status = status; - session.write(this); + if (!session.isClosing()) + session.write(this); } public void disconnect() { Modified: trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/Command.java =================================================================== --- trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/Command.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/Command.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -61,6 +61,10 @@ transactionID = val; } + public IoSession getSession() { + return session; + } + protected DebuggeeJoint getJoint() { if (session == null) return null; @@ -166,8 +170,6 @@ } - - return new Error(command, session, args); } Modified: trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/Init.java =================================================================== --- trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/Init.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/extensions/debuggee/src/org/exist/debuggee/dgbp/packets/Init.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -21,21 +21,22 @@ */ package org.exist.debuggee.dgbp.packets; -import java.nio.ByteBuffer; - -import org.exist.debuggee.dgbp.DGBPPacket; +import org.apache.mina.core.session.IoSession; import org.exist.security.xacml.XACMLSource; /** * @author <a href="mailto:sha...@gm...">Dmitriy Shabanov</a> * */ -public class Init extends DGBPPacket { +public class Init extends AbstractCommandContinuation { private XACMLSource fileuri; - public Init(XACMLSource source) { - System.out.println("Init: source = "+source.getKey()); + public Init(IoSession session) { + super(session, ""); + } + + public void setFileURI(XACMLSource source){ fileuri = source; } @@ -56,4 +57,16 @@ return init_message.getBytes(); } + + @Override + public void exec() { + } + + public int getType() { + return INIT; + } + + public boolean is(int type) { + return (type == INIT); + } } Modified: trunk/eXist/src/org/exist/debuggee/CommandContinuation.java =================================================================== --- trunk/eXist/src/org/exist/debuggee/CommandContinuation.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/src/org/exist/debuggee/CommandContinuation.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -29,7 +29,7 @@ public int WAIT = 0; - public int STOP_ON_FIRST_LINE = 1; + public int INIT = 1; public int RUN = 2; @@ -46,4 +46,7 @@ public String getStatus(); public void setStatus(String status); + + //close session + public void disconnect(); } \ No newline at end of file Modified: trunk/eXist/src/org/exist/debuggee/Debuggee.java =================================================================== --- trunk/eXist/src/org/exist/debuggee/Debuggee.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/src/org/exist/debuggee/Debuggee.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -32,5 +32,5 @@ public static final String NAMESPACE_URI = "http://www.xdebug.org/"; public static final String PREFIX = "dbgp"; - public DebuggeeJoint joint(CompiledXQuery compiledXQuery); + public void joint(CompiledXQuery compiledXQuery); } Modified: trunk/eXist/src/org/exist/debuggee/DebuggeeJoint.java =================================================================== --- trunk/eXist/src/org/exist/debuggee/DebuggeeJoint.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/src/org/exist/debuggee/DebuggeeJoint.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; +import org.exist.debuggee.dgbp.packets.Init; import org.exist.debugger.model.Breakpoint; import org.exist.dom.QName; import org.exist.xquery.Expression; @@ -71,5 +72,5 @@ public Breakpoint removeBreakpoint(int breakpointID); - public void sessionClosed(); + public void sessionClosed(boolean disconnect); } Modified: trunk/eXist/src/org/exist/debuggee/DummyDebuggee.java =================================================================== --- trunk/eXist/src/org/exist/debuggee/DummyDebuggee.java 2009-09-27 11:32:30 UTC (rev 10156) +++ trunk/eXist/src/org/exist/debuggee/DummyDebuggee.java 2009-09-27 13:37:34 UTC (rev 10157) @@ -32,8 +32,7 @@ /* (non-Javadoc) * @see org.exist.debuggee.Debuggee#joint() */ - public DebuggeeJoint joint(CompiledXQuery compiledXQuery) { - return null; + public void joint(CompiledXQuery compiledXQuery) { } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |