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 47701aa27b..e40d91fb4c 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 @@ -63,6 +63,7 @@ import org.jooq.debug.console.remote.ServerDebugger.CMS_setLoggingStatementMatch import org.jooq.debug.console.remote.messaging.CommandMessage; import org.jooq.debug.console.remote.messaging.CommunicationInterface; import org.jooq.debug.console.remote.messaging.CommunicationInterfaceFactory; +import org.jooq.debug.console.remote.messaging.MessageContext; /** * @author Christopher Deckers @@ -76,7 +77,7 @@ public class ClientDebugger implements Debugger { comm = CommunicationInterface.openClientCommunicationChannel(new CommunicationInterfaceFactory() { @Override public CommunicationInterface createCommunicationInterface(int port_) { - return new DebuggerCommmunicationInterface(ClientDebugger.this, port_); + return new CommunicationInterface(ClientDebugger.this, port_); } }, ip, port); } @@ -249,7 +250,7 @@ public class ClientDebugger implements Debugger { } - static class CMC_logQueries extends ClientDebuggerCommandMessage { + static class CMC_logQueries extends CommandMessage { private final StatementLog statementLog; CMC_logQueries(StatementLog statementLog) { @@ -257,8 +258,8 @@ public class ClientDebugger implements Debugger { } @Override - public Serializable run() { - LoggingListener loggingListener = getDebugger().getLoggingListener(); + public Serializable run(MessageContext context) { + LoggingListener loggingListener = context.getDebugger().getLoggingListener(); if (loggingListener != null) { loggingListener.logQueries(statementLog); @@ -268,7 +269,7 @@ public class ClientDebugger implements Debugger { } } - static class CMC_logResultSet extends ClientDebuggerCommandMessage { + static class CMC_logResultSet extends CommandMessage { private final int dataId; private final ResultSetLog resultSetLog; @@ -278,8 +279,8 @@ public class ClientDebugger implements Debugger { } @Override - public Serializable run() { - LoggingListener loggingListener = getDebugger().getLoggingListener(); + public Serializable run(MessageContext context) { + LoggingListener loggingListener = context.getDebugger().getLoggingListener(); if (loggingListener != null) { loggingListener.logResultSet(dataId, resultSetLog); @@ -289,7 +290,7 @@ public class ClientDebugger implements Debugger { } } - static class CMC_processBreakpointBeforeExecutionHit extends ClientDebuggerCommandMessage { + static class CMC_processBreakpointBeforeExecutionHit extends CommandMessage { private final BreakpointHit hit; CMC_processBreakpointBeforeExecutionHit(BreakpointHit hit) { @@ -297,8 +298,8 @@ public class ClientDebugger implements Debugger { } @Override - public BreakpointHit run() { - BreakpointHitHandler breakpointHitHandler = getDebugger().getBreakpointHitHandler(); + public BreakpointHit run(MessageContext context) { + BreakpointHitHandler breakpointHitHandler = context.getDebugger().getBreakpointHitHandler(); if (breakpointHitHandler != null) { breakpointHitHandler.processBreakpointBeforeExecutionHit(hit); @@ -313,7 +314,7 @@ public class ClientDebugger implements Debugger { } } - static class CMC_processBreakpointAfterExecutionHit extends ClientDebuggerCommandMessage { + static class CMC_processBreakpointAfterExecutionHit extends CommandMessage { private final BreakpointHit hit; CMC_processBreakpointAfterExecutionHit(BreakpointHit hit) { @@ -321,8 +322,8 @@ public class ClientDebugger implements Debugger { } @Override - public BreakpointHit run() { - BreakpointHitHandler breakpointHitHandler = getDebugger().getBreakpointHitHandler(); + public BreakpointHit run(MessageContext context) { + BreakpointHitHandler breakpointHitHandler = context.getDebugger().getBreakpointHitHandler(); if (breakpointHitHandler != null) { breakpointHitHandler.processBreakpointAfterExecutionHit(hit); diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientDebuggerCommandMessage.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientDebuggerCommandMessage.java deleted file mode 100644 index fafbda018d..0000000000 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ClientDebuggerCommandMessage.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * Christopher Deckers, chrriis@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.debug.console.remote; - -import java.io.Serializable; - -import org.jooq.debug.console.remote.messaging.CommandMessage; - -/** - * @author Christopher Deckers - */ -@SuppressWarnings("serial") -abstract class ClientDebuggerCommandMessage extends CommandMessage { - - protected ClientDebugger getDebugger() { - return (ClientDebugger)((DebuggerCommmunicationInterface)getCommunicationInterface()).getDebugger(); - } - -} diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/RemoteDebuggerServer.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/RemoteDebuggerServer.java index 38d44b69bd..5e41aac135 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/RemoteDebuggerServer.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/RemoteDebuggerServer.java @@ -63,7 +63,7 @@ public class RemoteDebuggerServer { @Override public CommunicationInterface createCommunicationInterface(int port_) { final ServerDebugger debugger = new ServerDebugger(descriptor); - DebuggerCommmunicationInterface commmunicationInterface = new DebuggerCommmunicationInterface(debugger, port_) { + CommunicationInterface commmunicationInterface = new CommunicationInterface(debugger, port_) { @Override protected void processOpened() { DebuggerRegistry.add(debugger); 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 057edcf079..a400857e4d 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 @@ -60,6 +60,7 @@ import org.jooq.debug.console.remote.ClientDebugger.CMC_processBreakpointAfterEx import org.jooq.debug.console.remote.ClientDebugger.CMC_processBreakpointBeforeExecutionHit; import org.jooq.debug.console.remote.messaging.CommandMessage; import org.jooq.debug.console.remote.messaging.CommunicationInterface; +import org.jooq.debug.console.remote.messaging.MessageContext; /** * @author Christopher Deckers @@ -94,7 +95,7 @@ class ServerDebugger extends LocalDebugger { } } - static class CMS_setLoggingActive extends ServerDebuggerCommandMessage { + static class CMS_setLoggingActive extends CommandMessage { private final boolean isActive; CMS_setLoggingActive(boolean isActive) { @@ -102,8 +103,8 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { - getDebugger().setLoggingActive(isActive); + public Serializable run(MessageContext context) { + getServerDebugger(context).setLoggingActive(isActive); return null; } } @@ -128,7 +129,7 @@ class ServerDebugger extends LocalDebugger { } } - static class CMS_setLoggingStatementMatchers extends ServerDebuggerCommandMessage { + static class CMS_setLoggingStatementMatchers extends CommandMessage { private final StatementMatcher[] matchers; CMS_setLoggingStatementMatchers(StatementMatcher[] matchers) { @@ -136,13 +137,13 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { - getDebugger().setLoggingStatementMatchers(matchers); + public Serializable run(MessageContext context) { + context.getDebugger().setLoggingStatementMatchers(matchers); return null; } } - static class CMS_setBreakpoints extends ServerDebuggerCommandMessage { + static class CMS_setBreakpoints extends CommandMessage { private final Breakpoint[] breakpoints; CMS_setBreakpoints(Breakpoint[] breakpoints) { @@ -150,7 +151,7 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { + public Serializable run(MessageContext context) { if (breakpoints != null) { for (Breakpoint breakpoint : breakpoints) { // Serialization has a cache, assuming objects are @@ -158,12 +159,12 @@ class ServerDebugger extends LocalDebugger { breakpoint.reset(); } } - getDebugger().setBreakpoints(breakpoints); + context.getDebugger().setBreakpoints(breakpoints); return null; } } - static class CMS_addBreakpoint extends ServerDebuggerCommandMessage { + static class CMS_addBreakpoint extends CommandMessage { private final Breakpoint breakpoint; CMS_addBreakpoint(Breakpoint breakpoint) { @@ -171,16 +172,16 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { + public Serializable run(MessageContext context) { // Serialization has a cache, assuming objects are immutable. We // have to reset our internal states. breakpoint.reset(); - getDebugger().addBreakpoint(breakpoint); + context.getDebugger().addBreakpoint(breakpoint); return null; } } - static class CMS_modifyBreakpoint extends ServerDebuggerCommandMessage { + static class CMS_modifyBreakpoint extends CommandMessage { private final Breakpoint breakpoint; CMS_modifyBreakpoint(Breakpoint breakpoint) { @@ -188,16 +189,16 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { + public Serializable run(MessageContext context) { // Serialization has a cache, assuming objects are immutable. We // have to reset our internal states. breakpoint.reset(); - getDebugger().modifyBreakpoint(breakpoint); + context.getDebugger().modifyBreakpoint(breakpoint); return null; } } - static class CMS_removeBreakpoint extends ServerDebuggerCommandMessage { + static class CMS_removeBreakpoint extends CommandMessage { private final Breakpoint breakpoint; CMS_removeBreakpoint(Breakpoint breakpoint) { @@ -205,13 +206,13 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { - getDebugger().removeBreakpoint(breakpoint); + public Serializable run(MessageContext context) { + context.getDebugger().removeBreakpoint(breakpoint); return null; } } - static class CMS_setBreakpointHitHandlerActive extends ServerDebuggerCommandMessage { + static class CMS_setBreakpointHitHandlerActive extends CommandMessage { private final boolean isActive; CMS_setBreakpointHitHandlerActive(boolean isActive) { @@ -219,16 +220,16 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { - getDebugger().setBreakpointHitHandlerActive(isActive); + public Serializable run(MessageContext context) { + getServerDebugger(context).setBreakpointHitHandlerActive(isActive); return null; } } - static class CMS_isExecutionSupported extends ServerDebuggerCommandMessage { + static class CMS_isExecutionSupported extends CommandMessage { @Override - public Boolean run() { - return getDebugger().isExecutionSupported(); + public Boolean run(MessageContext context) { + return context.getDebugger().isExecutionSupported(); } } @@ -258,7 +259,7 @@ class ServerDebugger extends LocalDebugger { } } - static class CMS_createServerStatementExecutor extends ServerDebuggerCommandMessage { + static class CMS_createServerStatementExecutor extends CommandMessage { private final int id; private final Long breakpointHitThreadID; @@ -268,13 +269,13 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { - getDebugger().createStatementExecutor(id, breakpointHitThreadID); + public Serializable run(MessageContext context) { + getServerDebugger(context).createStatementExecutor(id, breakpointHitThreadID); return null; } } - static class CMS_doStatementExecutorExecution extends ServerDebuggerCommandMessage { + static class CMS_doStatementExecutorExecution extends CommandMessage { private final int id; private final String sql; private final int maxRSRowsParsing; @@ -289,13 +290,13 @@ class ServerDebugger extends LocalDebugger { } @Override - public StatementExecution run() { - StatementExecution statementExecution = getDebugger().getStatementExecutor(id).execute(sql, maxRSRowsParsing, retainParsedRSDataRowCountThreshold); + public StatementExecution run(MessageContext context) { + StatementExecution statementExecution = getServerDebugger(context).getStatementExecutor(id).execute(sql, maxRSRowsParsing, retainParsedRSDataRowCountThreshold); return new ClientStatementExecution(statementExecution); } } - static class CMS_stopStatementExecutorExecution extends ServerDebuggerCommandMessage { + static class CMS_stopStatementExecutorExecution extends CommandMessage { private final int id; CMS_stopStatementExecutorExecution(int id) { @@ -303,13 +304,13 @@ class ServerDebugger extends LocalDebugger { } @Override - public Serializable run() { - getDebugger().removeStatementExecutor(id).stopExecution(); + public Serializable run(MessageContext context) { + getServerDebugger(context).removeStatementExecutor(id).stopExecution(); return null; } } - static class CMS_getStatementExecutorTableNames extends ServerDebuggerCommandMessage { + static class CMS_getStatementExecutorTableNames extends CommandMessage { private final int id; CMS_getStatementExecutorTableNames(int id) { @@ -317,12 +318,12 @@ class ServerDebugger extends LocalDebugger { } @Override - public String[] run() { - return getDebugger().getStatementExecutor(id).getTableNames(); + public String[] run(MessageContext context) { + return getServerDebugger(context).getStatementExecutor(id).getTableNames(); } } - static class CMS_getStatementExecutorTableColumnNames extends ServerDebuggerCommandMessage { + static class CMS_getStatementExecutorTableColumnNames extends CommandMessage { private final int id; CMS_getStatementExecutorTableColumnNames(int id) { @@ -330,11 +331,21 @@ class ServerDebugger extends LocalDebugger { } @Override - public String[] run() { - return getDebugger().getStatementExecutor(id).getTableColumnNames(); + public String[] run(MessageContext context) { + return getServerDebugger(context).getStatementExecutor(id).getTableColumnNames(); } } + /** + * Convenience method to extract a ServerDebugger from a MessageContext. + *

+ * This method is used for an intermediate [#1472] refactoring step and is + * likely to be removed again + */ + static ServerDebugger getServerDebugger(MessageContext context) { + return (ServerDebugger) context.getDebugger(); + } + void cleanup() { synchronized (idToStatementExecutorMap) { for(StatementExecutor executor: idToStatementExecutorMap.values()) { diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ServerDebuggerCommandMessage.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ServerDebuggerCommandMessage.java deleted file mode 100644 index 2946040397..0000000000 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/ServerDebuggerCommandMessage.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * Christopher Deckers, chrriis@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.debug.console.remote; - -import java.io.Serializable; - -import org.jooq.debug.console.remote.messaging.CommandMessage; - -/** - * @author Christopher Deckers - */ -@SuppressWarnings("serial") -abstract class ServerDebuggerCommandMessage extends CommandMessage { - - protected ServerDebugger getDebugger() { - return (ServerDebugger)((DebuggerCommmunicationInterface)getCommunicationInterface()).getDebugger(); - } - -} 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 4c0df1b0ea..ff31e92644 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 @@ -51,18 +51,19 @@ public abstract class CommandMessage extends Message */ private static final long serialVersionUID = -5396976580375899880L; - S runCommand() throws Exception { - return run(); + S runCommand(MessageContext context) throws Exception { + return run(context); } /** * Run the message. * + * @param context The context in which this {@link Message} object is run * @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. */ - public abstract S run() throws Exception; + public abstract S run(MessageContext context) throws Exception; // TODO: It looks as though args was only used for debugging purposes // maybe there is another way to access arguments? 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 9336e4580d..e2cb87ac67 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 @@ -42,8 +42,12 @@ import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; +import org.jooq.debug.Debugger; + /** - * The communication interface, which establishes the link between a peer VM and this local side. + * The communication interface, which establishes the link between a peer VM and + * this local side. + * * @author Christopher Deckers */ public class CommunicationInterface { @@ -51,6 +55,17 @@ public class CommunicationInterface { private final boolean IS_SYNCING_MESSAGES = Boolean.parseBoolean(System.getProperty("communication.interface.syncmessages")); private volatile boolean isOpen; + private final Debugger debugger; + private final int port; + + public CommunicationInterface(Debugger debugger, int port) { + this.debugger = debugger; + this.port = port; + } + + public Debugger getDebugger() { + return debugger; + } public boolean isOpen() { return isOpen; @@ -93,8 +108,6 @@ public class CommunicationInterface { protected void processClosed() { } - private int port; - private void createClientCommunicationChannel(String ip) throws Exception { // Create the interface to communicate with the process handling the other side Socket socket = null; @@ -120,10 +133,6 @@ public class CommunicationInterface { notifyOpen(); } - public CommunicationInterface(int port) { - this.port = port; - } - private volatile MessagingInterface messagingInterface; MessagingInterface getMessagingInterface() { @@ -138,10 +147,9 @@ public class CommunicationInterface { */ public final S syncSend(final Message message) { checkOpen(); - if(message instanceof LocalMessage) { + if (message instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) message; - localMessage.setCommunicationInterface(this); - return localMessage.runCommand(); + return localMessage.runCommand(new MessageContext(this)); } return messagingInterface.syncSend(message); } @@ -150,14 +158,14 @@ public class CommunicationInterface { * Send a message asynchronously. */ public final void asyncSend(final Message message) { - if(IS_SYNCING_MESSAGES) { + if (IS_SYNCING_MESSAGES) { syncSend(message); - } else { + } + else { checkOpen(); - if(message instanceof LocalMessage) { - LocalMessage localMessage = (LocalMessage)message; - localMessage.setCommunicationInterface(this); - localMessage.runCommand(); + if (message instanceof LocalMessage) { + LocalMessage localMessage = (LocalMessage) message; + localMessage.runCommand(new MessageContext(this)); return; } messagingInterface.asyncSend(message); 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 976f47a881..9dd5b544b5 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 @@ -39,28 +39,36 @@ package org.jooq.debug.console.remote.messaging; import java.io.Serializable; /** - * A local message is a special message that is not sent through the messaging interface. It is normally used to sequence a local command among remote commands. + * A local message is a special message that is not sent through the messaging + * interface. It is normally used to sequence a local command among remote + * commands. + * * @author Christopher Deckers */ -@SuppressWarnings("serial") public abstract class LocalMessage extends CommandMessage { - public LocalMessage() { - } + /** + * Generated UID + */ + private static final long serialVersionUID = 5946023022822987264L; + + public LocalMessage() {} @Override - S runCommand() { + S runCommand(MessageContext context) { try { - return super.runCommand(); - } catch(RuntimeException e) { + return super.runCommand(context); + } + catch (RuntimeException e) { throw e; - } catch(Exception e) { + } + catch (Exception e) { e.printStackTrace(); } return null; } @Override - public abstract S run(); + public abstract S run(MessageContext context); } diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/Message.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/Message.java index 829652cac0..2aa3e27960 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/Message.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/Message.java @@ -59,16 +59,6 @@ public abstract class Message implements Serializable { public Message() { } - private transient CommunicationInterface communicationInterface; - - void setCommunicationInterface(CommunicationInterface communicationInterface) { - this.communicationInterface = communicationInterface; - } - - protected CommunicationInterface getCommunicationInterface() { - return communicationInterface; - } - int getID() { return id; } diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/DebuggerCommmunicationInterface.java b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/MessageContext.java similarity index 70% rename from jOOQ-console/src/main/java/org/jooq/debug/console/remote/DebuggerCommmunicationInterface.java rename to jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/MessageContext.java index 117e7ac8fc..09cfba60c1 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/remote/DebuggerCommmunicationInterface.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/remote/messaging/MessageContext.java @@ -1,58 +1,70 @@ -/** - * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com - * Christopher Deckers, chrriis@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOQ" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package org.jooq.debug.console.remote; - -import org.jooq.debug.Debugger; -import org.jooq.debug.console.remote.messaging.CommunicationInterface; - -/** - * @author Christopher Deckers - */ -class DebuggerCommmunicationInterface extends CommunicationInterface { - - private Debugger debugger; - - public DebuggerCommmunicationInterface(Debugger debugger, int port) { - super(port); - this.debugger = debugger; - } - - public Debugger getDebugger() { - return debugger; - } - -} +/** + * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com + * Christopher Deckers, chrriis@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.jooq.debug.console.remote.messaging; + +import org.jooq.debug.Debugger; + +/** + * A wrapper object for types that are required in message execution contexts + *

+ * This type contains various objects that are needed when executing a + * {@link CommandMessage}. + * + * @author Lukas Eder + */ +public class MessageContext { + + private final Debugger debugger; + private final MessagingInterface messagingInterface; + + public MessageContext(CommunicationInterface comm) { + this(comm.getDebugger(), comm.getMessagingInterface()); + } + + public MessageContext(Debugger debugger, MessagingInterface messagingInterface) { + this.debugger = debugger; + this.messagingInterface = messagingInterface; + } + + public Debugger getDebugger() { + return debugger; + } + + public MessagingInterface getMessagingInterface() { + return messagingInterface; + } +} 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 402ac4f686..705128ccfd 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 @@ -168,11 +168,11 @@ class MessagingInterface { private Map originatorThreadIDToThreadMap = new HashMap(); - private CommunicationInterface communicationInterface; + private CommunicationInterface comm; private boolean isClient; MessagingInterface(final CommunicationInterface communicationInterface, final Socket socket, boolean isClient) { - this.communicationInterface = communicationInterface; + this.comm = communicationInterface; this.isClient = isClient; try { oos = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream()) { @@ -297,8 +297,7 @@ class MessagingInterface { Throwable throwable = null; if (message.isValid()) { try { - commandMessage.setCommunicationInterface(communicationInterface); - result = commandMessage.runCommand(); + result = commandMessage.runCommand(new MessageContext(comm)); } catch (Throwable t) { throwable = t; @@ -339,8 +338,8 @@ class MessagingInterface { @SuppressWarnings("unchecked") @Override - public Serializable run() { - MessagingInterface messagingInterface = getCommunicationInterface().getMessagingInterface(); + public Serializable run(MessageContext context) { + MessagingInterface messagingInterface = context.getMessagingInterface(); ThreadInfo threadInfo; synchronized (messagingInterface.idToThreadInfo) { threadInfo = (ThreadInfo) messagingInterface.idToThreadInfo.get(threadID); @@ -367,11 +366,10 @@ class MessagingInterface { } @Override - public Serializable run() { + public Serializable run(MessageContext context) { message.setSyncExec(false); - CommunicationInterface communicationInterface = getCommunicationInterface(); // message.setCommunicationInterface(communicationInterface); - MessagingInterface messagingInterface = communicationInterface.getMessagingInterface(); + MessagingInterface messagingInterface = context.getMessagingInterface(); CommandResultMessage commandResultMessage = messagingInterface.runMessage(message); CM_asyncExecResponse asyncExecResponse = new CM_asyncExecResponse(threadID, commandResultMessage); messagingInterface.asyncSend(asyncExecResponse);