Package com.mckoi.database.jdbcserver
Class StreamJDBCServerConnection
- java.lang.Object
-
- com.mckoi.database.jdbcserver.JDBCProcessor
-
- com.mckoi.database.jdbcserver.StreamJDBCServerConnection
-
- All Implemented Interfaces:
ProtocolConstants
,ServerConnection
- Direct Known Subclasses:
TCPJDBCServerConnection
abstract class StreamJDBCServerConnection extends JDBCProcessor implements ServerConnection
A generic JDBC stream protocol server that reads JDBC commands from a stream from each connection and dispatches the commands appropriately.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
INPUT_BUFFER_SIZE
The size in bytes of the buffer used for reading information from the input stream from the client.private LengthMarkedBufferedInputStream
marked_input
The LengthMarkedBufferedInputStream we use to poll for commands from the client.private java.io.DataOutputStream
out
The output stream to the client formatted as a DataOutputStream.private static int
OUTPUT_BUFFER_SIZE
The size in bytes of the buffer used for writing information onto the output stream to the client.-
Fields inherited from interface com.mckoi.database.jdbc.ProtocolConstants
ACKNOWLEDGEMENT, AUTHENTICATION_ERROR, CLOSE, DATABASE_EVENT, DISPOSE_RESULT, DISPOSE_STREAMABLE_OBJECT, EXCEPTION, FAILED, PING, PUSH_STREAMABLE_OBJECT_PART, QUERY, RESULT_SECTION, SERVER_REQUEST, STREAMABLE_OBJECT_SECTION, SUCCESS, USER_AUTHENTICATION_FAILED, USER_AUTHENTICATION_PASSED
-
-
Constructor Summary
Constructors Constructor Description StreamJDBCServerConnection(DatabaseInterface db_interface, java.io.InputStream in, java.io.OutputStream out, DebugLogger logger)
Sets up the protocol connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
blockForRequest()
Block waiting for a complete command to become available.void
ping()
Pings the client to check it's still alive.void
processRequest()
Processes a request from this connection.boolean
requestPending()
Inspects the input stream and determines in there's a command pending to be processed.void
sendEvent(byte[] event_msg)
Sends an event to the client.-
Methods inherited from class com.mckoi.database.jdbcserver.JDBCProcessor
close, dispose, finalize, getState, isClosed, printByteArray, processJDBCCommand
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.mckoi.database.jdbcserver.ServerConnection
close
-
-
-
-
Field Detail
-
OUTPUT_BUFFER_SIZE
private static final int OUTPUT_BUFFER_SIZE
The size in bytes of the buffer used for writing information onto the output stream to the client.- See Also:
- Constant Field Values
-
INPUT_BUFFER_SIZE
private static final int INPUT_BUFFER_SIZE
The size in bytes of the buffer used for reading information from the input stream from the client.- See Also:
- Constant Field Values
-
marked_input
private LengthMarkedBufferedInputStream marked_input
The LengthMarkedBufferedInputStream we use to poll for commands from the client.
-
out
private java.io.DataOutputStream out
The output stream to the client formatted as a DataOutputStream.
-
-
Constructor Detail
-
StreamJDBCServerConnection
StreamJDBCServerConnection(DatabaseInterface db_interface, java.io.InputStream in, java.io.OutputStream out, DebugLogger logger) throws java.io.IOException
Sets up the protocol connection.- Throws:
java.io.IOException
-
-
Method Detail
-
sendEvent
public void sendEvent(byte[] event_msg) throws java.io.IOException
Description copied from class:JDBCProcessor
Sends an event to the client. This is used to notify the client of trigger events, etc.SECURITY ISSUE: This is always invoked by the DatabaseDispatcher. We have to be careful that this method isn't allowed to block. Otherwise the DatabaseDispatcher thread will be out of operation. Unfortunately assuring this may not be possible until Java has non-blocking IO, or we use datagrams for transmission. I know for sure that the TCP implementation is vunrable. If the client doesn't 'read' what we are sending then this'll block when the buffers become full.
- Specified by:
sendEvent
in classJDBCProcessor
- Throws:
java.io.IOException
-
requestPending
public boolean requestPending() throws java.io.IOException
Inspects the input stream and determines in there's a command pending to be processed.- Specified by:
requestPending
in interfaceServerConnection
- Throws:
java.io.IOException
-
processRequest
public void processRequest() throws java.io.IOException
Processes a request from this connection.- Specified by:
processRequest
in interfaceServerConnection
- Throws:
java.io.IOException
-
blockForRequest
public void blockForRequest() throws java.io.IOException
Block waiting for a complete command to become available.- Specified by:
blockForRequest
in interfaceServerConnection
- Throws:
java.io.IOException
-
ping
public void ping() throws java.io.IOException
Pings the client to check it's still alive.- Specified by:
ping
in interfaceServerConnection
- Throws:
java.io.IOException
-
-