org.objectweb.cjdbc.controller.virtualdatabase
Class VirtualDatabaseWorkerThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread
All Implemented Interfaces:
java.lang.Runnable

public class VirtualDatabaseWorkerThread
extends java.lang.Thread

The VirtualDatabaseWorkerThread handles a connection with a C-JDBC driver.

Version:
1.0
Author:
Emmanuel Cecchet , Nicolas Modrzyk

Field Summary
private  CommandCompleted completed
           
private  Controller controller
           
private  CJDBCInputStream in
           
private  boolean isKilled
          true ifthis has been killed.
private  Trace logger
          Logger instance.
(package private)  boolean needSkeleton
          Needed for parsing
private  CJDBCOutputStream out
           
private  java.util.HashMap streamedResultSet
           
private static int threadID
           
private  VirtualDatabaseUser user
           
private  VirtualDatabase vdb
          Virtual database instantiating this thread.
private  boolean waitForCommand
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
VirtualDatabaseWorkerThread(Controller controller, VirtualDatabase vdb)
          Creates a new VirtualDatabaseWorkerThread instance.
 
Method Summary
 long getBytesRead()
          get bytes read
 long getBytesWritten()
          get bytes written
 long getReadingSpeed()
          get reading speed, WARNING!
 long getTimeActive()
          get time active
 java.lang.String getUser()
           
 long getWritingSpeed()
          get writing speed, WARNING!
private  StoredProcedure procedureFromStream(boolean isRead)
          Read a StoredProcedure from the stream.
private  SelectRequest readRequestFromStream()
          Read a SelectRequest from the stream.
 java.lang.String[] retrieveClientData()
          Retrieve general information on this client
 void run()
          Gets a connection from the connection queue and process it.
private  boolean setRequestParameters(AbstractRequest request, java.lang.String login, long tid, boolean transactionStarted)
          Set the login and transaction id on the given request.
 void shutdown()
          Shutdown this thread by setting isKilled value to true.
private  AbstractWriteRequest writeRequestFromStream(boolean withKeys)
          Read a write request send by the Connection object.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

threadID

private static int threadID

isKilled

private boolean isKilled
true ifthis has been killed.


needSkeleton

boolean needSkeleton
Needed for parsing


vdb

private VirtualDatabase vdb
Virtual database instantiating this thread.


completed

private final CommandCompleted completed

logger

private Trace logger
Logger instance.


in

private CJDBCInputStream in

out

private CJDBCOutputStream out

user

private VirtualDatabaseUser user

controller

private Controller controller

waitForCommand

private boolean waitForCommand

streamedResultSet

private java.util.HashMap streamedResultSet
Constructor Detail

VirtualDatabaseWorkerThread

public VirtualDatabaseWorkerThread(Controller controller,
                                   VirtualDatabase vdb)
Creates a new VirtualDatabaseWorkerThread instance.

Parameters:
controller - the thread was originated from
vdb - the virtual database instantiating this thread.
Method Detail

shutdown

public void shutdown()
Shutdown this thread by setting isKilled value to true. This gives time to check for needed rollback transactions


setRequestParameters

private boolean setRequestParameters(AbstractRequest request,
                                     java.lang.String login,
                                     long tid,
                                     boolean transactionStarted)
                              throws java.sql.SQLException
Set the login and transaction id on the given request. If the request is autocommit and a transaction was started, the transaction is first commited to return in autocommit mode.

Parameters:
request - The request to set
login - user login to set
tid - the transaction id to set
Returns:
new value of transaction started
Throws:
java.sql.SQLException

run

public void run()
Gets a connection from the connection queue and process it.


procedureFromStream

private StoredProcedure procedureFromStream(boolean isRead)
                                     throws java.io.OptionalDataException,
                                            java.io.IOException
Read a StoredProcedure from the stream.

Parameters:
isRead - true if we expect a read stored procedure
Returns:
the corresponding StoredProcedure object.
Throws:
java.io.OptionalDataException - if an error occurs
java.io.IOException - if an error occurs

writeRequestFromStream

private AbstractWriteRequest writeRequestFromStream(boolean withKeys)
                                             throws java.io.OptionalDataException,
                                                    java.io.IOException
Read a write request send by the Connection object. Only the needed parameters are sent, so we can reconstruct the object on the controller side, without serializing everything.

Parameters:
withKeys - true if we expect a write to return keus (as a ResultSet)
Returns:
an instace of the AbstractWriteRequest
Throws:
java.io.OptionalDataException
java.io.IOException

readRequestFromStream

private SelectRequest readRequestFromStream()
                                     throws java.io.OptionalDataException,
                                            java.io.IOException
Read a SelectRequest from the stream.

Returns:
the corresponding SelectRequest object.
Throws:
java.io.OptionalDataException - if an error occurs
java.io.IOException - if an error occurs

retrieveClientData

public java.lang.String[] retrieveClientData()
Retrieve general information on this client

Returns:
an array of string

getBytesRead

public long getBytesRead()
get bytes read

Returns:
bytes read

getBytesWritten

public long getBytesWritten()
get bytes written

Returns:
bytes written

getTimeActive

public long getTimeActive()
get time active

Returns:
time active since started

getReadingSpeed

public long getReadingSpeed()
get reading speed, WARNING! This is approximate

Returns:
reading speed

getWritingSpeed

public long getWritingSpeed()
get writing speed, WARNING! This is approximate

Returns:
writing speed

getUser

public java.lang.String getUser()
Returns:
Returns the login of the current user.


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.