org.objectweb.cjdbc.controller.requestmanager
Class RequestManager

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.requestmanager.RequestManager
Direct Known Subclasses:
DistributedRequestManager

public class RequestManager
extends java.lang.Object

This class defines the Request Manager.

The RM is composed of a Request Scheduler, an optional Query Cache, and a Load Balancer and an optional Recovery Log.

Version:
1.0
Author:
Emmanuel Cecchet, Julie Marguerite, Nicolas Modrzyk, Vadim Kassin

Field Summary
private  long beginTimeout
           
private  int cacheParsingranularity
           
private  long commitTimeout
           
private  DatabaseSchema dbs
           
private  int execWriteRequestResult
           
private  java.sql.ResultSet execWriteRequestWithKeysResult
           
protected  AbstractLoadBalancer loadBalancer
          The request load balancer to use to send requests to the databases
private  int loadBalancerParsingranularity
           
private static Trace logger
           
private  ParsingCache parsingCache
           
protected  AbstractRecoveryLog recoveryLog
          An optional recovery log
protected  AbstractRequestCache requestCache
          An optional request cache to cache responses to SQL requests
private  int requiredGranularity
           
private  long rollbackTimeout
           
protected  AbstractScheduler scheduler
          The request scheduler to order and schedule requests
private  int schedulerParsingranularity
           
private  boolean schemaIsStatic
           
private  java.util.Hashtable tidLoginTable
           
private  VirtualDatabase vdb
           
 
Constructor Summary
RequestManager(VirtualDatabase vdb, AbstractScheduler scheduler, AbstractLoadBalancer loadBalancer, AbstractRecoveryLog recoveryLog, long beginTimeout, long commitTimeout, long rollbackTimeout)
          Creates a new RequestManager instance without cache.
RequestManager(VirtualDatabase vdb, AbstractScheduler scheduler, AbstractLoadBalancer loadBalancer, long beginTimeout, long commitTimeout, long rollbackTimeout)
          Creates a new RequestManager instance without cache and log recovery.
RequestManager(VirtualDatabase vdb, AbstractScheduler scheduler, AbstractRequestCache cache, AbstractLoadBalancer loadBalancer, AbstractRecoveryLog recoveryLog, long beginTimeout, long commitTimeout, long rollbackTimeout)
          Creates a new RequestManager instance.
RequestManager(VirtualDatabase vdb, AbstractScheduler scheduler, AbstractRequestCache cache, AbstractLoadBalancer loadBalancer, long beginTimeout, long commitTimeout, long rollbackTimeout)
          Creates a new RequestManager instance without log recovery.
 
Method Summary
private  void addWorkerTask(BackendWorkerThread bwt, AbstractTask task)
          Add a task to a BackendWorkerThread using the proper synchronization.
private  void assignAndCheckSchedulerLoadBalancerValidity(AbstractScheduler scheduler, AbstractLoadBalancer loadBalancer)
          Check that Scheduler and Load Balancer are not null and have compatible RAIDb levels.
 int begin(java.lang.String login)
          Begin a new transaction and return the corresponding transaction identifier.
 void commit(int transactionId)
          Commit a transaction given its id.
 void disableBackend(DatabaseBackend db)
          Disable a backend that is currently enabled on this virtual database.
 void disableBackendForCheckpoint(DatabaseBackend db, java.lang.String checkpointName)
          The backend must belong to this virtual database and be in the enabled state.
 void enableBackend(DatabaseBackend db)
          Enable a backend that has been previously added to this virtual database and that is in the disabled state.
 void enableBackendFromCheckpoint(DatabaseBackend db, java.lang.String checkpointName)
          The backend must have been previously added to this virtual database and be in the disabled state.
 java.sql.ResultSet execReadRequest(SelectRequest request)
          Perform a read request and return the reply.
 java.sql.ResultSet execReadStoredProcedure(StoredProcedure proc)
          Call a stored procedure that returns a ResultSet.
 int execWriteRequest(AbstractWriteRequest request)
          Perform a write request and return the number of rows affected Call first the scheduler (if defined), then notify the cache (if defined) and finally call the load balancer.
