org.objectweb.cjdbc.controller.scheduler
Class AbstractScheduler

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.scheduler.AbstractScheduler
Direct Known Subclasses:
RAIDb0PessimisticTransactionLevelScheduler, RAIDb0QueryLevelScheduler, RAIDb1OptimisticQueryLevelScheduler, RAIDb1OptimisticTransactionLevelScheduler, RAIDb1PessimisticTransactionLevelScheduler, RAIDb1QueryLevelScheduler, RAIDb2PessimisticTransactionLevelScheduler, RAIDb2QueryLevelScheduler, SingleDBPessimisticTransactionLevelScheduler, SingleDBQueryLevelScheduler

public abstract class AbstractScheduler
extends java.lang.Object

The Request Scheduler should schedule the request according to a given policy.

The requests comes from the Request Controller and are sent later to the next ccontroller omponents (cache and load balancer).

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
private  java.lang.Object endOfCurrentTransactions
           
private  java.lang.Object endOfCurrentWrites
           
protected static Trace logger
           
protected  boolean needSQLMacroHandling
           
protected  int parsingGranularity
           
private  int pendingTransactions
           
private  int pendingWrites
           
protected  int raidbLevel
           
private  boolean suspendedTransactions
           
private  boolean suspendedWrites
           
private  int tid
           
private  java.lang.Object transactionSync
           
private  java.lang.Object writesSync
           
 
Constructor Summary
AbstractScheduler(int raidbLevel, int parsingGranularity, boolean needSQLMacroHandling)
          Default scheduler to assign scheduler RAIDb level, needed granularity and SQL macro handling (on the fly instanciation of NOW(), RAND(), ...).
 
Method Summary
 int begin(TransactionMarkerMetaData tm)
          Begin a new transaction and return the corresponding transaction identifier.
 void beginCompleted(int transactionId)
          Notify the completion of a begin command.
 void commit(TransactionMarkerMetaData tm)
          Commit a transaction.
 void commitCompleted(int transactionId)
          Notify the completion of a commit command.
protected abstract  void commitTransaction(int transactionId)
          Commit a transaction given its id.
abstract  java.lang.String getInformation()
          Get information about the Request Scheduler
 int getParsingGranularity()
          Get the needed query parsing granularity.
 int getPendingWrites()
          Returns the number of pending writes.
 int getRAIDbLevel()
          Returns the RAIDbLevel.
abstract  java.lang.String getXmlInformation()
          Get information about the Request Scheduler in xml format
protected  void handleSQLMacros(AbstractRequest request)
          Replace all SQL macros with an instanciated value: - NOW() is replaced with a current timestamp
protected  boolean hasSQLMacros(AbstractRequest request)
          Returns true if the query contains SQL macros.
 void mergeDatabaseSchema(DatabaseSchema dbs)
          Merge the given DatabaseSchema with the current one.
abstract  void notifyWriteCompleted(AbstractWriteRequest request)
          Notify the completion of a write statement.
abstract  void readCompleted(SelectRequest request)
          Notify the completion of a read statement.
 void resumeNewTransactions()
          Resume new transactions that were suspended by suspendNewTransactionsForCheckpoint().
 void resumeWrites()
          Resume the execution of write queries that were suspended by suspendWrites().
 void rollback(TransactionMarkerMetaData tm)
          Rollback a transaction.
 void rollbackCompleted(int transactionId)
          Notify the completion of a rollback command.
protected abstract  void rollbackTransaction(int transactionId)
          Rollback a transaction given its id.
abstract  void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request)
          Schedule a write request (implementation specific).
abstract  void scheduleReadRequest(SelectRequest request)
          Schedule a read request (implementation specific).
 void scheduleReadRequest(SelectRequest request, boolean queryCacheEnabled)
          Schedules a read request.
 void scheduleWriteRequest(AbstractWriteRequest request)
          Schedule a write request.
 void setDatabaseSchema(DatabaseSchema dbs)
          Sets the DatabaseSchema of the current virtual database.
 void setParsingGranularity(int parsingGranularity)
          Set the needed query parsing granularity.
 void setRAIDbLevel(int raidbLevel)
          Sets the RAIDb level.
 void suspendNewTransactionsForCheckpoint()
          Suspend all calls to begin() until all current transactions are finished in order to store a checkpoint.
 void suspendWrites()
          Suspend all write queries.
 void writeCompleted(AbstractWriteRequest request)
          Notify the completion of a write statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

