[#1472] Add a Settings.executeDebugging property, and move

server-side Console logic to core

 - Pulled up DebuggerCommunicationInterface dependency on Debugger
to CommunicationInterface and removed original class
 - Removed transient dependency between Message and
CommunicationInterface (moved it into a new MessageContext, which
is passed to Message.run() methods)
This commit is contained in:
Lukas Eder 2012-09-09 13:20:43 +02:00
parent 45a5b808a3
commit c38526ac35
11 changed files with 187 additions and 264 deletions

View File

@ -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<Serializable> {
static class CMC_logQueries extends CommandMessage<Serializable> {
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<Serializable> {
static class CMC_logResultSet extends CommandMessage<Serializable> {
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<BreakpointHit> {
static class CMC_processBreakpointBeforeExecutionHit extends CommandMessage<BreakpointHit> {
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<BreakpointHit> {
static class CMC_processBreakpointAfterExecutionHit extends CommandMessage<BreakpointHit> {
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);

View File

@ -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<S extends Serializable> extends CommandMessage<S> {
protected ClientDebugger getDebugger() {
return (ClientDebugger)((DebuggerCommmunicationInterface)getCommunicationInterface()).getDebugger();
}
}

View File

@ -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);

View File

@ -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<Serializable> {
static class CMS_setLoggingActive extends CommandMessage<Serializable> {
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<Serializable> {
static class CMS_setLoggingStatementMatchers extends CommandMessage<Serializable> {
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<Serializable> {
static class CMS_setBreakpoints extends CommandMessage<Serializable> {
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<Serializable> {
static class CMS_addBreakpoint extends CommandMessage<Serializable> {
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<Serializable> {
static class CMS_modifyBreakpoint extends CommandMessage<Serializable> {
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<Serializable> {
static class CMS_removeBreakpoint extends CommandMessage<Serializable> {
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<Serializable> {
static class CMS_setBreakpointHitHandlerActive extends CommandMessage<Serializable> {
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<Boolean> {
static class CMS_isExecutionSupported extends CommandMessage<Boolean> {
@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<Serializable> {
static class CMS_createServerStatementExecutor extends CommandMessage<Serializable> {
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<StatementExecution> {
static class CMS_doStatementExecutorExecution extends CommandMessage<StatementExecution> {
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<Serializable> {
static class CMS_stopStatementExecutorExecution extends CommandMessage<Serializable> {
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<String[]> {
static class CMS_getStatementExecutorTableNames extends CommandMessage<String[]> {
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<String[]> {
static class CMS_getStatementExecutorTableColumnNames extends CommandMessage<String[]> {
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.
* <p>
* 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()) {

View File

@ -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<S extends Serializable> extends CommandMessage<S> {
protected ServerDebugger getDebugger() {
return (ServerDebugger)((DebuggerCommmunicationInterface)getCommunicationInterface()).getDebugger();
}
}

View File

@ -51,18 +51,19 @@ public abstract class CommandMessage<S extends Serializable> extends Message<S>
*/
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?

View File

@ -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 extends Serializable> S syncSend(final Message<S> message) {
checkOpen();
if(message instanceof LocalMessage) {
if (message instanceof LocalMessage) {
LocalMessage<S> localMessage = (LocalMessage<S>) 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 <S extends Serializable> void asyncSend(final Message<S> 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);

View File

@ -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<S extends Serializable> extends CommandMessage<S> {
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);
}

View File

@ -59,16 +59,6 @@ public abstract class Message<S extends Serializable> implements Serializable {
public Message() {
}
private transient CommunicationInterface communicationInterface;
void setCommunicationInterface(CommunicationInterface communicationInterface) {
this.communicationInterface = communicationInterface;
}
protected CommunicationInterface getCommunicationInterface() {
return communicationInterface;
}
int getID() {
return id;
}

View File

@ -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
* <p>
* 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;
}
}

View File

@ -168,11 +168,11 @@ class MessagingInterface {
private Map<Long, MessageProcessingThread> originatorThreadIDToThreadMap = new HashMap<Long, MessagingInterface.MessageProcessingThread>();
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<S> threadInfo;
synchronized (messagingInterface.idToThreadInfo) {
threadInfo = (ThreadInfo<S>) 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<S> commandResultMessage = messagingInterface.runMessage(message);
CM_asyncExecResponse<S> asyncExecResponse = new CM_asyncExecResponse<S>(threadID, commandResultMessage);
messagingInterface.asyncSend(asyncExecResponse);