private  void execWriteRequest(AbstractWriteRequest request, boolean useKeys)
          Common code for execWriteRequest(AbstractWriteRequest) and execWriteRequestWithKeys(AbstractWriteRequest).
 java.sql.ResultSet execWriteRequestWithKeys(AbstractWriteRequest request)
          Perform a write request and return the auto generated keys.
 int execWriteStoredProcedure(StoredProcedure proc)
          Call a stored procedure that performs an update.
 DatabaseSchema getDatabaseSchema()
          Get the DatabaseSchema used by this Request Manager.
 java.lang.String getInformation()
          Get information about this Request Controller
 AbstractLoadBalancer getLoadBalancer()
          Get the Request Load Balancer used in this Request Controller.
 AbstractRecoveryLog getRecoveryLog()
          Returns the Recovery Log Manager.
 AbstractRequestCache getRequestCache()
          Get the Request Cache (if any) used in this Request Controller.
 int getRequiredParsingGranularity()
           
 AbstractScheduler getScheduler()
          Get the Request Scheduler (if any) used in this Request Controller.
 java.lang.String getXmlInformation()
          Get xml information about this Request Controller
private  void initRequestManagerVariables(VirtualDatabase vdb, long beginTimeout, long commitTimeout, long rollbackTimeout)
          Method initRequestManagerVariables.
 void mergeDatabaseSchema(DatabaseSchema backendSchema)
          Merge the given schema with the existing database schema.
 void rollback(int transactionId)
          Rollback a transaction given its id.
 void setBackgroundParsing(boolean backgroundParsing)
          Sets the background parsing.
 void setCaseSensitiveParsing(boolean isCaseSensitiveParsing)
          Sets the parsing case sensitivity.
 void setDatabaseSchema(DatabaseSchema schema, boolean isStatic)
          Sets the DatabaseSchema to be able to parse the requests and find dependencies.
 void setLoadBalancer(AbstractLoadBalancer loadBalancer)
          Set the Request Load Balancer to use in this Request Controller.
 void setRecoveryLog(AbstractRecoveryLog recoveryLog)
          Sets the Recovery Log Manager.
 void setRequestCache(AbstractRequestCache cache)
          Set the Request Cache to use in this Request Controller.
 void setScheduler(AbstractScheduler scheduler)
          Set the Request Scheduler to use in this Request Controller.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beginTimeout

private long beginTimeout

commitTimeout

private long commitTimeout

rollbackTimeout

private long rollbackTimeout

scheduler

protected AbstractScheduler scheduler
The request scheduler to order and schedule requests


requestCache

protected AbstractRequestCache requestCache
An optional request cache to cache responses to SQL requests


loadBalancer

protected AbstractLoadBalancer loadBalancer
The request load balancer to use to send requests to the databases


recoveryLog

protected AbstractRecoveryLog recoveryLog
An optional recovery log


vdb

private VirtualDatabase vdb

dbs

private DatabaseSchema dbs

schemaIsStatic

private boolean schemaIsStatic

parsingCache

private ParsingCache parsingCache

schedulerParsingranularity

private int schedulerParsingranularity

cacheParsingranularity

private int cacheParsingranularity

loadBalancerParsingranularity

private int loadBalancerParsingranularity

requiredGranularity

private int requiredGranularity

tidLoginTable

private java.util.Hashtable tidLoginTable

logger

private static Trace logger

execWriteRequestResult

private int execWriteRequestResult

execWriteRequestWithKeysResult

private java.sql.ResultSet execWriteRequestWithKeysResult
Constructor Detail

RequestManager