raidbLevel

protected int raidbLevel

parsingGranularity

protected int parsingGranularity

needSQLMacroHandling

protected boolean needSQLMacroHandling

tid

private int tid

suspendedTransactions

private boolean suspendedTransactions

pendingTransactions

private int pendingTransactions

transactionSync

private java.lang.Object transactionSync

endOfCurrentTransactions

private java.lang.Object endOfCurrentTransactions

suspendedWrites

private boolean suspendedWrites

pendingWrites

private int pendingWrites

writesSync

private java.lang.Object writesSync

endOfCurrentWrites

private java.lang.Object endOfCurrentWrites

logger

protected static Trace logger
Constructor Detail

AbstractScheduler

public AbstractScheduler(int raidbLevel,
                         int parsingGranularity,
                         boolean needSQLMacroHandling)
Default scheduler to assign scheduler RAIDb level, needed granularity and SQL macro handling (on the fly instanciation of NOW(), RAND(), ...).

Parameters:
raidbLevel - RAIDb level of this scheduler
parsingGranularity - Parsing granularity needed by the scheduler
needSQLMacroHandling - True if SQL macro processing is needed.
Method Detail

getParsingGranularity

public final int getParsingGranularity()
Get the needed query parsing granularity.

Returns:
needed query parsing granularity

setParsingGranularity

public final void setParsingGranularity(int parsingGranularity)
Set the needed query parsing granularity.

Parameters:
parsingGranularity - Parsing granularity needed by the scheduler

getPendingWrites

public final int getPendingWrites()
Returns the number of pending writes.

Returns:
int

getRAIDbLevel

public final int getRAIDbLevel()
Returns the RAIDbLevel.

Returns:
int

setRAIDbLevel

public final void setRAIDbLevel(int raidbLevel)
Sets the RAIDb level.

Parameters:
raidbLevel - The RAIDbLevel to set

setDatabaseSchema

public void setDatabaseSchema(DatabaseSchema dbs)
Sets the DatabaseSchema of the current virtual database. This is only needed by some schedulers that will have to define their own scheduler schema

Parameters:
dbs - a DatabaseSchema value
See Also:
SchedulerDatabaseSchema

mergeDatabaseSchema

public void mergeDatabaseSchema(DatabaseSchema dbs)
Merge the given DatabaseSchema with the current one.

Parameters:
dbs - a DatabaseSchema value
See Also:
SchedulerDatabaseSchema

scheduleReadRequest

public void scheduleReadRequest(SelectRequest request,
                                boolean queryCacheEnabled)
                         throws java.sql.SQLException
Schedules a read request. SQL macros are replaced in the request if the scheduler has needSQLMacroHandling set to true then the implementation specific handleSQLMacros(AbstractRequest) function is called.

Parameters:
request - Select request to schedule
queryCacheEnabled - true if a query cache is active
Throws:
java.sql.SQLException - if a timeout occurs
See Also:
handleSQLMacros(AbstractRequest)

scheduleReadRequest

public abstract void scheduleReadRequest(SelectRequest request)
                                  throws java.sql.SQLException
Schedule a read request (implementation specific). This method blocks until the read can be executed.

Parameters:
request - Select request to schedule (SQL macros are already handled if needed)
Throws:
java.sql.SQLException - if a timeout occurs

readCompleted

public abstract void readCompleted(SelectRequest request)
Notify the completion of a read statement.

Parameters:
request - the completed request

scheduleWriteRequest

public final void scheduleWriteRequest(AbstractWriteRequest request)
                                throws java.sql.SQLException,
                                       RollbackException
Schedule a write request. This method blocks if the writes are suspended. Then the number of pending writes is updated and the implementation specific scheduleNonSuspendedWriteRequest function is called. SQL macros are replaced in the request if the scheduler has needSQLMacroHandling set to true.

Parameters:
request - Write request to schedule
Throws:
java.sql.SQLException - if a timeout occurs
RollbackException - if an error occurs
See Also:
scheduleNonSuspendedWriteRequest(AbstractWriteRequest)

scheduleNonSuspendedWriteRequest

