From 8086066e8b88ebdab89f1da3cfe970321eccc55a Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sat, 8 Sep 2012 13:09:17 +0200 Subject: [PATCH] [#1472] Add a Settings.executeDebugging property, and move server-side Console logic to core - Inline CommandMessage.{sync|async}Message. This indirection is not needed, but obscures further refactorings --- .../debug/console/remote/ClientDebugger.java | 42 +++++++++------- .../remote/ClientStatementExecutor.java | 15 ++++-- .../debug/console/remote/ServerDebugger.java | 48 ++++++++++--------- .../remote/messaging/CommandMessage.java | 37 +++++--------- .../messaging/CommunicationInterface.java | 22 +++++++++ .../remote/messaging/LocalMessage.java | 2 +- .../remote/messaging/MessagingInterface.java | 4 +- 7 files changed, 97 insertions(+), 73 deletions(-) diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientDebugger.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientDebugger.java index cd5bed02de..a809c62e92 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientDebugger.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientDebugger.java @@ -52,6 +52,14 @@ import org.jooq.debug.QueryLoggingData; import org.jooq.debug.ResultSetLoggingData; import org.jooq.debug.StatementExecutor; import org.jooq.debug.StatementMatcher; +import org.jooq.debug.console.remote.ServerDebugger.CMS_addBreakpoint; +import org.jooq.debug.console.remote.ServerDebugger.CMS_isExecutionSupported; +import org.jooq.debug.console.remote.ServerDebugger.CMS_modifyBreakpoint; +import org.jooq.debug.console.remote.ServerDebugger.CMS_removeBreakpoint; +import org.jooq.debug.console.remote.ServerDebugger.CMS_setBreakpointHitHandlerActive; +import org.jooq.debug.console.remote.ServerDebugger.CMS_setBreakpoints; +import org.jooq.debug.console.remote.ServerDebugger.CMS_setLoggingActive; +import org.jooq.debug.console.remote.ServerDebugger.CMS_setLoggingStatementMatchers; import org.jooq.debug.console.remote.messaging.CommunicationInterface; import org.jooq.debug.console.remote.messaging.CommunicationInterfaceFactory; @@ -60,10 +68,10 @@ import org.jooq.debug.console.remote.messaging.CommunicationInterfaceFactory; */ public class ClientDebugger implements Debugger { - private CommunicationInterface communicationInterface; + private CommunicationInterface comm; public ClientDebugger(String ip, int port) throws Exception { - communicationInterface = CommunicationInterface.openClientCommunicationChannel(new CommunicationInterfaceFactory() { + comm = CommunicationInterface.openClientCommunicationChannel(new CommunicationInterfaceFactory() { @Override public CommunicationInterface createCommunicationInterface(int port_) { return new DebuggerCommmunicationInterface(ClientDebugger.this, port_); @@ -72,7 +80,7 @@ public class ClientDebugger implements Debugger { } CommunicationInterface getCommunicationInterface() { - return communicationInterface; + return comm; } private LoggingListener loggingListener; @@ -86,7 +94,7 @@ public class ClientDebugger implements Debugger { } this.loggingListener = loggingListener; } - new ServerDebugger.CMS_setLoggingActive().asyncExec(communicationInterface, loggingListener != null); + comm.asyncExec(new CMS_setLoggingActive(), loggingListener != null); } @Override @@ -104,7 +112,7 @@ public class ClientDebugger implements Debugger { synchronized (LOGGING_STATEMENT_MATCHERS_LOCK) { this.loggingStatementMatchers = loggingStatementMatchers; } - new ServerDebugger.CMS_setLoggingStatementMatchers().asyncExec(communicationInterface, (Object)loggingStatementMatchers); + comm.asyncExec(new CMS_setLoggingStatementMatchers(), (Serializable[]) loggingStatementMatchers); } @Override @@ -125,7 +133,7 @@ public class ClientDebugger implements Debugger { synchronized (BREAKPOINT_LOCK) { this.breakpoints = breakpoints; } - new ServerDebugger.CMS_setBreakpoints().asyncExec(communicationInterface, (Object)breakpoints); + comm.asyncExec(new CMS_setBreakpoints(), (Serializable[]) breakpoints); } @Override @@ -133,13 +141,13 @@ public class ClientDebugger implements Debugger { synchronized (BREAKPOINT_LOCK) { if(this.breakpoints == null) { this.breakpoints = new Breakpoint[] {breakpoint}; - new ServerDebugger.CMS_addBreakpoint().asyncExec(communicationInterface, (Object)breakpoint); + comm.asyncExec(new CMS_addBreakpoint(), breakpoint); return; } for(int i=0; i { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { LoggingListener loggingListener = getDebugger().getLoggingListener(); if(loggingListener != null) { loggingListener.logQueries((QueryLoggingData)args[0]); @@ -253,7 +261,7 @@ public class ClientDebugger implements Debugger { @SuppressWarnings("serial") static class CMC_logResultSet extends ClientDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { LoggingListener loggingListener = getDebugger().getLoggingListener(); if(loggingListener != null) { loggingListener.logResultSet((Integer)args[0], (ResultSetLoggingData)args[1]); @@ -265,7 +273,7 @@ public class ClientDebugger implements Debugger { @SuppressWarnings("serial") static class CMC_processBreakpointBeforeExecutionHit extends ClientDebuggerCommandMessage { @Override - public BreakpointHit run(Object[] args) { + public BreakpointHit run(Serializable... args) { BreakpointHitHandler breakpointHitHandler = getDebugger().getBreakpointHitHandler(); if(breakpointHitHandler != null) { BreakpointHit breakpointHit = (BreakpointHit)args[0]; @@ -283,7 +291,7 @@ public class ClientDebugger implements Debugger { @SuppressWarnings("serial") static class CMC_processBreakpointAfterExecutionHit extends ClientDebuggerCommandMessage { @Override - public BreakpointHit run(Object[] args) { + public BreakpointHit run(Serializable... args) { BreakpointHitHandler breakpointHitHandler = getDebugger().getBreakpointHitHandler(); if(breakpointHitHandler != null) { BreakpointHit breakpointHit = (BreakpointHit)args[0]; diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientStatementExecutor.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientStatementExecutor.java index 602ce5d6af..8395ac2f8a 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientStatementExecutor.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientStatementExecutor.java @@ -40,6 +40,11 @@ import java.util.concurrent.atomic.AtomicInteger; import org.jooq.debug.StatementExecution; import org.jooq.debug.StatementExecutor; +import org.jooq.debug.console.remote.ServerDebugger.CMS_createServerStatementExecutor; +import org.jooq.debug.console.remote.ServerDebugger.CMS_doStatementExecutorExecution; +import org.jooq.debug.console.remote.ServerDebugger.CMS_getStatementExecutorTableColumnNames; +import org.jooq.debug.console.remote.ServerDebugger.CMS_getStatementExecutorTableNames; +import org.jooq.debug.console.remote.ServerDebugger.CMS_stopStatementExecutorExecution; /** * @author Christopher Deckers @@ -57,28 +62,28 @@ public class ClientStatementExecutor implements StatementExecutor { public ClientStatementExecutor(ClientDebugger debugger, Long breakpointHitThreadID) { id = nextID.incrementAndGet(); this.debugger = debugger; - new ServerDebugger.CMS_createServerStatementExecutor().asyncExec(debugger.getCommunicationInterface(), id, breakpointHitThreadID); + debugger.getCommunicationInterface().asyncExec(new CMS_createServerStatementExecutor(), id, breakpointHitThreadID); } @Override public StatementExecution execute(String sql, int maxRSRowsParsing, int retainParsedRSDataRowCountThreshold) { - return new ServerDebugger.CMS_doStatementExecutorExecution().syncExec(debugger.getCommunicationInterface(), id, sql, maxRSRowsParsing, retainParsedRSDataRowCountThreshold); + return debugger.getCommunicationInterface().syncExec(new CMS_doStatementExecutorExecution(), id, sql, maxRSRowsParsing, retainParsedRSDataRowCountThreshold); } @Override public void stopExecution() { - new ServerDebugger.CMS_stopStatementExecutorExecution().asyncExec(debugger.getCommunicationInterface(), id); + debugger.getCommunicationInterface().asyncExec(new CMS_stopStatementExecutorExecution(), id); } @Override public String[] getTableNames() { - String[] tableNames = (String[])new ServerDebugger.CMS_getStatementExecutorTableNames().syncExec(debugger.getCommunicationInterface(), id); + String[] tableNames = debugger.getCommunicationInterface().syncExec(new CMS_getStatementExecutorTableNames(), id); return tableNames == null? new String[0]: tableNames; } @Override public String[] getTableColumnNames() { - String[] tableColumnNames = (String[])new ServerDebugger.CMS_getStatementExecutorTableColumnNames().syncExec(debugger.getCommunicationInterface(), id); + String[] tableColumnNames = debugger.getCommunicationInterface().syncExec(new CMS_getStatementExecutorTableColumnNames(), id); return tableColumnNames == null? new String[0]: tableColumnNames; } diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ServerDebugger.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ServerDebugger.java index 9eff344955..c0b9ac5ea1 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ServerDebugger.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ServerDebugger.java @@ -54,6 +54,10 @@ import org.jooq.debug.StatementExecution; import org.jooq.debug.StatementExecutor; import org.jooq.debug.StatementMatcher; import org.jooq.debug.console.DatabaseDescriptor; +import org.jooq.debug.console.remote.ClientDebugger.CMC_logQueries; +import org.jooq.debug.console.remote.ClientDebugger.CMC_logResultSet; +import org.jooq.debug.console.remote.ClientDebugger.CMC_processBreakpointAfterExecutionHit; +import org.jooq.debug.console.remote.ClientDebugger.CMC_processBreakpointBeforeExecutionHit; import org.jooq.debug.console.remote.messaging.CommunicationInterface; /** @@ -65,10 +69,10 @@ class ServerDebugger extends LocalDebugger { super(databaseDescriptor); } - private CommunicationInterface communicationInterface; + private CommunicationInterface comm; void setCommunicationInterface(CommunicationInterface communicationInterface) { - this.communicationInterface = communicationInterface; + this.comm = communicationInterface; } private void setLoggingActive(boolean isActive) { @@ -76,11 +80,11 @@ class ServerDebugger extends LocalDebugger { setLoggingListener(new LoggingListener() { @Override public void logQueries(QueryLoggingData queryLoggingData) { - new ClientDebugger.CMC_logQueries().asyncExec(communicationInterface, queryLoggingData); + comm.asyncExec(new CMC_logQueries(), queryLoggingData); } @Override public void logResultSet(int sqlQueryDebuggerDataID, ResultSetLoggingData resultSetLoggingData) { - new ClientDebugger.CMC_logResultSet().asyncExec(communicationInterface, sqlQueryDebuggerDataID, resultSetLoggingData); + comm.asyncExec(new CMC_logResultSet(), sqlQueryDebuggerDataID, resultSetLoggingData); } }); } else { @@ -91,7 +95,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_setLoggingActive extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { getDebugger().setLoggingActive((Boolean)args[0]); return null; } @@ -102,14 +106,14 @@ class ServerDebugger extends LocalDebugger { setBreakpointHitHandler(new BreakpointHitHandler() { @Override public void processBreakpointBeforeExecutionHit(BreakpointHit breakpointHit) { - BreakpointHit modifiedBreakpointHit = new ClientDebugger.CMC_processBreakpointBeforeExecutionHit().syncExec(communicationInterface, breakpointHit); + BreakpointHit modifiedBreakpointHit = comm.syncExec(new CMC_processBreakpointBeforeExecutionHit(), breakpointHit); if(modifiedBreakpointHit != null) { breakpointHit.setExecutionType(modifiedBreakpointHit.getExecutionType(), modifiedBreakpointHit.getSql()); } } @Override public void processBreakpointAfterExecutionHit(BreakpointHit breakpointHit) { - new ClientDebugger.CMC_processBreakpointAfterExecutionHit().syncExec(communicationInterface, breakpointHit); + comm.syncExec(new CMC_processBreakpointAfterExecutionHit(), breakpointHit); } }); } else { @@ -120,7 +124,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_setLoggingStatementMatchers extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { getDebugger().setLoggingStatementMatchers((StatementMatcher[])args[0]); return null; } @@ -129,7 +133,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_setBreakpoints extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { Breakpoint[] breakpoints = (Breakpoint[])args[0]; if(breakpoints != null) { for(Breakpoint breakpoint: breakpoints) { @@ -145,7 +149,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_addBreakpoint extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { Breakpoint breakpoint = (Breakpoint)args[0]; // Serialization has a cache, assuming objects are immutable. We have to reset our internal states. breakpoint.reset(); @@ -157,7 +161,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_modifyBreakpoint extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { Breakpoint breakpoint = (Breakpoint)args[0]; // Serialization has a cache, assuming objects are immutable. We have to reset our internal states. breakpoint.reset(); @@ -169,7 +173,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_removeBreakpoint extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { getDebugger().removeBreakpoint((Breakpoint)args[0]); return null; } @@ -178,16 +182,16 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_setBreakpointHitHandlerActive extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { getDebugger().setBreakpointHitHandlerActive((Boolean)args[0]); return null; } } @SuppressWarnings("serial") - static class CMS_isExecutionSupported extends ServerDebuggerCommandMessage { + static class CMS_isExecutionSupported extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Boolean run(Serializable... args) { return getDebugger().isExecutionSupported(); } } @@ -221,7 +225,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_createServerStatementExecutor extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { int id = (Integer)args[0]; Long breakpointHitThreadID = (Long)args[1]; getDebugger().createStatementExecutor(id, breakpointHitThreadID); @@ -232,7 +236,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_doStatementExecutorExecution extends ServerDebuggerCommandMessage { @Override - public StatementExecution run(Object[] args) { + public StatementExecution run(Serializable... args) { int id = (Integer)args[0]; String sql = (String)args[1]; int maxRSRowsParsing = (Integer)args[2]; @@ -245,7 +249,7 @@ class ServerDebugger extends LocalDebugger { @SuppressWarnings("serial") static class CMS_stopStatementExecutorExecution extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { int id = (Integer)args[0]; getDebugger().removeStatementExecutor(id).stopExecution(); return null; @@ -253,18 +257,18 @@ class ServerDebugger extends LocalDebugger { } @SuppressWarnings("serial") - static class CMS_getStatementExecutorTableNames extends ServerDebuggerCommandMessage { + static class CMS_getStatementExecutorTableNames extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public String[] run(Serializable... args) { int id = (Integer)args[0]; return getDebugger().getStatementExecutor(id).getTableNames(); } } @SuppressWarnings("serial") - static class CMS_getStatementExecutorTableColumnNames extends ServerDebuggerCommandMessage { + static class CMS_getStatementExecutorTableColumnNames extends ServerDebuggerCommandMessage { @Override - public Serializable run(Object[] args) { + public String[] run(Serializable... args) { int id = (Integer)args[0]; return getDebugger().getStatementExecutor(id).getTableColumnNames(); } diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/CommandMessage.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/CommandMessage.java index 60f420f01a..b51310ad30 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/CommandMessage.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/CommandMessage.java @@ -49,39 +49,21 @@ public abstract class CommandMessage extends Message public CommandMessage() { } - private Object[] args; + private Serializable[] args; /** * Set the arguments that will be used when the message is run. + * * @param arguments the arguments, which must be serializable. */ - void setArgs(Object... arguments) { - if(arguments.length == 0) { + void setArgs(Serializable... arguments) { + if (arguments.length == 0) { arguments = null; } this.args = arguments; } - /** - * Execute that message asynchronously with the given arguments. - * @param arguments the arguments, which must be serializable. - */ - public void asyncExec(CommunicationInterface communicationInterface, Object... arguments) { - setArgs(arguments); - communicationInterface.asyncSend(this); - } - - /** - * Execute that message synchronously with the given arguments and return the result. - * @param arguments the arguments, which must be serializable. - * @return the result of the execution. - */ - public S syncExec(CommunicationInterface communicationInterface, Object... arguments) { - setArgs(arguments); - return communicationInterface.syncSend(this); - } - - private static final Object[] EMPTY_ARGS = new Object[0]; + private static final Serializable[] EMPTY_ARGS = new Serializable[0]; S runCommand() throws Exception { return run(args == null? EMPTY_ARGS: args); @@ -89,11 +71,14 @@ public abstract class CommandMessage extends Message /** * Run the message. - * @param arguments the arguments that were specified for that command, or an empty array if none were specified. + * + * @param arguments the arguments that were specified for that command, or + * an empty array if none were specified. * @return the result that may be passed back to the caller. - * @throws Exception any exception that may happen, and which would be passed back if it is a synchronous execution. + * @throws Exception any exception that may happen, and which would be + * passed back if it is a synchronous execution. */ - public abstract S run(Object[] arguments) throws Exception; + public abstract S run(Serializable... arguments) throws Exception; @Override public String toString() { diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/CommunicationInterface.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/CommunicationInterface.java index ea0effb291..f11c497836 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/CommunicationInterface.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/CommunicationInterface.java @@ -130,6 +130,28 @@ public class CommunicationInterface { return messagingInterface; } + /** + * Execute that message asynchronously with the given arguments. + * + * @param arguments the arguments, which must be serializable. + */ + public void asyncExec(CommandMessage message, Serializable... arguments) { + message.setArgs(arguments); + asyncSend(message); + } + + /** + * Execute that message synchronously with the given arguments and return + * the result. + * + * @param arguments the arguments, which must be serializable. + * @return the result of the execution. + */ + public S syncExec(CommandMessage message, Serializable... arguments) { + message.setArgs(arguments); + return syncSend(message); + } + /** * Send that message synchronously, potentially returning a result if the * message type allows that. diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/LocalMessage.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/LocalMessage.java index 927ffe9454..c184994286 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/LocalMessage.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/LocalMessage.java @@ -61,6 +61,6 @@ public abstract class LocalMessage extends CommandMessag } @Override - public abstract S run(Object[] args); + public abstract S run(Serializable... args); } diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/MessagingInterface.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/MessagingInterface.java index 73720f926c..127502c60a 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/MessagingInterface.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/MessagingInterface.java @@ -331,7 +331,7 @@ class MessagingInterface { @SuppressWarnings("serial") private static class CM_asyncExecResponse extends CommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { MessagingInterface messagingInterface = getCommunicationInterface().getMessagingInterface(); long threadID = (Long)args[0]; CommandResultMessage commandResultMessage = (CommandResultMessage)args[1]; @@ -354,7 +354,7 @@ class MessagingInterface { @SuppressWarnings("serial") private static class CM_asyncExec extends CommandMessage { @Override - public Serializable run(Object[] args) { + public Serializable run(Serializable... args) { Message message = (Message)args[1]; message.setSyncExec(false); CommunicationInterface communicationInterface = getCommunicationInterface();