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

server-side Console logic to core - Remove DebuggerRegistry from
the public API
This commit is contained in:
Lukas Eder 2012-09-09 15:10:35 +02:00
parent 7c60d72448
commit 46c6eb4a96
8 changed files with 71 additions and 115 deletions

View File

@ -76,7 +76,6 @@ import org.jooq.debug.console.misc.JSedRegExBuilder;
import org.jooq.tools.debug.DatabaseDescriptor;
import org.jooq.tools.debug.Debugger;
import org.jooq.tools.debug.impl.DebuggerFactory;
import org.jooq.tools.debug.impl.DebuggerRegistry;
/**
* @author Christopher Deckers
@ -93,13 +92,9 @@ public class Console extends JFrame {
debugger = DebuggerFactory.localDebugger(editorDatabaseDescriptor);
// Local debugger registration is managed by the console since it hides the debugger.
addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
DebuggerRegistry.add(debugger);
}
@Override
public void windowClosed(WindowEvent e) {
DebuggerRegistry.remove(debugger);
debugger.close();
}
});
init(isShowingLoggingTab, isShowingDebugger);

View File

@ -77,4 +77,6 @@ public interface Debugger extends StatementExecutorCreator {
public StatementExecutor createBreakpointHitStatementExecutor(long threadID);
public void close();
}

View File

@ -77,6 +77,9 @@ class ClientDebugger implements Debugger {
return comm;
}
@Override
public void close() {}
private LoggingListener loggingListener;
private final Object LOGGING_LISTENER_LOCK = new Object();

View File

@ -83,10 +83,6 @@ abstract class Communication {
void notifyOpen() {
isOpen = true;
processOpened();
}
protected void processOpened() {
}
void notifyKilled() {

View File

@ -60,13 +60,28 @@ import org.jooq.tools.debug.StatementInfo;
import org.jooq.tools.debug.StatementLog;
import org.jooq.tools.debug.StatementMatcher;
import org.jooq.tools.debug.StatementProcessor;
import org.jooq.tools.debug.impl.LocalDebugger.DebuggerRegistry;
/**
* @author Christopher Deckers
*/
public class DebugListener extends DefaultExecuteListener {
private boolean hasDebuggers;
private boolean hasDebuggers;
private long startPreparationTime;
private long aggregatedPreparationDuration;
private long startBindTime;
private long endBindTime;
private long startExecutionTime;
private long endExecutionTime;
private String matchingSQL;
private String matchingParameterDescription;
private String effectiveSQL;
private Breakpoint matchingBreakpoint;
private Debugger matchingDebugger = null;
@Override
public void renderStart(ExecuteContext ctx) {
@ -79,9 +94,6 @@ public class DebugListener extends DefaultExecuteListener {
endExecutionTime = 0;
}
private long startPreparationTime;
private long aggregatedPreparationDuration;
@Override
public void prepareStart(ExecuteContext ctx) {
if(!hasDebuggers) {
@ -104,9 +116,6 @@ public class DebugListener extends DefaultExecuteListener {
}
}
private long startBindTime;
private long endBindTime;
@Override
public void bindStart(ExecuteContext ctx) {
if(!hasDebuggers) {
@ -123,14 +132,6 @@ public class DebugListener extends DefaultExecuteListener {
endBindTime = System.currentTimeMillis();
}
private long startExecutionTime;
private long endExecutionTime;
private String matchingSQL;
private String matchingParameterDescription;
private String effectiveSQL;
private Breakpoint matchingBreakpoint;
private Debugger matchingDebugger = null;
@Override
public void executeStart(ExecuteContext ctx) {
List<Debugger> debuggerList = DebuggerRegistry.get();

View File

@ -1,84 +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.tools.debug.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jooq.tools.debug.Debugger;
/**
* @author Christopher Deckers
*/
public class DebuggerRegistry {
private DebuggerRegistry() {}
private static final Object LOCK = new Object();
private static final List<Debugger> debuggers = new ArrayList<Debugger>();
public static void add(Debugger sqlQueryDebugger) {
synchronized (LOCK) {
debuggers.add(sqlQueryDebugger);
}
}
public static void remove(Debugger sqlQueryDebugger) {
synchronized (LOCK) {
debuggers.remove(sqlQueryDebugger);
}
}
/*
* @return an immutable list of all the debuggers currently registered.
*/
public static List<Debugger> get() {
synchronized (LOCK) {
// No cost when no loggers
if (debuggers.isEmpty()) {
return Collections.emptyList();
}
// Small cost: copy collection and make it immutable.
// Generally, no more than one or two listeners in the list.
return Collections.unmodifiableList(new ArrayList<Debugger>(debuggers));
}
}
}

View File

@ -70,11 +70,17 @@ class LocalDebugger implements Debugger {
public LocalDebugger(DatabaseDescriptor databaseDescriptor) {
this.databaseDescriptor = databaseDescriptor;
DebuggerRegistry.add(this);
}
private LoggingListener loggingListener;
private final Object LOGGING_LISTENER_LOCK = new Object();
@Override
public void close() {
DebuggerRegistry.remove(this);
}
@Override
public void setLoggingListener(LoggingListener loggingListener) {
synchronized (LOGGING_LISTENER_LOCK) {
@ -352,4 +358,46 @@ class LocalDebugger implements Debugger {
});
}
/**
* A registry for local debuggers
*/
static class DebuggerRegistry {
private static final Object LOCK = new Object();
private static final List<Debugger> debuggers = new ArrayList<Debugger>();
private static void add(Debugger debugger) {
synchronized (LOCK) {
debuggers.add(debugger);
}
}
private static void remove(Debugger debugger) {
synchronized (LOCK) {
debuggers.remove(debugger);
}
}
/*
* @return an immutable list of all the debuggers currently registered.
*/
public static List<Debugger> get() {
synchronized (LOCK) {
// No cost when no loggers
if (debuggers.isEmpty()) {
return Collections.emptyList();
}
// Small cost: copy collection and make it immutable.
// Generally, no more than one or two listeners in the list.
return Collections.unmodifiableList(new ArrayList<Debugger>(debuggers));
}
}
/**
* No instances
*/
private DebuggerRegistry() {}
}
}

View File

@ -52,14 +52,9 @@ final class ServerCommunication extends Communication {
return (ServerDebugger) super.getDebugger();
}
@Override
protected void processOpened() {
DebuggerRegistry.add(getDebugger());
}
@Override
protected void processClosed() {
DebuggerRegistry.remove(getDebugger());
getDebugger().close();
getDebugger().cleanup();
}
}