public abstract void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request)
                                               throws java.sql.SQLException,
                                                      RollbackException
Schedule a write request (implementation specific). This method blocks until the request can be executed.

Parameters:
request - Write request to schedule (SQL macros are already handled if needed)
Throws:
java.sql.SQLException - if a timeout occurs
RollbackException - if the transaction must be rollbacked

writeCompleted

public final void writeCompleted(AbstractWriteRequest request)
Notify the completion of a write statement.

This method updates the number of pending writes and calls the implementation specific notifyWriteCompleted function.

Finally, the suspendWrites() function is notified if needed.

Parameters:
request - the completed request
See Also:
notifyWriteCompleted(AbstractWriteRequest), suspendWrites()

notifyWriteCompleted

public abstract void notifyWriteCompleted(AbstractWriteRequest request)
Notify the completion of a write statement. This method does not need to be synchronized, it is enforced by the caller.

Parameters:
request - the completed request
See Also:
writeCompleted(AbstractWriteRequest)

hasSQLMacros

protected boolean hasSQLMacros(AbstractRequest request)
Returns true if the query contains SQL macros. Currently supported macros are NOW() and RAND().

Parameters:
request - the request to check
Returns:
true if the query contains SQL macros.

handleSQLMacros

protected void handleSQLMacros(AbstractRequest request)
Replace all SQL macros with an instanciated value: - NOW() is replaced with a current timestamp. - RAND() is replaced with a random value

Parameters:
request - the request to handle macros

begin

public final int begin(TransactionMarkerMetaData tm)
                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:
tm - The transaction marker metadata
Returns:
the transaction identifier
Throws:
java.sql.SQLException - if an error occurs

beginCompleted

public final void beginCompleted(int transactionId)
Notify the completion of a begin command.

Parameters:
transactionId - of the completed begin

commit

public final void commit(TransactionMarkerMetaData tm)
                  throws java.sql.SQLException
Commit a transaction.

Calls the implementation specific commitTransaction()

Parameters:
tm - The transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs
See Also:
commitTransaction(int)

commitTransaction

protected abstract void commitTransaction(int transactionId)
Commit a transaction given its id.

Parameters:
transactionId - the transaction id
Throws:
RemoteException - if an error occurs

commitCompleted

public final void commitCompleted(int transactionId)
Notify the completion of a commit command.

Parameters:
transactionId - of the completed commit

rollback

public final void rollback(TransactionMarkerMetaData tm)
                    throws java.sql.SQLException
Rollback a transaction.

Calls the implementation specific rollbackTransaction()

Parameters:
tm - The transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs
See Also:
rollbackTransaction(int)

rollbackTransaction

protected abstract void rollbackTransaction(int transactionId)
Rollback a transaction given its id.

Parameters:
transactionId - the transaction id
Throws:
RemoteException - if an error occurs

rollbackCompleted

public final void rollbackCompleted(int transactionId)
Notify the completion of a rollback command.

Parameters:
transactionId - of the rollback commit

suspendNewTransactionsForCheckpoint

public final void suspendNewTransactionsForCheckpoint()
                                               throws java.sql.SQLException
Suspend all calls to begin() until all current transactions are finished in order to store a checkpoint. This method returns when all pending transactions have finished.

New transactions remain suspended until resumeNewTransactions() is called.

Throws:
java.sql.SQLException
See Also:
resumeNewTransactions()

resumeNewTransactions

public final void resumeNewTransactions()
Resume new transactions that were suspended by suspendNewTransactionsForCheckpoint().

See Also:
suspendNewTransactionsForCheckpoint()

suspendWrites

public void suspendWrites()
                   throws java.sql.SQLException
Suspend all write queries. This method blocks until all pending writes are completed.

Writes execution is resumed by calling resumeWrites()

Throws:
java.sql.SQLException
See Also:
resumeWrites()

resumeWrites

public void resumeWrites()
Resume the execution of write queries that were suspended by suspendWrites().

See Also:
suspendWrites()

getInformation

public abstract java.lang.String getInformation()
Get information about the Request Scheduler

Returns:
String containing information

getXmlInformation

public abstract java.lang.String getXmlInformation()
Get information about the Request Scheduler in xml format

Returns:
String containing information in xml


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