Package com.mckoi.database.jdbc
Class RemoteDatabaseInterface.ConnectionThread
- java.lang.Object
-
- java.lang.Thread
-
- com.mckoi.database.jdbc.RemoteDatabaseInterface.ConnectionThread
-
- All Implemented Interfaces:
java.lang.Runnable
- Enclosing class:
- RemoteDatabaseInterface
private class RemoteDatabaseInterface.ConnectionThread extends java.lang.Thread
The connection thread that can dispatch commands concurrently through the in/out pipe.
-
-
Field Summary
Fields Modifier and Type Field Description private RemoteDatabaseInterface.MByteArrayOutputStream
com_bytes
The command to write out to the server.private java.io.DataOutputStream
com_data
private java.util.Vector
commands_list
The list of commands received from the server that are pending to be processed (ServerCommand).private int
running_dispatch_id
Running dispatch id values which we use as a unique key.private boolean
thread_closed
Set to true when the thread is closed.
-
Constructor Summary
Constructors Constructor Description ConnectionThread()
Constructs the connection thread.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) int
disposeResult(int result_id)
Releases the server side resources associated with a given query key returned by the server.(package private) int
disposeStreamableObject(int result_id, long streamable_object_id)
Disposes the resources associated with a streamable object on the server.(package private) int
executeQuery(SQLQuery sql)
Sends a command to the server to process a query.private void
flushCommand()
Flushes the command in 'com_bytes' to the server.(package private) RemoteDatabaseInterface.ServerCommand
getCommand(int timeout, int dispatch_id)
Blocks until a response from the server has been received with the given dispatch id.(package private) int
getResultPart(int result_id, int row_number, int row_count)
Requests a part of a result of a query.(package private) int
getStreamableObjectPart(int result_id, long streamable_object_id, long offset, int length)
Requests a part of an open StreamableObject channel.private int
nextDispatchID()
Returns a unique dispatch id number for a command.private void
processEvent(byte[] buf)
Processes a server side event.(package private) int
pushStreamableObjectPart(byte type, long object_id, long object_length, byte[] buf, long offset, int length)
Pushes a part of a streamable object onto the server.void
run()
Listens for commands from the server.(package private) int
sendCloseCommand()
Sends close command to server.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
com_bytes
private RemoteDatabaseInterface.MByteArrayOutputStream com_bytes
The command to write out to the server.
-
com_data
private java.io.DataOutputStream com_data
-
running_dispatch_id
private int running_dispatch_id
Running dispatch id values which we use as a unique key.
-
thread_closed
private boolean thread_closed
Set to true when the thread is closed.
-
commands_list
private java.util.Vector commands_list
The list of commands received from the server that are pending to be processed (ServerCommand).
-
-
Method Detail
-
nextDispatchID
private int nextDispatchID()
Returns a unique dispatch id number for a command.
-
getCommand
RemoteDatabaseInterface.ServerCommand getCommand(int timeout, int dispatch_id) throws java.sql.SQLException
Blocks until a response from the server has been received with the given dispatch id. It waits for 'timeout' seconds and if the response hasn't been received by then returns null.- Throws:
java.sql.SQLException
-
flushCommand
private void flushCommand() throws java.io.IOException
Flushes the command in 'com_bytes' to the server.- Throws:
java.io.IOException
-
pushStreamableObjectPart
int pushStreamableObjectPart(byte type, long object_id, long object_length, byte[] buf, long offset, int length) throws java.io.IOException
Pushes a part of a streamable object onto the server. Used in preparation to executing queries containing large objects.- Throws:
java.io.IOException
-
executeQuery
int executeQuery(SQLQuery sql) throws java.io.IOException
Sends a command to the server to process a query. The response from the server will contain a 'result_id' that is a unique number for refering to the result. It also contains information about the columns in the table, and the total number of rows in the result.Returns the dispatch id key for the response from the server.
- Throws:
java.io.IOException
-
disposeResult
int disposeResult(int result_id) throws java.io.IOException
Releases the server side resources associated with a given query key returned by the server. This should be called when the ResultSet is closed, or if we cancel in the middle of downloading a result.It's very important that the server resources for a query is released.
Returns the dispatch id key for the response from the server.
- Throws:
java.io.IOException
-
getResultPart
int getResultPart(int result_id, int row_number, int row_count) throws java.io.IOException
Requests a part of a result of a query. This is used to download a part of a result set from the server. The 'result_id' is generated by the 'query' command. Please note that this will generate an error if the result_id is invalid or has previously been disposed. The 'row_number' refers to the row to download from. The 'row_count' refers to the number of rows to download.Returns the dispatch id key for the response from the server.
- Throws:
java.io.IOException
-
getStreamableObjectPart
int getStreamableObjectPart(int result_id, long streamable_object_id, long offset, int length) throws java.io.IOException
Requests a part of an open StreamableObject channel. This is used to download a section of a large object, such as a Blob or a Clob. The 'streamable_object_id' is returned by the 'getIdentifier' method of the StreamableObject in a ResultPart.Returns the dispatch id key for the response from the server.
- Throws:
java.io.IOException
-
disposeStreamableObject
int disposeStreamableObject(int result_id, long streamable_object_id) throws java.io.IOException
Disposes the resources associated with a streamable object on the server. This would typically be called when either of the following situations occured - the Blob is closed/disposed/finalized, the InputStream is closes/finalized.It's very important that the server resources for a streamable object is released.
Returns the dispatch id key for the response from the server.
- Throws:
java.io.IOException
-
sendCloseCommand
int sendCloseCommand() throws java.io.IOException
Sends close command to server.- Throws:
java.io.IOException
-
run
public void run()
Listens for commands from the server. When received puts the command on the dispatch list.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
processEvent
private void processEvent(byte[] buf) throws java.io.IOException
Processes a server side event.- Throws:
java.io.IOException
-
-