diff --git a/build.xml b/build.xml index c924ed6f..24c8ba65 100644 --- a/build.xml +++ b/build.xml @@ -1,5 +1,5 @@ - + diff --git a/src/debug/org/luaj/debug/DebugLuaState.java b/src/debug/org/luaj/debug/DebugLuaState.java index 5fb9a0c3..8150e070 100644 --- a/src/debug/org/luaj/debug/DebugLuaState.java +++ b/src/debug/org/luaj/debug/DebugLuaState.java @@ -26,17 +26,13 @@ import java.util.Hashtable; import java.util.Vector; import org.luaj.compiler.LexState; -import org.luaj.debug.event.DebugEvent; import org.luaj.debug.event.DebugEventBreakpoint; import org.luaj.debug.event.DebugEventError; -import org.luaj.debug.event.DebugEventType; import org.luaj.debug.net.DebugSupport; -import org.luaj.debug.request.DebugRequest; import org.luaj.debug.request.DebugRequestDisconnect; import org.luaj.debug.request.DebugRequestLineBreakpointToggle; import org.luaj.debug.request.DebugRequestListener; import org.luaj.debug.request.DebugRequestStack; -import org.luaj.debug.request.DebugRequestType; import org.luaj.debug.response.DebugResponseCallgraph; import org.luaj.debug.response.DebugResponseStack; import org.luaj.debug.response.DebugResponseVariables; @@ -241,7 +237,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener { private void cancelStepping() { if (debugSupport != null) { debugSupport.notifyDebugEvent( - new DebugEvent(DebugEventType.resumedOnSteppingEnd)); + new DebugMessage(DebugMessageType.resumedOnSteppingEnd)); } stepping = STEP_NONE; steppingFrame = -1; @@ -250,8 +246,8 @@ public class DebugLuaState extends LuaState implements DebugRequestListener { private void suspendOnStepping() { if (debugSupport != null) { - debugSupport.notifyDebugEvent(new DebugEvent( - DebugEventType.suspendedOnStepping)); + debugSupport.notifyDebugEvent( + new DebugMessage(DebugMessageType.suspendedOnStepping)); } suspended = true; steppingFrame = -1; @@ -274,7 +270,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener { // ------------------ commands coming from the debugger ------------------- - public void handleRequest(DebugRequest request) { + public void handleRequest(DebugMessage request) { if (this.debugSupport == null) { throw new IllegalStateException( "DebugSupport must be defined."); @@ -284,65 +280,67 @@ public class DebugLuaState extends LuaState implements DebugRequestListener { System.out.println("DebugStackState is handling request: " + request.toString()); - DebugRequestType requestType = request.getType(); - if (DebugRequestType.start == requestType) { - DebugEvent event = new DebugEvent(DebugEventType.started); + DebugMessageType requestType = request.getType(); + if (DebugMessageType.start == requestType) { + DebugMessage event = new DebugMessage(DebugMessageType.started); debugSupport.notifyDebugEvent(event); cancelSuspendOnStart(); - } else if (DebugRequestType.exit == requestType) { + } else if (DebugMessageType.exit == requestType) { stop(); - } else if (DebugRequestType.disconnect == requestType) { + } else if (DebugMessageType.disconnect == requestType) { DebugRequestDisconnect disconnectRequest = (DebugRequestDisconnect) request; int connectionId = disconnectRequest.getSessionId(); disconnect(connectionId); - } else if (DebugRequestType.reset == requestType) { + } else if (DebugMessageType.debugServiceDown == requestType) { + disconnectFromDebugService(); + } else if (DebugMessageType.reset == requestType) { reset(); - } else if (DebugRequestType.suspend == requestType) { + } else if (DebugMessageType.suspend == requestType) { suspend(); - DebugEvent event = new DebugEvent(DebugEventType.suspendedByClient); + DebugMessage event = new DebugMessage(DebugMessageType.suspendedByClient); debugSupport.notifyDebugEvent(event); - } else if (DebugRequestType.resume == requestType) { + } else if (DebugMessageType.resume == requestType) { resume(); - DebugEvent event = new DebugEvent(DebugEventType.resumedByClient); + DebugMessage event = new DebugMessage(DebugMessageType.resumedByClient); debugSupport.notifyDebugEvent(event); - } else if (DebugRequestType.lineBreakpointSet == requestType) { + } else if (DebugMessageType.lineBreakpointSet == requestType) { DebugRequestLineBreakpointToggle setBreakpointRequest = (DebugRequestLineBreakpointToggle) request; setBreakpoint(setBreakpointRequest.getSource(), setBreakpointRequest.getLineNumber()); - } else if (DebugRequestType.lineBreakpointClear == requestType) { + } else if (DebugMessageType.lineBreakpointClear == requestType) { DebugRequestLineBreakpointToggle clearBreakpointRequest = (DebugRequestLineBreakpointToggle) request; clearBreakpoint(clearBreakpointRequest.getSource(), clearBreakpointRequest.getLineNumber()); - } else if (DebugRequestType.callgraph == requestType) { + } else if (DebugMessageType.callgraph == requestType) { DebugResponseCallgraph callgraph = new DebugResponseCallgraph(getCallgraph()); debugSupport.notifyDebugEvent(callgraph); - } else if (DebugRequestType.stack == requestType) { + } else if (DebugMessageType.stack == requestType) { DebugRequestStack stackRequest = (DebugRequestStack) request; int index = stackRequest.getIndex(); DebugResponseStack stackState = new DebugResponseStack(index, getStack(index)); debugSupport.notifyDebugEvent(stackState); - } else if (DebugRequestType.global == requestType) { + } else if (DebugMessageType.global == requestType) { DebugResponseVariables globals - = new DebugResponseVariables(getGlobals(), DebugEventType.clientRequestGlobalReply); + = new DebugResponseVariables(getGlobals(), DebugMessageType.clientRequestGlobalReply); debugSupport.notifyDebugEvent(globals); - } else if (DebugRequestType.stepInto == requestType) { - DebugEvent event = new DebugEvent( - DebugEventType.resumedOnSteppingInto); + } else if (DebugMessageType.stepInto == requestType) { + DebugMessage event = new DebugMessage( + DebugMessageType.resumedOnSteppingInto); debugSupport.notifyDebugEvent(event); stepInto(); - } else if (DebugRequestType.stepOver == requestType) { - DebugEvent event = new DebugEvent( - DebugEventType.resumedOnSteppingOver); + } else if (DebugMessageType.stepOver == requestType) { + DebugMessage event = new DebugMessage( + DebugMessageType.resumedOnSteppingOver); debugSupport.notifyDebugEvent(event); stepOver(); - } else if (DebugRequestType.stepReturn == requestType) { - DebugEvent event = new DebugEvent( - DebugEventType.resumedOnSteppingReturn); + } else if (DebugMessageType.stepReturn == requestType) { + DebugMessage event = new DebugMessage( + DebugMessageType.resumedOnSteppingReturn); debugSupport.notifyDebugEvent(event); stepReturn(); } else { @@ -393,16 +391,20 @@ public class DebugLuaState extends LuaState implements DebugRequestListener { * VM execution. */ public void stop() { - if (this.debugSupport == null) { - throw new IllegalStateException( - "DebugSupport must be defined."); - } + synchronized (this) { + if (exiting) return; + + if (this.debugSupport == null) { + throw new IllegalStateException( + "DebugSupport must be defined."); + } - DebugEvent event = new DebugEvent(DebugEventType.terminated); - debugSupport.notifyDebugEvent(event); - exit(); - debugSupport.stop(); - debugSupport = null; + DebugMessage event = new DebugMessage(DebugMessageType.terminated); + debugSupport.notifyDebugEvent(event); + exit(); + debugSupport.stop(); + debugSupport = null; + } } public void disconnect(int connectionId) { @@ -412,11 +414,21 @@ public class DebugLuaState extends LuaState implements DebugRequestListener { } reset(); - DebugEvent event = new DebugEvent(DebugEventType.disconnected); + DebugMessage event = new DebugMessage(DebugMessageType.disconnected); debugSupport.notifyDebugEvent(event); debugSupport.disconnect(connectionId); } + public void disconnectFromDebugService() { + if (this.debugSupport == null) { + throw new IllegalStateException( + "DebugSupport must be defined."); + } + + reset(); + debugSupport.disconnect(); + } + public void reset() { synchronized (this) { this.breakpoints.clear(); diff --git a/src/debug/org/luaj/debug/DebugMessage.java b/src/debug/org/luaj/debug/DebugMessage.java new file mode 100644 index 00000000..c69e2524 --- /dev/null +++ b/src/debug/org/luaj/debug/DebugMessage.java @@ -0,0 +1,41 @@ +package org.luaj.debug; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class DebugMessage implements Serializable { + protected DebugMessageType type; + + public DebugMessage(DebugMessageType type) { + this.type = type; + } + + public DebugMessageType getType() { + return type; + } + + public void setType(DebugMessageType type) { + this.type = type; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + public String toString() { + return type.toString(); + } + + public static void serialize(DataOutputStream out, DebugMessage object) + throws IOException { + SerializationHelper.serialize(object.getType(), out); + } + + public static DebugMessage deserialize(DataInputStream in) throws IOException { + DebugMessageType type = (DebugMessageType) SerializationHelper + .deserialize(in); + return new DebugMessage(type); + } +} diff --git a/src/debug/org/luaj/debug/DebugMessageType.java b/src/debug/org/luaj/debug/DebugMessageType.java new file mode 100644 index 00000000..0b3a7287 --- /dev/null +++ b/src/debug/org/luaj/debug/DebugMessageType.java @@ -0,0 +1,123 @@ +/******************************************************************************* +* Copyright (c) 2007 LuaJ. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ +package org.luaj.debug; + +import java.io.DataInputStream; +import java.io.IOException; + + +public class DebugMessageType extends EnumType { + // requests + public static final DebugMessageType start = new DebugMessageType("start", 0); + public static final DebugMessageType resume = new DebugMessageType("resume", 1); + public static final DebugMessageType suspend = new DebugMessageType("suspend", 2); + public static final DebugMessageType exit = new DebugMessageType("exit", 3); + public static final DebugMessageType lineBreakpointSet = new DebugMessageType("lineBreakpointSet", 4); + public static final DebugMessageType lineBreakpointClear = new DebugMessageType("lineBreakpointClear", 5); + public static final DebugMessageType watchpointSet = new DebugMessageType("watchpointSet", 6); + public static final DebugMessageType watchpointClear = new DebugMessageType("watchpointClear", 7); + public static final DebugMessageType callgraph = new DebugMessageType("callgraph", 8); + public static final DebugMessageType stack = new DebugMessageType("stack", 9); + public static final DebugMessageType stepInto = new DebugMessageType("stepInto", 10); + public static final DebugMessageType stepOver = new DebugMessageType("stepOver", 11); + public static final DebugMessageType stepReturn = new DebugMessageType("stepReturn", 12); + public static final DebugMessageType global = new DebugMessageType("global", 13); + public static final DebugMessageType disconnect = new DebugMessageType("disconnect", 14); + public static final DebugMessageType reset = new DebugMessageType("reset", 15); + public static final DebugMessageType session = new DebugMessageType("session", 16); + + // events + public static final DebugMessageType started = new DebugMessageType("started", 17); + public static final DebugMessageType suspendedByClient = new DebugMessageType("suspendedByClient", 18); + public static final DebugMessageType suspendedOnBreakpoint = new DebugMessageType("suspendedOnBreakpoint", 19); + public static final DebugMessageType suspendedOnWatchpoint = new DebugMessageType("suspendedOnWatchpoint", 20); + public static final DebugMessageType suspendedOnStepping = new DebugMessageType("suspendedOnStepping", 21); + public static final DebugMessageType suspendedOnError = new DebugMessageType("suspendedOnError", 22); + public static final DebugMessageType resumedByClient = new DebugMessageType("resumedByClient", 23); + public static final DebugMessageType resumedOnSteppingInto = new DebugMessageType("resumedOnSteppingInto", 24); + public static final DebugMessageType resumedOnSteppingOver = new DebugMessageType("resumedOnSteppingOver", 25); + public static final DebugMessageType resumedOnSteppingReturn = new DebugMessageType("resumedOnSteppingReturn", 26); + public static final DebugMessageType resumedOnSteppingEnd = new DebugMessageType("resumedOnSteppingEnd", 27); + public static final DebugMessageType resumedOnError = new DebugMessageType("resumedOnError", 28); + public static final DebugMessageType error = new DebugMessageType("error", 29); + public static final DebugMessageType terminated = new DebugMessageType("terminated", 30); + public static final DebugMessageType clientRequestCallgraphReply = new DebugMessageType("clientRequestCallgraphReply", 31); + public static final DebugMessageType clientRequestStackReply = new DebugMessageType("clientRequestStackReply", 32); + public static final DebugMessageType clientRequestGlobalReply = new DebugMessageType("clientRequestGlobalReply", 33); + public static final DebugMessageType disconnected = new DebugMessageType("disconnected", 34); + public static final DebugMessageType sessionId = new DebugMessageType("sessionId", 35); + public static final DebugMessageType debugServiceDown = new DebugMessageType("debugServiceDown", 36); + + protected static DebugMessageType[] ENUMS = new DebugMessageType[] { + start, + resume, + suspend, + exit, + lineBreakpointSet, + lineBreakpointClear, + watchpointSet, + watchpointClear, + callgraph, + stack, + stepInto, + stepOver, + stepReturn, + global, + disconnect, + reset, + session, + started, + suspendedByClient, + suspendedOnBreakpoint, + suspendedOnWatchpoint, + suspendedOnStepping, + suspendedOnError, + resumedByClient, + resumedOnSteppingInto, + resumedOnSteppingOver, + resumedOnSteppingReturn, + resumedOnSteppingEnd, + resumedOnError, + error, + terminated, + clientRequestCallgraphReply, + clientRequestStackReply, + clientRequestGlobalReply, + disconnected, + sessionId, + debugServiceDown + }; + + protected DebugMessageType(String name, int ordinal) { + super(name, ordinal); + } + + public static DebugMessageType deserialize(DataInputStream in) + throws IOException { + int ordinal = in.readInt(); + if (ordinal < 0 || ordinal >= ENUMS.length) { + throw new RuntimeException( + "DebugMessageType: ordinal is out of the range."); + } + return ENUMS[ordinal]; + } +} diff --git a/src/debug/org/luaj/debug/SerializationHelper.java b/src/debug/org/luaj/debug/SerializationHelper.java index 2591396a..8cb80144 100644 --- a/src/debug/org/luaj/debug/SerializationHelper.java +++ b/src/debug/org/luaj/debug/SerializationHelper.java @@ -6,15 +6,11 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import org.luaj.debug.event.DebugEvent; import org.luaj.debug.event.DebugEventBreakpoint; import org.luaj.debug.event.DebugEventError; -import org.luaj.debug.event.DebugEventType; -import org.luaj.debug.request.DebugRequest; import org.luaj.debug.request.DebugRequestDisconnect; import org.luaj.debug.request.DebugRequestLineBreakpointToggle; import org.luaj.debug.request.DebugRequestStack; -import org.luaj.debug.request.DebugRequestType; import org.luaj.debug.response.DebugResponseCallgraph; import org.luaj.debug.response.DebugResponseSession; import org.luaj.debug.response.DebugResponseStack; @@ -52,19 +48,17 @@ public class SerializationHelper { static final int SERIAL_TYPE_TableVariable = 1; static final int SERIAL_TYPE_Variable = 2; static final int SERIAL_TYPE_StackFrame = 3; - static final int SERIAL_TYPE_DebugRequestType = 4; - static final int SERIAL_TYPE_DebugRequest = 5; + static final int SERIAL_TYPE_DebugMessageType = 4; + static final int SERIAL_TYPE_DebugMessage = 5; static final int SERIAL_TYPE_DebugRequestStack = 6; static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 7; static final int SERIAL_TYPE_DebugRequestDisconnect = 8; - static final int SERIAL_TYPE_DebugEventType = 9; - static final int SERIAL_TYPE_DebugEvent = 10; - static final int SERIAL_TYPE_DebugEventBreakpoint = 11; - static final int SERIAL_TYPE_DebugEventError = 12; - static final int SERIAL_TYPE_DebugResponseCallgraph = 13; - static final int SERIAL_TYPE_DebugResponseVariables = 14; - static final int SERIAL_TYPE_DebugResponseStack = 15; - static final int SERIAL_TYPE_DebugResponseSession = 16; + static final int SERIAL_TYPE_DebugEventBreakpoint = 9; + static final int SERIAL_TYPE_DebugEventError = 10; + static final int SERIAL_TYPE_DebugResponseCallgraph = 11; + static final int SERIAL_TYPE_DebugResponseVariables = 12; + static final int SERIAL_TYPE_DebugResponseStack = 13; + static final int SERIAL_TYPE_DebugResponseSession = 14; public static void serialize(Serializable object, DataOutputStream dout) throws IOException { @@ -80,9 +74,9 @@ public class SerializationHelper { } else if (object instanceof StackFrame) { dout.writeInt(SERIAL_TYPE_StackFrame); StackFrame.serialize(dout, (StackFrame) object); - } else if (object instanceof DebugRequestType) { - dout.writeInt(SERIAL_TYPE_DebugRequestType); - DebugRequestType.serialize(dout, (DebugRequestType) object); + } else if (object instanceof DebugMessageType) { + dout.writeInt(SERIAL_TYPE_DebugMessageType); + DebugMessageType.serialize(dout, (DebugMessageType) object); } else if (object instanceof DebugRequestStack) { dout.writeInt(SERIAL_TYPE_DebugRequestStack); DebugRequestStack.serialize(dout, (DebugRequestStack) object); @@ -93,12 +87,6 @@ public class SerializationHelper { } else if (object instanceof DebugRequestDisconnect) { dout.writeInt(SERIAL_TYPE_DebugRequestDisconnect); DebugRequestDisconnect.serialize(dout, (DebugRequestDisconnect) object); - } else if (object instanceof DebugRequest) { - dout.writeInt(SERIAL_TYPE_DebugRequest); - DebugRequest.serialize(dout, (DebugRequest) object); - } else if (object instanceof DebugEventType) { - dout.writeInt(SERIAL_TYPE_DebugEventType); - DebugEventType.serialize(dout, (DebugEventType) object); } else if (object instanceof DebugEventBreakpoint) { dout.writeInt(SERIAL_TYPE_DebugEventBreakpoint); DebugEventBreakpoint.serialize(dout, (DebugEventBreakpoint) object); @@ -118,9 +106,9 @@ public class SerializationHelper { } else if (object instanceof DebugResponseSession) { dout.writeInt(SERIAL_TYPE_DebugResponseSession); DebugResponseSession.serialize(dout, (DebugResponseSession) object); - } else if (object instanceof DebugEvent) { - dout.writeInt(SERIAL_TYPE_DebugEvent); - DebugEvent.serialize(dout, (DebugEvent) object); + } else if (object instanceof DebugMessage) { + dout.writeInt(SERIAL_TYPE_DebugMessage); + DebugMessage.serialize(dout, (DebugMessage) object); } else { // catch the errors: forgot to implement // serialization/deserialization @@ -146,9 +134,9 @@ public class SerializationHelper { case SERIAL_TYPE_StackFrame: object = StackFrame.deserialize(din); break; - case SERIAL_TYPE_DebugRequestType: - object = DebugRequestType.deserialize(din); - break; + case SERIAL_TYPE_DebugMessageType: + object = DebugMessageType.deserialize(din); + break; case SERIAL_TYPE_DebugRequestStack: object = DebugRequestStack.deserialize(din); break; @@ -158,12 +146,6 @@ public class SerializationHelper { case SERIAL_TYPE_DebugRequestDisconnect: object = DebugRequestDisconnect.deserialize(din); break; - case SERIAL_TYPE_DebugRequest: - object = DebugRequest.deserialize(din); - break; - case SERIAL_TYPE_DebugEventType: - object = DebugEventType.deserialize(din); - break; case SERIAL_TYPE_DebugEventBreakpoint: object = DebugEventBreakpoint.deserialize(din); break; @@ -182,8 +164,8 @@ public class SerializationHelper { case SERIAL_TYPE_DebugResponseSession: object = DebugResponseSession.deserialize(din); break; - case SERIAL_TYPE_DebugEvent: - object = DebugEvent.deserialize(din); + case SERIAL_TYPE_DebugMessage: + object = DebugMessage.deserialize(din); break; default: throw new RuntimeException( diff --git a/src/debug/org/luaj/debug/event/DebugEvent.java b/src/debug/org/luaj/debug/event/DebugEvent.java deleted file mode 100644 index 4fbfbf40..00000000 --- a/src/debug/org/luaj/debug/event/DebugEvent.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -package org.luaj.debug.event; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.Serializable; -import org.luaj.debug.SerializationHelper; - - -public class DebugEvent implements Serializable { - - protected DebugEventType type; - - public DebugEvent(DebugEventType type) { - this.type = type; - } - - public DebugEventType getType() { - return type; - } - - public void setType(DebugEventType type) { - this.type = type; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - public String toString() { - return type.toString(); - } - - public static void serialize(DataOutputStream out, DebugEvent object) - throws IOException { - SerializationHelper.serialize(object.getType(), out); - } - - public static DebugEvent deserialize(DataInputStream in) throws IOException { - DebugEventType type = (DebugEventType) SerializationHelper - .deserialize(in); - return new DebugEvent(type); - } -} diff --git a/src/debug/org/luaj/debug/event/DebugEventBreakpoint.java b/src/debug/org/luaj/debug/event/DebugEventBreakpoint.java index 39e10eec..ff412dfa 100644 --- a/src/debug/org/luaj/debug/event/DebugEventBreakpoint.java +++ b/src/debug/org/luaj/debug/event/DebugEventBreakpoint.java @@ -25,13 +25,16 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -public class DebugEventBreakpoint extends DebugEvent { +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; + +public class DebugEventBreakpoint extends DebugMessage { protected String source; protected int lineNumber; public DebugEventBreakpoint(String source, int lineNumber) { - super(DebugEventType.suspendedOnBreakpoint); + super(DebugMessageType.suspendedOnBreakpoint); if (source == null) { throw new IllegalArgumentException("argument source cannot be null"); } @@ -69,7 +72,7 @@ public class DebugEventBreakpoint extends DebugEvent { out.writeInt(object.getLineNumber()); } - public static DebugEvent deserialize(DataInputStream in) throws IOException { + public static DebugMessage deserialize(DataInputStream in) throws IOException { String source = in.readUTF(); int lineNo = in.readInt(); diff --git a/src/debug/org/luaj/debug/event/DebugEventError.java b/src/debug/org/luaj/debug/event/DebugEventError.java index 582c5396..da72648d 100644 --- a/src/debug/org/luaj/debug/event/DebugEventError.java +++ b/src/debug/org/luaj/debug/event/DebugEventError.java @@ -25,12 +25,15 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -public class DebugEventError extends DebugEvent { +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; + +public class DebugEventError extends DebugMessage { protected String cause; protected String trace; public DebugEventError(String cause, String trace) { - super(DebugEventType.error); + super(DebugMessageType.error); this.cause = cause; this.trace = trace; } @@ -58,7 +61,7 @@ public class DebugEventError extends DebugEvent { out.writeUTF(object.getTrace()); } - public static DebugEvent deserialize(DataInputStream in) throws IOException { + public static DebugMessage deserialize(DataInputStream in) throws IOException { String detail = in.readUTF(); String trace = in.readUTF(); return new DebugEventError(detail, trace); diff --git a/src/debug/org/luaj/debug/event/DebugEventListener.java b/src/debug/org/luaj/debug/event/DebugEventListener.java index d0e65bb1..5d7023a3 100644 --- a/src/debug/org/luaj/debug/event/DebugEventListener.java +++ b/src/debug/org/luaj/debug/event/DebugEventListener.java @@ -21,6 +21,8 @@ ******************************************************************************/ package org.luaj.debug.event; +import org.luaj.debug.DebugMessage; + public interface DebugEventListener { - public void notifyDebugEvent(DebugEvent event); + public void notifyDebugEvent(DebugMessage event); } diff --git a/src/debug/org/luaj/debug/event/DebugEventType.java b/src/debug/org/luaj/debug/event/DebugEventType.java deleted file mode 100644 index 3e0af5d6..00000000 --- a/src/debug/org/luaj/debug/event/DebugEventType.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug.event; - -import java.io.DataInputStream; -import java.io.IOException; - -import org.luaj.debug.EnumType; - - - -public class DebugEventType extends EnumType { - public static DebugEventType started = new DebugEventType("started", 0); - public static DebugEventType suspendedByClient = new DebugEventType("suspendedByClient", 1); - public static DebugEventType suspendedOnBreakpoint = new DebugEventType("suspendedOnBreakpoint", 2); - public static DebugEventType suspendedOnWatchpoint = new DebugEventType("suspendedOnWatchpoint", 3); - public static DebugEventType suspendedOnStepping = new DebugEventType("suspendedOnStepping", 4); - public static DebugEventType suspendedOnError = new DebugEventType("suspendedOnError", 5); - public static DebugEventType resumedByClient = new DebugEventType("resumedByClient", 6); - public static DebugEventType resumedOnSteppingInto = new DebugEventType("resumedOnSteppingInto", 7); - public static DebugEventType resumedOnSteppingOver = new DebugEventType("resumedOnSteppingOver", 8); - public static DebugEventType resumedOnSteppingReturn = new DebugEventType("resumedOnSteppingReturn", 9); - public static DebugEventType resumedOnSteppingEnd = new DebugEventType("resumedOnSteppingEnd", 10); - public static DebugEventType resumedOnError = new DebugEventType("resumedOnError", 11); - public static DebugEventType error = new DebugEventType("error", 12); - public static DebugEventType terminated = new DebugEventType("terminated", 13); - public static DebugEventType clientRequestCallgraphReply - = new DebugEventType("clientRequestCallgraphReply", 14); - public static DebugEventType clientRequestStackReply - = new DebugEventType("clientRequestStackReply", 15); - public static DebugEventType clientRequestGlobalReply - = new DebugEventType("clientRequestGlobalReply", 16); - public static DebugEventType disconnected - = new DebugEventType("disconnected", 17); - public static DebugEventType session - = new DebugEventType("session", 17); - - protected static DebugEventType[] ENUMS = new DebugEventType[] { - started, - suspendedByClient, - suspendedOnBreakpoint, - suspendedOnWatchpoint, - suspendedOnStepping, - suspendedOnError, - resumedByClient, - resumedOnSteppingInto, - resumedOnSteppingOver, - resumedOnSteppingReturn, - resumedOnSteppingEnd, - resumedOnError, - error, - terminated, - clientRequestCallgraphReply, - clientRequestStackReply, - clientRequestGlobalReply, - disconnected, - session - }; - - protected DebugEventType(String name, int ordinal) { - super(name, ordinal); - } - - public static DebugEventType deserialize(DataInputStream in) - throws IOException { - int ordinal = in.readInt(); - if (ordinal < 0 || ordinal >= ENUMS.length) { - throw new RuntimeException("DebugEventType: ordinal is out of the range."); - } - return ENUMS[ordinal]; - } -} diff --git a/src/debug/org/luaj/debug/net/DebugSupport.java b/src/debug/org/luaj/debug/net/DebugSupport.java index b7db57c1..30c27d34 100644 --- a/src/debug/org/luaj/debug/net/DebugSupport.java +++ b/src/debug/org/luaj/debug/net/DebugSupport.java @@ -3,16 +3,55 @@ package org.luaj.debug.net; import java.io.IOException; import org.luaj.debug.DebugLuaState; +import org.luaj.debug.DebugMessage; import org.luaj.debug.event.DebugEventListener; import org.luaj.debug.request.DebugRequestListener; /** - * DebugSupport provides the network communication support for the debugger and - * debug clients. + * DebugSupport provides the network communication support between the luaj-vm + * and debug clients. */ -public interface DebugSupport extends DebugRequestListener, DebugEventListener { - public void start() throws IOException; - public void stop(); - public void setDebugStackState(DebugLuaState vm); - public void disconnect(int id); +public abstract class DebugSupport implements DebugRequestListener, DebugEventListener { + + public abstract void start() throws IOException; + + public abstract void stop(); + + /** + * Disconnect all connected clients. + */ + public abstract void disconnect(); + + /** + * Disconnect the client with the given id. + * @param id -- client id + */ + public abstract void disconnect(int id); + + protected DebugLuaState vm; + public void setDebugStackState(DebugLuaState vm) { + this.vm = vm; + } + + /* + * (non-Javadoc) + * + * @see org.luaj.debug.request.DebugRequestListener#handleRequest(org.luaj.debug.request.DebugRequest) + */ + public void handleRequest(DebugMessage request) { + vm.handleRequest(request); + } + + protected static final int UNKNOWN = 0; + protected static final int RUNNING = 1; + protected static final int STOPPED = 2; + + protected int state = UNKNOWN; + protected synchronized void setState(int state) { + this.state = state; + } + + protected synchronized boolean isRunning() { + return this.state == RUNNING; + } } \ No newline at end of file diff --git a/src/debug/org/luaj/debug/net/j2me/ClientConnectionTask.java b/src/debug/org/luaj/debug/net/j2me/ClientConnectionTask.java new file mode 100644 index 00000000..63f2b37d --- /dev/null +++ b/src/debug/org/luaj/debug/net/j2me/ClientConnectionTask.java @@ -0,0 +1,141 @@ +package org.luaj.debug.net.j2me; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.EOFException; +import java.io.IOException; + +import javax.microedition.io.Connector; +import javax.microedition.io.SocketConnection; + +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; +import org.luaj.debug.SerializationHelper; +import org.luaj.debug.event.DebugEventListener; +import org.luaj.debug.response.DebugResponseSession; + +public class ClientConnectionTask implements Runnable, DebugEventListener { + private static final boolean TRACE = true; //(null != System.getProperty("TRACE")); + + protected String host; + protected int port; + DebugSupportImpl debugSupport; + protected boolean bDisconnected = false; + + protected SocketConnection connection; + protected DataInputStream inStream; + protected DataOutputStream outStream; + + public ClientConnectionTask(String host, int port, DebugSupportImpl debugSupport) { + this.host = host; + this.port = port; + this.debugSupport = debugSupport; + } + + public synchronized void disconnect () { + this.bDisconnected = true; + if (this.inStream != null) { + try { + inStream.close(); + } catch (IOException e) {} + } + } + + public boolean isDisconnected() { + return this.bDisconnected; + } + + public void run() { + try { + if ( TRACE ) + System.out.println("LuaJ debug server connecting to " + host + ":" + port); + + // create connection + this.connection = (SocketConnection) + Connector.open("socket://" + host + ":" + port); + this.inStream = connection.openDataInputStream(); + this.outStream = connection.openDataOutputStream(); + + if ( TRACE ) + System.out.println("LuaJ debug server connected to " + host + ":" + port); + + // loop for incoming requests + while ( !isDisconnected() ) { + byte[] data = null; + int size = inStream.readInt(); + data = new byte[size]; + inStream.readFully(data); + + DebugMessage request = (DebugMessage) SerializationHelper + .deserialize(data); + if ( TRACE ) + System.out.println("SERVER receives request: " + request.toString()); + + handleRequest(request); + } + } catch (EOFException e) { + // client has terminated the connection + // it's time to exit. + } catch (IOException e) { + e.printStackTrace(); + + // if the connected debugging client aborted abnormally, + // discard the current connection. + handleRequest(new DebugMessage(DebugMessageType.reset)); + + debugSupport.disconnect(1); + } finally { + dispose(); + } + } + + protected void dispose() { + if (this.inStream != null) { + try { + inStream.close(); + inStream = null; + } catch (IOException e) {} + } + + if (this.outStream != null) { + try { + outStream.close(); + outStream = null; + } catch (IOException e) {} + } + + if (this.connection != null) { + try { + connection.close(); + connection = null; + } catch (IOException e) {} + } + } + + public void handleRequest(DebugMessage request) { + if ( TRACE ) + System.out.println("SERVER handling request: " + request.toString()); + + if (request.getType() == DebugMessageType.session) { + notifyDebugEvent(new DebugResponseSession(1)); + } else { + debugSupport.handleRequest(request); + } + } + + public void notifyDebugEvent(DebugMessage event) { + if (outStream == null) return; + + if ( TRACE ) + System.out.println("SERVER sending event: " + event.toString()); + + try { + byte[] data = SerializationHelper.serialize(event); + outStream.writeInt(data.length); + outStream.write(data); + outStream.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/debug/org/luaj/debug/net/j2me/DebugSupportImpl.java b/src/debug/org/luaj/debug/net/j2me/DebugSupportImpl.java index 85fab27f..784e4201 100644 --- a/src/debug/org/luaj/debug/net/j2me/DebugSupportImpl.java +++ b/src/debug/org/luaj/debug/net/j2me/DebugSupportImpl.java @@ -2,74 +2,71 @@ package org.luaj.debug.net.j2me; import java.io.IOException; -import javax.microedition.io.Connector; -import javax.microedition.io.ServerSocketConnection; -import javax.microedition.io.SocketConnection; - -import org.luaj.debug.DebugLuaState; -import org.luaj.debug.event.DebugEvent; +import org.luaj.debug.DebugMessage; import org.luaj.debug.net.DebugSupport; -import org.luaj.debug.request.DebugRequest; -public class DebugSupportImpl implements DebugSupport { - protected ServerSocketConnection serverConnection; +/** + * J2ME version of DebugSupport implementation. The vm will connect to a debug + * service hosted on a remote machine and have the debug service relay the + * debugging messages between the vm and the debug client. + */ +public class DebugSupportImpl extends DebugSupport { + protected String host; + protected int port; + ClientConnectionTask clientTask; + Thread main; - public DebugSupportImpl(int port) throws IOException { - this.serverConnection - = (ServerSocketConnection) Connector.open( - "socket://:" + port); - } - - public synchronized void acceptClientConnection() - throws IOException { - // Set up the request socket and request input + event output streams - SocketConnection clientDebugConnection - = (SocketConnection) serverConnection.acceptAndOpen(); - clientDebugConnection.setSocketOption(SocketConnection.DELAY, 0); - clientDebugConnection.setSocketOption(SocketConnection.LINGER, 0); - clientDebugConnection.setSocketOption(SocketConnection.KEEPALIVE, 1); - clientDebugConnection.setSocketOption(SocketConnection.RCVBUF, 1024); - clientDebugConnection.setSocketOption(SocketConnection.SNDBUF, 1024); - //TODO.... - } - - protected void dispose() { - if (this.serverConnection != null) { - try { - serverConnection.close(); - serverConnection = null; - } catch (IOException e) { - } - } - } - - public void disconnect(int id) { - // TODO Auto-generated method stub - - } - - public void setDebugStackState(DebugLuaState vm) { - // TODO Auto-generated method stub - + public DebugSupportImpl(String host, int port) throws IOException { + this.host = host; + this.port = port; } public void start() throws IOException { - // TODO Auto-generated method stub - + setState(RUNNING); + main = new Thread(new Runnable() { + public void run() { + while ( isRunning() ) { + synchronized (DebugSupportImpl.this) { + if ( clientTask == null ) { + clientTask = new ClientConnectionTask(host, port, DebugSupportImpl.this); + new Thread(clientTask).start(); + } + } + + synchronized(main) { + try { + main.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + }); + main.start(); } + public void stop() { - // TODO Auto-generated method stub - + setState(STOPPED); + disconnect(1); } - public void handleRequest(DebugRequest request) { - // TODO Auto-generated method stub - + public void disconnect() { + clientTask.disconnect(); + clientTask = null; + synchronized(main) { + main.notify(); + } + } + + public synchronized void disconnect(int id) { + disconnect(); } - public void notifyDebugEvent(DebugEvent event) { - // TODO Auto-generated method stub - + public synchronized void notifyDebugEvent(DebugMessage event) { + if (clientTask != null) { + clientTask.notifyDebugEvent(event); + } } } diff --git a/src/debug/org/luaj/debug/net/j2se/ClientConnectionTask.java b/src/debug/org/luaj/debug/net/j2se/ClientConnectionTask.java index 657e1a2b..ed1761e3 100644 --- a/src/debug/org/luaj/debug/net/j2se/ClientConnectionTask.java +++ b/src/debug/org/luaj/debug/net/j2se/ClientConnectionTask.java @@ -6,11 +6,10 @@ import java.io.EOFException; import java.io.IOException; import java.net.Socket; +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; import org.luaj.debug.SerializationHelper; -import org.luaj.debug.event.DebugEvent; import org.luaj.debug.event.DebugEventListener; -import org.luaj.debug.request.DebugRequest; -import org.luaj.debug.request.DebugRequestType; import org.luaj.debug.response.DebugResponseSession; public class ClientConnectionTask implements Runnable, DebugEventListener { @@ -23,6 +22,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener { protected DataInputStream requestReader; protected DataOutputStream eventWriter; protected DebugSupportImpl debugSupport; + protected boolean isDisposed = false; public ClientConnectionTask(DebugSupportImpl debugSupport, Socket socket) throws IOException { @@ -67,7 +67,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener { data = new byte[size]; requestReader.readFully(data); - DebugRequest request = (DebugRequest) SerializationHelper + DebugMessage request = (DebugMessage) SerializationHelper .deserialize(data); if (TRACE) { System.out.println("SERVER receives request: " + request.toString()); @@ -83,33 +83,30 @@ public class ClientConnectionTask implements Runnable, DebugEventListener { // if the connected debugging client aborted abnormally, // discard the current connection. - handleRequest(new DebugRequest(DebugRequestType.reset)); + handleRequest(new DebugMessage(DebugMessageType.reset)); + + debugSupport.disconnect(getSessionId()); } finally { dispose(); } } - public void handleRequest(DebugRequest request) { + public void handleRequest(DebugMessage request) { if (TRACE) { System.out.println("SERVER handling request: " + request.toString()); } - if (request.getType() == DebugRequestType.session) { + if (request.getType() == DebugMessageType.session) { notifyDebugEvent(new DebugResponseSession(getSessionId())); } else { debugSupport.handleRequest(request); } } - public void notifyDebugEvent(DebugEvent event) { + public void notifyDebugEvent(DebugMessage event) { if (TRACE) System.out.println("SERVER sending event: " + event.toString()); - - if (event == null) - System.out.println("notifyDebugEvent: event is null"); - if (eventWriter == null) - System.out.println("notifyDebugEvent: eventWriter is null"); - + try { byte[] data = SerializationHelper.serialize(event); eventWriter.writeInt(data.length); @@ -120,7 +117,10 @@ public class ClientConnectionTask implements Runnable, DebugEventListener { } } - protected void dispose() { + public void dispose() { + if ( this.isDisposed ) return; + + this.isDisposed = true; debugSupport.decrementClientCount(); if (this.requestReader != null) { diff --git a/src/debug/org/luaj/debug/net/j2se/DebugSupportImpl.java b/src/debug/org/luaj/debug/net/j2se/DebugSupportImpl.java index e3be7d07..30c1d24b 100644 --- a/src/debug/org/luaj/debug/net/j2se/DebugSupportImpl.java +++ b/src/debug/org/luaj/debug/net/j2se/DebugSupportImpl.java @@ -25,21 +25,18 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; -import org.luaj.debug.DebugLuaState; -import org.luaj.debug.event.DebugEvent; +import org.luaj.debug.DebugMessage; import org.luaj.debug.net.DebugSupport; -import org.luaj.debug.request.DebugRequest; +/** + * J2SE version of DebugSupport. The luaj-vm opens a port accepting the debug + * client connections. The current implementation allows the vm to accept one + * and only one debug client connection at any time. + */ +public class DebugSupportImpl extends DebugSupport { -public class DebugSupportImpl implements DebugSupport { - protected static final int UNKNOWN = 0; - protected static final int RUNNING = 1; - protected static final int STOPPED = 2; - - protected int state = UNKNOWN; protected int numClientConnectionsAllowed; protected int numClientConnections = 0; - protected DebugLuaState vm; protected ServerSocket serverSocket; protected int debugPort; protected ClientConnectionTask clientConnectionTask; @@ -74,10 +71,6 @@ public class DebugSupportImpl implements DebugSupport { this.debugPort = port; this.numClientConnectionsAllowed = connections; } - - public void setDebugStackState(DebugLuaState vm) { - this.vm = vm; - } public void start() throws IOException { if (this.vm == null) { @@ -110,15 +103,7 @@ public class DebugSupportImpl implements DebugSupport { public synchronized int getClientCount() { return this.numClientConnections; } - - protected synchronized void setState(int state) { - this.state = state; - } - - protected synchronized boolean isRunning() { - return this.state == RUNNING; - } - + public synchronized void stop() { setState(STOPPED); if (clientConnectionTask != null) { @@ -129,22 +114,16 @@ public class DebugSupportImpl implements DebugSupport { /* * (non-Javadoc) - * - * @see org.luaj.debug.event.DebugEventListener#notifyDebugEvent(org.luaj.debug.event.DebugEvent) + * @see org.luaj.debug.event.DebugEventListener#notifyDebugEvent(org.luaj.debug.DebugMessage) */ - public void notifyDebugEvent(DebugEvent event) { + public void notifyDebugEvent(DebugMessage event) { if (clientConnectionTask != null) { clientConnectionTask.notifyDebugEvent(event); } } - - /* - * (non-Javadoc) - * - * @see org.luaj.debug.request.DebugRequestListener#handleRequest(org.luaj.debug.request.DebugRequest) - */ - public void handleRequest(DebugRequest request) { - vm.handleRequest(request); + + public synchronized void disconnect() { + disconnect(clientConnectionTask.getSessionId()); } public synchronized void disconnect(int id) { @@ -152,26 +131,34 @@ public class DebugSupportImpl implements DebugSupport { clientConnectionTask.disconnect(); clientConnectionTask = null; } else { - throw new RuntimeException("Internal Error: mismatching sesion Id: " + id + " current task: " + clientConnectionTask.getSessionId()); + throw new RuntimeException("Internal Error: mismatching sesion Id"); } } public void acceptClientConnection() throws IOException { - Socket clientSocket = serverSocket.accept(); - int count = getClientCount(); - if (count == numClientConnectionsAllowed) { - clientSocket.close(); - } else { - synchronized(this) { - incrementClientCount(); - this.clientConnectionTask = new ClientConnectionTask(this, clientSocket); - new Thread(clientConnectionTask).start(); + try { + Socket clientSocket = serverSocket.accept(); + int count = getClientCount(); + if (count == numClientConnectionsAllowed) { + clientSocket.close(); + } else { + synchronized(this) { + incrementClientCount(); + this.clientConnectionTask = new ClientConnectionTask(this, clientSocket); + new Thread(clientConnectionTask).start(); + } } + } finally { + dispose(); } } protected synchronized void dispose() { - this.clientConnectionTask = null; + if (this.clientConnectionTask != null) { + clientConnectionTask.dispose(); + clientConnectionTask = null; + } + if (this.serverSocket != null) { try { serverSocket.close(); diff --git a/src/debug/org/luaj/debug/request/DebugRequest.java b/src/debug/org/luaj/debug/request/DebugRequest.java deleted file mode 100644 index feca7c61..00000000 --- a/src/debug/org/luaj/debug/request/DebugRequest.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug.request; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.Serializable; -import org.luaj.debug.SerializationHelper; - - -public class DebugRequest implements Serializable { - protected DebugRequestType type; - - public DebugRequest(DebugRequestType type) { - this.type = type; - } - - public DebugRequestType getType() { - return this.type; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - return type.toString(); - } - - public static void serialize(DataOutputStream out, DebugRequest request) - throws IOException { - DebugRequestType type = request.getType(); - SerializationHelper.serialize(type, out); - } - - public static DebugRequest deserialize(DataInputStream in) throws IOException { - DebugRequestType type = (DebugRequestType) SerializationHelper.deserialize(in); - return new DebugRequest(type); - } -} diff --git a/src/debug/org/luaj/debug/request/DebugRequestDisconnect.java b/src/debug/org/luaj/debug/request/DebugRequestDisconnect.java index 4bcf1183..10a94ece 100644 --- a/src/debug/org/luaj/debug/request/DebugRequestDisconnect.java +++ b/src/debug/org/luaj/debug/request/DebugRequestDisconnect.java @@ -4,11 +4,14 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -public class DebugRequestDisconnect extends DebugRequest { +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; + +public class DebugRequestDisconnect extends DebugMessage { protected int sessionId; public DebugRequestDisconnect(int connectionId) { - super(DebugRequestType.disconnect); + super(DebugMessageType.disconnect); this.sessionId = connectionId; } @@ -25,7 +28,7 @@ public class DebugRequestDisconnect extends DebugRequest { out.writeInt(request.getSessionId()); } - public static DebugRequest deserialize(DataInputStream in) + public static DebugMessage deserialize(DataInputStream in) throws IOException { int id = in.readInt(); diff --git a/src/debug/org/luaj/debug/request/DebugRequestLineBreakpointToggle.java b/src/debug/org/luaj/debug/request/DebugRequestLineBreakpointToggle.java index 4b81932b..c89eae29 100644 --- a/src/debug/org/luaj/debug/request/DebugRequestLineBreakpointToggle.java +++ b/src/debug/org/luaj/debug/request/DebugRequestLineBreakpointToggle.java @@ -25,14 +25,16 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; import org.luaj.debug.SerializationHelper; -public class DebugRequestLineBreakpointToggle extends DebugRequest { +public class DebugRequestLineBreakpointToggle extends DebugMessage { protected String source; protected int lineNumber; - public DebugRequestLineBreakpointToggle(DebugRequestType type, String source, int lineNumber) { + public DebugRequestLineBreakpointToggle(DebugMessageType type, String source, int lineNumber) { super(type); if (lineNumber < 0) { throw new IllegalArgumentException("lineNumber must be equal to greater than zero"); @@ -63,8 +65,8 @@ public class DebugRequestLineBreakpointToggle extends DebugRequest { out.writeInt(request.getLineNumber()); } - public static DebugRequest deserialize(DataInputStream in) throws IOException { - DebugRequestType type = (DebugRequestType)SerializationHelper.deserialize(in); + public static DebugMessage deserialize(DataInputStream in) throws IOException { + DebugMessageType type = (DebugMessageType)SerializationHelper.deserialize(in); String source = in.readUTF(); int lineNo = in.readInt(); diff --git a/src/debug/org/luaj/debug/request/DebugRequestListener.java b/src/debug/org/luaj/debug/request/DebugRequestListener.java index b512f737..098d545d 100644 --- a/src/debug/org/luaj/debug/request/DebugRequestListener.java +++ b/src/debug/org/luaj/debug/request/DebugRequestListener.java @@ -21,6 +21,8 @@ ******************************************************************************/ package org.luaj.debug.request; +import org.luaj.debug.DebugMessage; + public interface DebugRequestListener { @@ -37,5 +39,5 @@ public interface DebugRequestListener { * listing the (variable, value) pairs * step -- single step forward (go to next statement) */ - public void handleRequest(DebugRequest request); + public void handleRequest(DebugMessage request); } diff --git a/src/debug/org/luaj/debug/request/DebugRequestStack.java b/src/debug/org/luaj/debug/request/DebugRequestStack.java index 42a1dc37..e07aa96a 100644 --- a/src/debug/org/luaj/debug/request/DebugRequestStack.java +++ b/src/debug/org/luaj/debug/request/DebugRequestStack.java @@ -25,13 +25,14 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import org.luaj.debug.Serializable; +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; -public class DebugRequestStack extends DebugRequest implements Serializable { +public class DebugRequestStack extends DebugMessage { protected int index; public DebugRequestStack(int index) { - super(DebugRequestType.stack); + super(DebugMessageType.stack); this.index = index; } @@ -53,7 +54,7 @@ public class DebugRequestStack extends DebugRequest implements Serializable { out.writeInt(request.getIndex()); } - public static DebugRequest deserialize(DataInputStream in) + public static DebugMessage deserialize(DataInputStream in) throws IOException { int index = in.readInt(); diff --git a/src/debug/org/luaj/debug/request/DebugRequestType.java b/src/debug/org/luaj/debug/request/DebugRequestType.java deleted file mode 100644 index 8cd3054a..00000000 --- a/src/debug/org/luaj/debug/request/DebugRequestType.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug.request; - -import java.io.DataInputStream; -import java.io.IOException; - -import org.luaj.debug.EnumType; - - - -public class DebugRequestType extends EnumType { - public static final DebugRequestType start = new DebugRequestType("start", 0); - public static final DebugRequestType resume = new DebugRequestType("resume", 1); - public static final DebugRequestType suspend = new DebugRequestType("suspend", 2); - public static final DebugRequestType exit = new DebugRequestType("exit", 3); - public static final DebugRequestType lineBreakpointSet = new DebugRequestType("lineBreakpointSet", 4); - public static final DebugRequestType lineBreakpointClear = new DebugRequestType("lineBreakpointClear", 5); - public static final DebugRequestType watchpointSet = new DebugRequestType("watchpointSet", 6); - public static final DebugRequestType watchpointClear = new DebugRequestType("watchpointClear", 7); - public static final DebugRequestType callgraph = new DebugRequestType("callgraph", 8); - public static final DebugRequestType stack = new DebugRequestType("stack", 9); - public static final DebugRequestType stepInto = new DebugRequestType("stepInto", 10); - public static final DebugRequestType stepOver = new DebugRequestType("stepOver", 11); - public static final DebugRequestType stepReturn = new DebugRequestType("stepReturn", 12); - public static final DebugRequestType global = new DebugRequestType("global", 13); - public static final DebugRequestType disconnect = new DebugRequestType("disconnect", 14); - public static final DebugRequestType reset = new DebugRequestType("reset", 15); - public static final DebugRequestType session = new DebugRequestType("session", 16); - - protected static final DebugRequestType[] ENUMS = new DebugRequestType[] { - start, - resume, - suspend, - exit, - lineBreakpointSet, - lineBreakpointClear, - watchpointSet, - watchpointClear, - callgraph, - stack, - stepInto, - stepOver, - stepReturn, - global, - disconnect, - reset, - session - }; - - public DebugRequestType(String name, int ordinal) { - super(name, ordinal); - } - - public static DebugRequestType deserialize(DataInputStream in) throws IOException { - int ordinal = in.readInt(); - if (ordinal < 0 || ordinal >= ENUMS.length) { - throw new RuntimeException("DebugRequestType: ordinal is out of the range."); - } - return ENUMS[ordinal]; - } -} diff --git a/src/debug/org/luaj/debug/request/DebugRequestWatchpointToggle.java b/src/debug/org/luaj/debug/request/DebugRequestWatchpointToggle.java index 9cbc3fff..8d1c455c 100644 --- a/src/debug/org/luaj/debug/request/DebugRequestWatchpointToggle.java +++ b/src/debug/org/luaj/debug/request/DebugRequestWatchpointToggle.java @@ -21,13 +21,15 @@ ******************************************************************************/ package org.luaj.debug.request; +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; import org.luaj.debug.EnumType; -public class DebugRequestWatchpointToggle extends DebugRequest { +public class DebugRequestWatchpointToggle extends DebugMessage { public static class AccessType extends EnumType { - private static final long serialVersionUID = 3523086189648091587L; + private static final long serialVersionUID = 3523086189648091587L; - public static final AccessType Ignore = new AccessType("Ignore", 0); + public static final AccessType Ignore = new AccessType("Ignore", 0); public static final AccessType Read = new AccessType("Read", 1); public static final AccessType Modify = new AccessType("Modify", 2); public static final AccessType ReadAndModify = new AccessType("ReadAndModify", 3); @@ -44,8 +46,8 @@ public class DebugRequestWatchpointToggle extends DebugRequest { String variableName, AccessType accessType) { super(accessType == AccessType.Ignore ? - DebugRequestType.watchpointClear : - DebugRequestType.watchpointSet); + DebugMessageType.watchpointClear : + DebugMessageType.watchpointSet); this.functionName = functionName; this.variableName = variableName; } diff --git a/src/debug/org/luaj/debug/response/DebugResponseCallgraph.java b/src/debug/org/luaj/debug/response/DebugResponseCallgraph.java index f4fdcfc9..5d98ef4b 100644 --- a/src/debug/org/luaj/debug/response/DebugResponseCallgraph.java +++ b/src/debug/org/luaj/debug/response/DebugResponseCallgraph.java @@ -25,15 +25,15 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; import org.luaj.debug.StackFrame; -import org.luaj.debug.event.DebugEvent; -import org.luaj.debug.event.DebugEventType; -public class DebugResponseCallgraph extends DebugEvent { +public class DebugResponseCallgraph extends DebugMessage { protected StackFrame[] stackFrames; public DebugResponseCallgraph(StackFrame[] callgraph) { - super(DebugEventType.clientRequestCallgraphReply); + super(DebugMessageType.clientRequestCallgraphReply); if (callgraph == null) { this.stackFrames = new StackFrame[0]; } else { @@ -64,7 +64,7 @@ public class DebugResponseCallgraph extends DebugEvent { } } - public static DebugEvent deserialize(DataInputStream in) throws IOException { + public static DebugMessage deserialize(DataInputStream in) throws IOException { int count = in.readInt(); StackFrame[] stackFrames = new StackFrame[count]; for (int i = 0; i < count; i++) { diff --git a/src/debug/org/luaj/debug/response/DebugResponseSession.java b/src/debug/org/luaj/debug/response/DebugResponseSession.java index b2ab0759..5ed55489 100644 --- a/src/debug/org/luaj/debug/response/DebugResponseSession.java +++ b/src/debug/org/luaj/debug/response/DebugResponseSession.java @@ -4,14 +4,14 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import org.luaj.debug.event.DebugEvent; -import org.luaj.debug.event.DebugEventType; +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; -public class DebugResponseSession extends DebugEvent { +public class DebugResponseSession extends DebugMessage { protected int sessionId; public DebugResponseSession(int id) { - super(DebugEventType.session); + super(DebugMessageType.session); this.sessionId = id; } @@ -29,7 +29,7 @@ public class DebugResponseSession extends DebugEvent { out.writeInt(response.getSessionId()); } - public static DebugEvent deserialize(DataInputStream in) throws IOException { + public static DebugMessage deserialize(DataInputStream in) throws IOException { int id = in.readInt(); return new DebugResponseSession(id); } diff --git a/src/debug/org/luaj/debug/response/DebugResponseStack.java b/src/debug/org/luaj/debug/response/DebugResponseStack.java index 3b5c9501..cfddfa39 100644 --- a/src/debug/org/luaj/debug/response/DebugResponseStack.java +++ b/src/debug/org/luaj/debug/response/DebugResponseStack.java @@ -4,16 +4,16 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; import org.luaj.debug.SerializationHelper; import org.luaj.debug.Variable; -import org.luaj.debug.event.DebugEvent; -import org.luaj.debug.event.DebugEventType; public class DebugResponseStack extends DebugResponseVariables { protected int stackFrameIndex; public DebugResponseStack(int index, Variable[] variables) { - super(variables, DebugEventType.clientRequestStackReply); + super(variables, DebugMessageType.clientRequestStackReply); this.stackFrameIndex = index; } @@ -33,7 +33,7 @@ public class DebugResponseStack extends DebugResponseVariables { } } - public static DebugEvent deserialize(DataInputStream in) throws IOException { + public static DebugMessage deserialize(DataInputStream in) throws IOException { int index = in.readInt(); int count = in.readInt(); diff --git a/src/debug/org/luaj/debug/response/DebugResponseVariables.java b/src/debug/org/luaj/debug/response/DebugResponseVariables.java index b3a3c508..f2ec66a1 100644 --- a/src/debug/org/luaj/debug/response/DebugResponseVariables.java +++ b/src/debug/org/luaj/debug/response/DebugResponseVariables.java @@ -25,15 +25,15 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import org.luaj.debug.DebugMessage; +import org.luaj.debug.DebugMessageType; import org.luaj.debug.SerializationHelper; import org.luaj.debug.Variable; -import org.luaj.debug.event.DebugEvent; -import org.luaj.debug.event.DebugEventType; -public class DebugResponseVariables extends DebugEvent { +public class DebugResponseVariables extends DebugMessage { protected Variable[] variables; - public DebugResponseVariables(Variable[] variables, DebugEventType type) { + public DebugResponseVariables(Variable[] variables, DebugMessageType type) { super(type); if (variables == null) { this.variables = new Variable[0]; @@ -60,7 +60,7 @@ public class DebugResponseVariables extends DebugEvent { public static void serialize(DataOutputStream out, DebugResponseVariables response) throws IOException { - DebugEventType.serialize(out, response.getType()); + DebugMessageType.serialize(out, response.getType()); Variable[] variables = response.getVariables(); out.writeInt(variables == null ? 0 : variables.length); for (int i = 0; i < variables.length; i++) { @@ -68,9 +68,9 @@ public class DebugResponseVariables extends DebugEvent { } } - public static DebugEvent deserialize(DataInputStream in) + public static DebugMessage deserialize(DataInputStream in) throws IOException { - DebugEventType type = DebugEventType.deserialize(in); + DebugMessageType type = DebugMessageType.deserialize(in); int count = in.readInt(); Variable[] variables = new Variable[count]; for (int i = 0; i < count; i++) { diff --git a/src/test/java/org/luaj/debug/DebugEventTest.java b/src/test/java/org/luaj/debug/DebugEventTest.java index 88ff8d15..3b55d69b 100644 --- a/src/test/java/org/luaj/debug/DebugEventTest.java +++ b/src/test/java/org/luaj/debug/DebugEventTest.java @@ -2,37 +2,36 @@ package org.luaj.debug; import java.io.IOException; -import org.luaj.debug.SerializationHelper; -import org.luaj.debug.event.DebugEvent; -import org.luaj.debug.event.DebugEventBreakpoint; -import org.luaj.debug.event.DebugEventType; - import junit.framework.TestCase; +import org.luaj.debug.event.DebugEventBreakpoint; + public class DebugEventTest extends TestCase { - public void testDebugEventSerialization() { - try { - DebugEvent event = new DebugEvent(DebugEventType.started); - byte[] data = SerializationHelper.serialize(event); - DebugEvent eventOut = (DebugEvent)SerializationHelper.deserialize(data); - assertNotNull(eventOut); - assertEquals(event.getType(), eventOut.getType()); - } catch (IOException e) { - fail(e.getMessage()); - } - } - - public void testDebugEventBreakpointSerialization() { - try { - DebugEventBreakpoint event = new DebugEventBreakpoint("test.lua", 100); - byte[] data = SerializationHelper.serialize(event); - DebugEventBreakpoint eventOut - = (DebugEventBreakpoint) SerializationHelper.deserialize(data); - assertNotNull(eventOut); - assertEquals(event.getSource(), eventOut.getSource()); - assertEquals(event.getLineNumber(), eventOut.getLineNumber()); - } catch (IOException e) { - fail(e.getMessage()); - } - } + public void testDebugEventSerialization() { + try { + DebugMessage event = new DebugMessage(DebugMessageType.started); + byte[] data = SerializationHelper.serialize(event); + DebugMessage eventOut = (DebugMessage) SerializationHelper + .deserialize(data); + assertNotNull(eventOut); + assertEquals(event.getType(), eventOut.getType()); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + public void testDebugEventBreakpointSerialization() { + try { + DebugEventBreakpoint event = new DebugEventBreakpoint("test.lua", + 100); + byte[] data = SerializationHelper.serialize(event); + DebugEventBreakpoint eventOut = (DebugEventBreakpoint) SerializationHelper + .deserialize(data); + assertNotNull(eventOut); + assertEquals(event.getSource(), eventOut.getSource()); + assertEquals(event.getLineNumber(), eventOut.getLineNumber()); + } catch (IOException e) { + fail(e.getMessage()); + } + } } diff --git a/src/test/java/org/luaj/debug/DebugRequestTest.java b/src/test/java/org/luaj/debug/DebugRequestTest.java index 217c85d4..4e28de62 100644 --- a/src/test/java/org/luaj/debug/DebugRequestTest.java +++ b/src/test/java/org/luaj/debug/DebugRequestTest.java @@ -2,61 +2,60 @@ package org.luaj.debug; import java.io.IOException; -import org.luaj.debug.SerializationHelper; -import org.luaj.debug.request.DebugRequest; -import org.luaj.debug.request.DebugRequestLineBreakpointToggle; -import org.luaj.debug.request.DebugRequestStack; -import org.luaj.debug.request.DebugRequestType; - import junit.framework.TestCase; +import org.luaj.debug.request.DebugRequestLineBreakpointToggle; +import org.luaj.debug.request.DebugRequestStack; + public class DebugRequestTest extends TestCase { - public void testDebugRequestSerialization() { - try { - DebugRequest request = new DebugRequest(DebugRequestType.resume); - byte[] data = SerializationHelper.serialize(request); - DebugRequest requestOut - = (DebugRequest)SerializationHelper.deserialize(data); - assertNotNull(requestOut); - assertEquals(request.getType(), requestOut.getType()); - } catch (IOException e) { - fail(e.getMessage()); - } - } - - public void testDebugRequestStackSerialization() { - try { - DebugRequestStack request = new DebugRequestStack(1); - byte[] data = SerializationHelper.serialize(request); - DebugRequestStack requestOut - = (DebugRequestStack) SerializationHelper.deserialize(data); - assertNotNull(requestOut); - assertEquals(requestOut.getIndex(), 1); - } catch (IOException e) { - fail(e.getMessage()); - } - } - - public void testDebugRequestLineBreakpointToggleSerialization() { - try - { - doTestDebugRequestLineBreakpointToggleSerialization(DebugRequestType.lineBreakpointSet, "test.lua", 100); - doTestDebugRequestLineBreakpointToggleSerialization(DebugRequestType.lineBreakpointClear, "test.lua", 50); - } catch (IOException e) { - fail(e.getMessage()); - } - } - - private void doTestDebugRequestLineBreakpointToggleSerialization( - DebugRequestType type, String source, int lineNo) throws IOException { - DebugRequestLineBreakpointToggle request - = new DebugRequestLineBreakpointToggle(DebugRequestType.lineBreakpointSet, "test.lua", 100); - byte[] data = SerializationHelper.serialize(request); - DebugRequestLineBreakpointToggle requestOut = - (DebugRequestLineBreakpointToggle) SerializationHelper.deserialize(data); - assertNotNull(requestOut); - assertEquals(request.getType(), requestOut.getType()); - assertEquals(request.getSource(), requestOut.getSource()); - assertEquals(request.getLineNumber(), requestOut.getLineNumber()); - } + public void testDebugRequestSerialization() { + try { + DebugMessage request = new DebugMessage(DebugMessageType.resume); + byte[] data = SerializationHelper.serialize(request); + DebugMessage requestOut = (DebugMessage) SerializationHelper + .deserialize(data); + assertNotNull(requestOut); + assertEquals(request.getType(), requestOut.getType()); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + public void testDebugRequestStackSerialization() { + try { + DebugRequestStack request = new DebugRequestStack(1); + byte[] data = SerializationHelper.serialize(request); + DebugRequestStack requestOut = (DebugRequestStack) SerializationHelper + .deserialize(data); + assertNotNull(requestOut); + assertEquals(requestOut.getIndex(), 1); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + public void testDebugRequestLineBreakpointToggleSerialization() { + try { + doTestDebugRequestLineBreakpointToggleSerialization( + DebugMessageType.lineBreakpointSet, "test.lua", 100); + doTestDebugRequestLineBreakpointToggleSerialization( + DebugMessageType.lineBreakpointClear, "test.lua", 50); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + private void doTestDebugRequestLineBreakpointToggleSerialization( + DebugMessageType type, String source, int lineNo) + throws IOException { + DebugRequestLineBreakpointToggle request = new DebugRequestLineBreakpointToggle( + DebugMessageType.lineBreakpointSet, "test.lua", 100); + byte[] data = SerializationHelper.serialize(request); + DebugRequestLineBreakpointToggle requestOut = (DebugRequestLineBreakpointToggle) SerializationHelper + .deserialize(data); + assertNotNull(requestOut); + assertEquals(request.getType(), requestOut.getType()); + assertEquals(request.getSource(), requestOut.getSource()); + assertEquals(request.getLineNumber(), requestOut.getLineNumber()); + } } diff --git a/src/test/java/org/luaj/debug/EnumTypeTest.java b/src/test/java/org/luaj/debug/EnumTypeTest.java index 81513c21..5d269db3 100644 --- a/src/test/java/org/luaj/debug/EnumTypeTest.java +++ b/src/test/java/org/luaj/debug/EnumTypeTest.java @@ -1,33 +1,30 @@ package org.luaj.debug; -import org.luaj.debug.SerializationHelper; -import org.luaj.debug.event.DebugEventType; -import org.luaj.debug.request.DebugRequestType; - import junit.framework.TestCase; public class EnumTypeTest extends TestCase { - public void testDebugRequestTypeSerialization() { - try { - DebugRequestType type = DebugRequestType.lineBreakpointClear; - byte[] data = SerializationHelper.serialize(type); - DebugRequestType typeOut - = (DebugRequestType) SerializationHelper.deserialize(data); - assertEquals(type, typeOut); - } catch (Exception e) { - fail(e.getMessage()); - } - } - - public void testDebugEventTypeSerialization() { - try { - DebugEventType type = DebugEventType.error; - byte[] data = SerializationHelper.serialize(type); - DebugEventType typeOut = (DebugEventType) SerializationHelper.deserialize(data); - assertNotNull(typeOut); - assertEquals(type, typeOut); - } catch (Exception e) { - fail(e.getMessage()); - } - } + public void testDebugRequestTypeSerialization() { + try { + DebugMessageType type = DebugMessageType.lineBreakpointClear; + byte[] data = SerializationHelper.serialize(type); + DebugMessageType typeOut = (DebugMessageType) SerializationHelper + .deserialize(data); + assertEquals(type, typeOut); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + public void testDebugEventTypeSerialization() { + try { + DebugMessageType type = DebugMessageType.error; + byte[] data = SerializationHelper.serialize(type); + DebugMessageType typeOut = (DebugMessageType) SerializationHelper + .deserialize(data); + assertNotNull(typeOut); + assertEquals(type, typeOut); + } catch (Exception e) { + fail(e.getMessage()); + } + } }