public RequestManager(VirtualDatabase vdb,
                      AbstractScheduler scheduler,
                      AbstractLoadBalancer loadBalancer,
                      long beginTimeout,
                      long commitTimeout,
                      long rollbackTimeout)
               throws java.sql.SQLException
Creates a new RequestManager instance without cache and log recovery.

Parameters:
vdb - the virtual database this request manager belongs to
scheduler - the Request Scheduler to use
loadBalancer - the Request Load Balancer to use
beginTimeout - timeout in seconds for begin
commitTimeout - timeout in seconds for commit
rollbackTimeout - timeout in seconds for rollback
Throws:
java.sql.SQLException - if an error occurs

RequestManager

public RequestManager(VirtualDatabase vdb,
                      AbstractScheduler scheduler,
                      AbstractRequestCache cache,
                      AbstractLoadBalancer loadBalancer,
                      long beginTimeout,
                      long commitTimeout,
                      long rollbackTimeout)
               throws java.sql.SQLException
Creates a new RequestManager instance without log recovery.

Parameters:
vdb - the virtual database this request manager belongs to
scheduler - the Request Scheduler to use
cache - a Query Cache implementation
loadBalancer - the Request Load Balancer to use
beginTimeout - timeout in seconds for begin
commitTimeout - timeout in seconds for commit
rollbackTimeout - timeout in seconds for rollback
Throws:
java.sql.SQLException - if an error occurs

RequestManager

public RequestManager(VirtualDatabase vdb,
                      AbstractScheduler scheduler,
                      AbstractLoadBalancer loadBalancer,
                      AbstractRecoveryLog recoveryLog,
                      long beginTimeout,
                      long commitTimeout,
                      long rollbackTimeout)
               throws java.sql.SQLException
Creates a new RequestManager instance without cache.

Parameters:
vdb - the virtual database this request manager belongs to
scheduler - the Request Scheduler to use
loadBalancer - the Request Load Balancer to use
recoveryLog - the Log Recovery to use
beginTimeout - timeout in seconds for begin
commitTimeout - timeout in seconds for commit
rollbackTimeout - timeout in seconds for rollback
Throws:
java.sql.SQLException - if an error occurs

RequestManager

public RequestManager(VirtualDatabase vdb,
                      AbstractScheduler scheduler,
                      AbstractRequestCache cache,
                      AbstractLoadBalancer loadBalancer,
                      AbstractRecoveryLog recoveryLog,
                      long beginTimeout,
                      long commitTimeout,
                      long rollbackTimeout)
               throws java.sql.SQLException
Creates a new RequestManager instance.

Parameters:
vdb - the virtual database this request manager belongs to
scheduler - the Request Scheduler to use
cache - a Query Cache implementation
loadBalancer - the Request Load Balancer to use
recoveryLog - the Log Recovery to use
beginTimeout - timeout in seconds for begin
commitTimeout - timeout in seconds for commit
rollbackTimeout - timeout in seconds for rollback
Throws:
java.sql.SQLException - if an error occurs
Method Detail

assignAndCheckSchedulerLoadBalancerValidity

private void assignAndCheckSchedulerLoadBalancerValidity(AbstractScheduler scheduler,
                                                         AbstractLoadBalancer loadBalancer)
                                                  throws java.sql.SQLException
Check that Scheduler and Load Balancer are not null and have compatible RAIDb levels.

Parameters:
scheduler -
loadBalancer -
Throws:
java.sql.SQLException - if an error occurs

initRequestManagerVariables

private void initRequestManagerVariables(VirtualDatabase vdb,
                                         long beginTimeout,
                                         long commitTimeout,
                                         long rollbackTimeout)
Method initRequestManagerVariables.

Parameters:
vdb -
beginTimeout -
commitTimeout -
rollbackTimeout -

execReadRequest

public java.sql.ResultSet execReadRequest(SelectRequest request)
                                   throws java.sql.SQLException
Perform a read request and return the reply. Call first the scheduler (if defined), then the cache (if defined) and finally the load balancer.

