[#1393] Communication protocol between Console server and client - code

cleanup and API adjustments.
This commit is contained in:
Chrriis 2012-05-04 17:54:43 +02:00
parent 130e6b1024
commit f3591a3b47
7 changed files with 28 additions and 442 deletions

View File

@ -103,9 +103,34 @@ public class Console extends JFrame {
private JTabbedPane mainTabbedPane;
private JTabbedPane editorTabbedPane;
public Console(DatabaseDescriptor editorDatabaseDescriptor, boolean isShowingLoggingTab) {
debugger = new 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.addSqlQueryDebugger(debugger);
}
@Override
public void windowClosed(WindowEvent e) {
DebuggerRegistry.removeSqlQueryDebugger(debugger);
}
});
init(isShowingLoggingTab);
}
public Console(final Debugger debugger, boolean isShowingLoggingTab) {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.debugger = debugger;
this.debugger = debugger;
// Local debugger registration is handled externally if needed (e.g.: remote client must not be registered).
init(isShowingLoggingTab);
}
/**
* @param debugger
* @param isShowingLoggingTab
*/
private void init(boolean isShowingLoggingTab) {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic('F');
@ -382,15 +407,8 @@ public class Console extends JFrame {
}
public static void openConsole(DatabaseDescriptor databaseDescriptor, boolean isLoggingActive) {
final LocalDebugger debugger = new LocalDebugger(databaseDescriptor);
Console sqlConsoleFrame = new Console(debugger, true);
Console sqlConsoleFrame = new Console(databaseDescriptor, true);
sqlConsoleFrame.setLoggingActive(isLoggingActive);
sqlConsoleFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
DebuggerRegistry.removeSqlQueryDebugger(debugger);
}
});
sqlConsoleFrame.setVisible(true);
}

View File

@ -1,57 +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 org.jooq.debug.QueryLoggingData;
/**
* @author Christopher Deckers
*/
@SuppressWarnings("serial")
public class ClientDebugQueriesMessage implements Message {
private QueryLoggingData sqlQueryDebuggerData;
public ClientDebugQueriesMessage(QueryLoggingData sqlQueryDebuggerData) {
this.sqlQueryDebuggerData = sqlQueryDebuggerData;
}
public QueryLoggingData getSqlQueryDebuggerData() {
return sqlQueryDebuggerData;
}
}

View File

@ -1,63 +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 org.jooq.debug.ResultSetLoggingData;
/**
* @author Christopher Deckers
*/
@SuppressWarnings("serial")
public class ClientDebugResultSetMessage implements Message {
private int sqlQueryDebuggerDataID;
private ResultSetLoggingData sqlQueryDebuggerResultSetData;
public ClientDebugResultSetMessage(int sqlQueryDebuggerDataID, ResultSetLoggingData sqlQueryDebuggerData) {
this.sqlQueryDebuggerDataID = sqlQueryDebuggerDataID;
this.sqlQueryDebuggerResultSetData = sqlQueryDebuggerData;
}
public int getSqlQueryDebuggerDataID() {
return sqlQueryDebuggerDataID;
}
public ResultSetLoggingData getSqlQueryDebuggerResultSetData() {
return sqlQueryDebuggerResultSetData;
}
}

View File

@ -1,46 +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;
/**
* @author Christopher Deckers
*/
public interface Message extends Serializable {
}

View File

@ -1,154 +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.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import org.jooq.debug.Debugger;
import org.jooq.debug.LoggingListener;
import org.jooq.debug.QueryLoggingData;
import org.jooq.debug.ResultSetLoggingData;
import org.jooq.debug.StatementExecutor;
import org.jooq.debug.StatementMatcher;
/**
* @author Christopher Deckers
*/
public class RemoteDebuggerClient implements Debugger {
private Socket socket;
private ObjectOutputStream out;
private final Object LOCK = new Object();
public RemoteDebuggerClient(String ip, int port) throws Exception {
socket = new Socket(ip, port);
out = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream()));
Thread thread = new Thread("SQL Remote Debugger Client on port " + port) {
@Override
public void run() {
try {
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
for(Message o; (o=(Message)in.readObject()) != null; ) {
if(o instanceof ClientDebugQueriesMessage) {
LoggingListener loggingListener_;
synchronized (LOCK) {
loggingListener_ = loggingListener;
}
if(loggingListener_ != null) {
QueryLoggingData sqlQueryDebuggerData = ((ClientDebugQueriesMessage) o).getSqlQueryDebuggerData();
loggingListener_.logQueries(sqlQueryDebuggerData);
}
} else if(o instanceof ClientDebugResultSetMessage) {
LoggingListener loggingListener_;
synchronized (LOCK) {
loggingListener_ = loggingListener;
}
if(loggingListener_ != null) {
ClientDebugResultSetMessage m = (ClientDebugResultSetMessage) o;
int sqlQueryDebuggerDataID = m.getSqlQueryDebuggerDataID();
ResultSetLoggingData clientDebugResultSetData = m.getSqlQueryDebuggerResultSetData();
loggingListener_.logResultSet(sqlQueryDebuggerDataID, clientDebugResultSetData);
}
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
};
thread.setDaemon(true);
thread.start();
}
private LoggingListener loggingListener;
@Override
public void setLoggingListener(LoggingListener loggingListener) {
synchronized (LOCK) {
this.loggingListener = loggingListener;
try {
out.writeObject(new ServerLoggingActivationMessage(loggingListener != null));
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public LoggingListener getLoggingListener() {
return loggingListener;
}
private StatementMatcher[] loggingStatementMatchers;
@Override
public void setLoggingStatementMatchers(StatementMatcher[] loggingStatementMatchers) {
this.loggingStatementMatchers = loggingStatementMatchers;
try {
synchronized (LOCK) {
out.writeObject(new ServerLoggingStatementMatchersMessage(loggingStatementMatchers));
out.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public StatementMatcher[] getLoggingStatementMatchers() {
return loggingStatementMatchers;
}
@Override
public boolean isExecutionSupported() {
// TODO: implement
return false;
}
@Override
public StatementExecutor createStatementExecutor() {
// TODO: implement
return null;
}
}

View File

@ -1,55 +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;
/**
* @author Christopher Deckers
*/
@SuppressWarnings("serial")
public class ServerLoggingActivationMessage implements Message {
private boolean isLogging;
public ServerLoggingActivationMessage(boolean isLogging) {
this.isLogging = isLogging;
}
public boolean isLogging() {
return isLogging;
}
}

View File

@ -1,57 +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 org.jooq.debug.StatementMatcher;
/**
* @author Christopher Deckers
*/
@SuppressWarnings("serial")
public class ServerLoggingStatementMatchersMessage implements Message {
private StatementMatcher[] statementMatchers;
public ServerLoggingStatementMatchersMessage(StatementMatcher[] statementMatchers) {
this.statementMatchers = statementMatchers;
}
public StatementMatcher[] getStatementMatchers() {
return statementMatchers;
}
}