diff --git a/jOOQ-console/src/main/java/org/jooq/debug/console/Console.java b/jOOQ-console/src/main/java/org/jooq/debug/console/Console.java index 9776cffdcb..03a28df971 100644 --- a/jOOQ-console/src/main/java/org/jooq/debug/console/Console.java +++ b/jOOQ-console/src/main/java/org/jooq/debug/console/Console.java @@ -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); diff --git a/jOOQ-console/src/main/java/org/jooq/tools/debug/Debugger.java b/jOOQ-console/src/main/java/org/jooq/tools/debug/Debugger.java index 3df51d6dc5..4b8e396cdd 100644 --- a/jOOQ-console/src/main/java/org/jooq/tools/debug/Debugger.java +++ b/jOOQ-console/src/main/java/org/jooq/tools/debug/Debugger.java @@ -77,4 +77,6 @@ public interface Debugger extends StatementExecutorCreator { public StatementExecutor createBreakpointHitStatementExecutor(long threadID); + public void close(); + } diff --git a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/ClientDebugger.java b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/ClientDebugger.java index 857e34869a..93e0fc6fb2 100644 --- a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/ClientDebugger.java +++ b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/ClientDebugger.java @@ -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(); diff --git a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/Communication.java b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/Communication.java index fd0c81dd74..dd16befe95 100644 --- a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/Communication.java +++ b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/Communication.java @@ -83,10 +83,6 @@ abstract class Communication { void notifyOpen() { isOpen = true; - processOpened(); - } - - protected void processOpened() { } void notifyKilled() { diff --git a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/DebugListener.java b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/DebugListener.java index 5b22b462a2..b09dbf764a 100644 --- a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/DebugListener.java +++ b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/DebugListener.java @@ -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 debuggerList = DebuggerRegistry.get(); diff --git a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/DebuggerRegistry.java b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/DebuggerRegistry.java deleted file mode 100644 index 3231eaa50b..0000000000 --- a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/DebuggerRegistry.java +++ /dev/null @@ -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 debuggers = new ArrayList(); - - 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 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(debuggers)); - } - } - -} diff --git a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/LocalDebugger.java b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/LocalDebugger.java index d711fd58c6..ad6d2b05bf 100644 --- a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/LocalDebugger.java +++ b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/LocalDebugger.java @@ -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 debuggers = new ArrayList(); + + 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 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(debuggers)); + } + } + + /** + * No instances + */ + private DebuggerRegistry() {} + } } diff --git a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/ServerCommunication.java b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/ServerCommunication.java index 553d8bf091..94208b4630 100644 --- a/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/ServerCommunication.java +++ b/jOOQ-console/src/main/java/org/jooq/tools/debug/impl/ServerCommunication.java @@ -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(); } }