Parameters:
request - the request to execute
Returns:
a java.sql.ResultSet value
Throws:
java.sql.SQLException - if an error occurs

execWriteRequest

public int execWriteRequest(AbstractWriteRequest request)
                     throws java.sql.SQLException
Perform a write request and return the number of rows affected Call first the scheduler (if defined), then notify the cache (if defined) and finally call the load balancer.

Parameters:
request - the request to execute
Returns:
number of rows affected
Throws:
java.sql.SQLException - if an error occurs

execWriteRequestWithKeys

public java.sql.ResultSet execWriteRequestWithKeys(AbstractWriteRequest request)
                                            throws java.sql.SQLException
Perform a write request and return the auto generated keys. Call first the scheduler (if defined), then notify the cache (if defined) and finally call the load balancer.

Parameters:
request - the request to execute
Returns:
auto generated keys.
Throws:
java.sql.SQLException - if an error occurs

execWriteRequest

private void execWriteRequest(AbstractWriteRequest request,
                              boolean useKeys)
                       throws java.sql.SQLException
Common code for execWriteRequest(AbstractWriteRequest) and execWriteRequestWithKeys(AbstractWriteRequest). The result is given back using member variables execWriteRequestResult and execWriteRequestWithKeysResult defined above.

Parameters:
request - the request to execute
useKeys - true if this must give an auto generated keys ResultSet
Throws:
java.sql.SQLException - if an error occurs

execReadStoredProcedure

public java.sql.ResultSet execReadStoredProcedure(StoredProcedure proc)
                                           throws java.sql.SQLException
Call a stored procedure that returns a ResultSet.

Parameters:
proc - the stored procedure call
Returns:
a java.sql.ResultSet value
Throws:
java.sql.SQLException - if an error occurs

execWriteStoredProcedure

public int execWriteStoredProcedure(StoredProcedure proc)
                             throws java.sql.SQLException
Call a stored procedure that performs an update.

Parameters:
proc - the stored procedure call
Returns:
number of rows affected
Throws:
java.sql.SQLException - if an error occurs

begin

public int begin(java.lang.String login)
          throws java.sql.SQLException
Begin a new transaction and return the corresponding transaction identifier. This method is called from the driver when setAutoCommit(false) is called.

Parameters:
login - the login used by the connection
Returns:
int a unique transaction identifier
Throws:
java.sql.SQLException - if an error occurs

commit

public void commit(int transactionId)
            throws java.sql.SQLException
Commit a transaction given its id.

Parameters:
transactionId - the transaction id
Throws:
java.sql.SQLException - if an error occurs

rollback

public void rollback(int transactionId)
              throws java.sql.SQLException
Rollback a transaction given its id.

Parameters:
transactionId - the transaction id
Throws:
java.sql.SQLException - if an error occurs

enableBackend

public void enableBackend(DatabaseBackend db)
                   throws java.sql.SQLException
Enable a backend that has been previously added to this virtual database and that is in the disabled state.

The backend is enabled without further check.

The enableBackend method of the load balancer is called.

Parameters:
db - The database backend to enable
Throws:
java.sql.SQLException - if an error occurs

addWorkerTask

private void addWorkerTask(BackendWorkerThread bwt,
                           AbstractTask task)
Add a task to a BackendWorkerThread using the proper synchronization.

Parameters:
bwt - BackendWorkerThread to synchronize on
task - the task to add to the thread queue

enableBackendFromCheckpoint

public void enableBackendFromCheckpoint(DatabaseBackend db,
                                        java.lang.String checkpointName)
                                 throws java.sql.SQLException
The backend must have been previously added to this virtual database and be in the disabled state.

All the queries since the given checkpoint are played and the backend state is set to enabled when it is completely synchronized.

Parameters:
db - The database backend to enable
checkpointName - The checkpoint name to restart from
Throws:
java.sql.SQLException - if an error occurs

disableBackend

public void disableBackend(DatabaseBackend db)
                    throws java.sql.SQLException
Disable a backend that is currently enabled on this virtual database.

The backend is disabled without further check.

The load balancer disabled method is called on the specified backend.

Parameters:
db - The database backend to disable
Throws:
java.sql.SQLException - if an error occurs

disableBackendForCheckpoint

public void disableBackendForCheckpoint(DatabaseBackend db,
                                        java.lang.String checkpointName)
                                 throws java.sql.SQLException
The backend must belong to this virtual database and be in the enabled state.

The backend is disabled once all the pending write queries are executed. A checkpoint is inserted in the recovery log.

Parameters:
db - The database backend to enable
checkpointName - The checkpoint name to restart from
Throws:
java.sql.SQLException - if an error occurs

setDatabaseSchema

public void setDatabaseSchema(DatabaseSchema schema,
                              boolean isStatic)
Sets the DatabaseSchema to be able to parse the requests and find dependencies.

Parameters:
schema - a DatabaseSchema value
isStatic - true if the given schema is static

mergeDatabaseSchema

public void mergeDatabaseSchema(DatabaseSchema backendSchema)
Merge the given schema with the existing database schema.

Parameters:
backendSchema - The virtual database schema to merge.

getDatabaseSchema

public DatabaseSchema getDatabaseSchema()
Get the DatabaseSchema used by this Request Manager.

Returns:
a DatabaseSchema value

getLoadBalancer

public AbstractLoadBalancer getLoadBalancer()
Get the Request Load Balancer used in this Request Controller.

Returns:
an AbstractLoadBalancer value

setLoadBalancer

public void setLoadBalancer(AbstractLoadBalancer loadBalancer)
Set the Request Load Balancer to use in this Request Controller.

Parameters:
loadBalancer - a Request Load Balancer implementation

getRequestCache

public AbstractRequestCache getRequestCache()
Get the Request Cache (if any) used in this Request Controller.

Returns:
an AbstractRequestCache value or null if no Request Cache has been defined

getRecoveryLog

public AbstractRecoveryLog getRecoveryLog()
Returns the Recovery Log Manager.

Returns:
AbstractRecoveryLog

setRecoveryLog

public void setRecoveryLog(AbstractRecoveryLog recoveryLog)
Sets the Recovery Log Manager.

Parameters:
recoveryLog - The log recovery to set

setRequestCache

public void setRequestCache(AbstractRequestCache cache)
Set the Request Cache to use in this Request Controller.

Parameters:
cache - a Request Cache implementation

getScheduler

public AbstractScheduler getScheduler()
Get the Request Scheduler (if any) used in this Request Controller.

Returns:
an AbstractScheduler value or null if no Request Scheduler has been defined

setScheduler

public void setScheduler(AbstractScheduler scheduler)
Set the Request Scheduler to use in this Request Controller.

Parameters:
scheduler - a Request Scheduler implementation

setBackgroundParsing

public void setBackgroundParsing(boolean backgroundParsing)
Sets the background parsing. If true the request are parsed in background by a separate thread that is created for this purpose.

Parameters:
backgroundParsing - The backgroundParsing to set

setCaseSensitiveParsing

public void setCaseSensitiveParsing(boolean isCaseSensitiveParsing)
Sets the parsing case sensitivity. If true the request are parsed in a case sensitive way (table/column name must match exactly the case of the names fetched from the database or enforced by a static schema).

Parameters:
isCaseSensitiveParsing - true if parsing is case sensitive

getRequiredParsingGranularity

public int getRequiredParsingGranularity()
Returns:
the parsing granularity required by the current configuration

getXmlInformation

public java.lang.String getXmlInformation()
Get xml information about this Request Controller

Returns:
String in xml formatted text

getInformation

public java.lang.String getInformation()
Get information about this Request Controller

Returns:
String containing information


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