org.objectweb.cjdbc.controller.loadbalancer.raidb1
Class RAIDb1

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
      extended byorg.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1
Direct Known Subclasses:
RAIDb1_LPRF, RAIDb1_RR, RAIDb1_WRR, RAIDb1ec

public abstract class RAIDb1
extends AbstractLoadBalancer

RAIDb-1 load balancer.

This class is an abstract call because the read requests coming from the request controller are NOT treated here but in the subclasses. Transaction management and write requests are broadcasted to all backends.

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
protected  java.util.ArrayList backendBlockingThreads
           
protected  ReadPrioritaryFIFOWriteLock backendBlockingThreadsRWLock
           
protected  java.util.ArrayList backendNonBlockingThreads
           
protected  ReadPrioritaryFIFOWriteLock backendNonBlockingThreadsRWLock
           
private  int execWriteRequestResult
           
private  java.sql.ResultSet execWriteRequestWithKeysResult
           
protected static Trace logger
           
private  WaitForCompletionPolicy waitForCompletionPolicy
           
 
Fields inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
parsingGranularity, raidbLevel, vdb
 
Constructor Summary
RAIDb1(VirtualDatabase vdb, WaitForCompletionPolicy waitForCompletionPolicy)
          Creates a new RAIDb-1 Round Robin request load balancer.
 
Method Summary
 void begin(TransactionMarkerMetaData tm)
          Begins a new transaction.
private  AbstractTask callStoredProcedure(StoredProcedure proc, boolean isRead)
          Post the stored procedure call in the threads task list.
 void commit(TransactionMarkerMetaData tm)
          Commits a transaction.
 void disableBackend(DatabaseBackend db)
          Disables a backend that was previously enabled.
 void enableBackend(DatabaseBackend db)
          Enables a Backend that was previously disabled.
abstract  java.sql.ResultSet execReadRequest(SelectRequest request)
          Perform a read request.
 java.sql.ResultSet execReadStoredProcedure(StoredProcedure proc)
          Call a stored procedure that returns a ResultSet.
protected  java.sql.ResultSet executeRequest(SelectRequest request, DatabaseBackend backend)
          Execute a read request on the selected backend.
 int execWriteRequest(AbstractWriteRequest request)
          Performs a write request.
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.
private  int getNbToWait(int nbOfThreads)
          Returns the number of nodes to wait for according to the defined waitForCompletion policy.
protected abstract  java.lang.String getRaidb1Xml()
          Surrounding raidb1 tags can be treated by getXmlInformation above, but more detailed content have to be returned by the method getRaidb1Xmlbelow.
 java.lang.String getXmlInformation()
          Get information about the Request Load Balancer in xml
 java.lang.String getXmlWaitPolicy()
          get xml formatted wait policy according to c-jdbc.dtd
 void rollback(TransactionMarkerMetaData tm)
          Rollbacks a transaction.
protected  void waitForAllWritesToComplete(DatabaseBackend backend)
          Waits for all writes in the blocking thread queue of the given backend to complete.
protected  void waitForAllWritesToComplete(DatabaseBackend backend, int transactionId)
          Waits for all writes of the given transaction in the blocking thread queue of the given backend to complete before being able to complete the transaction.
protected  void waitForAllWritesToComplete(int transactionId)
          Waits for all writes of the given transaction in the blocking thread queue to complete before being able to complete the transaction.
 
Methods inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
getInformation, getParsingGranularity, getRAIDbLevel, setParsingGranularity, setRAIDbLevel, setWeight
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

backendBlockingThreads

protected java.util.ArrayList backendBlockingThreads

backendNonBlockingThreads

protected java.util.ArrayList backendNonBlockingThreads

backendBlockingThreadsRWLock

protected ReadPrioritaryFIFOWriteLock backendBlockingThreadsRWLock

backendNonBlockingThreadsRWLock

protected ReadPrioritaryFIFOWriteLock backendNonBlockingThreadsRWLock

waitForCompletionPolicy

private WaitForCompletionPolicy waitForCompletionPolicy

logger

protected static Trace logger

execWriteRequestResult

private int execWriteRequestResult

execWriteRequestWithKeysResult

private java.sql.ResultSet execWriteRequestWithKeysResult
Constructor Detail

RAIDb1

public RAIDb1(VirtualDatabase vdb,
              WaitForCompletionPolicy waitForCompletionPolicy)
       throws java.sql.SQLException
Creates a new RAIDb-1 Round Robin request load balancer. A new backend worker thread is created for each backend.

Parameters:
vdb - the virtual database this load balancer belongs to.
waitForCompletionPolicy - How many backends must complete before returning the result?
Throws:
java.sql.SQLException - if an error occurs
Method Detail

getNbToWait

private final int getNbToWait(int nbOfThreads)
Returns the number of nodes to wait for according to the defined waitForCompletion policy.

Parameters:
nbOfThreads - total number of threads
Returns:
int number of threads to wait for

execReadRequest

public abstract java.sql.ResultSet execReadRequest(SelectRequest request)
                                            throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Perform a read request. It is up to the implementation to choose to which backend node(s) this request should be sent.

Specified by:
execReadRequest in class AbstractLoadBalancer
Parameters:
request - an SelectRequest
Returns:
the corresponding java.sql.ResultSet
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execReadRequest(SelectRequest)

executeRequest

protected java.sql.ResultSet executeRequest(SelectRequest request,
                                            DatabaseBackend backend)
                                     throws java.sql.SQLException
Execute a read request on the selected backend.

Parameters:
request - the request to execute
backend - the backend that will execute the request
Returns:
the ResultSet
Throws:
java.sql.SQLException - if an error occurs

execWriteRequest

public int execWriteRequest(AbstractWriteRequest request)
                     throws java.sql.SQLException
Performs a write request. This request is broadcasted to all nodes.

Specified by:
execWriteRequest in class AbstractLoadBalancer
Parameters:
request - an AbstractWriteRequest
Returns:
number of rows affected by the request
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.

Specified by:
execWriteRequestWithKeys in class AbstractLoadBalancer
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
Description copied from class: AbstractLoadBalancer
Call a stored procedure that returns a ResultSet.

Specified by:
execReadStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
Returns:
a java.sql.ResultSet value
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execReadStoredProcedure(org.objectweb.cjdbc.sql.StoredProcedure)

execWriteStoredProcedure

public int execWriteStoredProcedure(StoredProcedure proc)
                             throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Call a stored procedure that performs an update.

Specified by:
execWriteStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
Returns:
number of rows affected
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execWriteStoredProcedure(org.objectweb.cjdbc.sql.StoredProcedure)

callStoredProcedure

private AbstractTask callStoredProcedure(StoredProcedure proc,
                                         boolean isRead)
                                  throws java.sql.SQLException
Post the stored procedure call in the threads task list.

Parameters:
proc - the stored procedure to call
isRead - true if the call returns a ResultSet
Returns:
the task that has been executed (caller can get the result by calling getResult())
Throws:
java.sql.SQLException - if an error occurs

begin

public final void begin(TransactionMarkerMetaData tm)
                 throws java.sql.SQLException
Begins a new transaction.

Specified by:
begin in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

commit

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

Specified by:
commit in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

rollback

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

Specified by:
rollback in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

waitForAllWritesToComplete

protected void waitForAllWritesToComplete(int transactionId)
                                   throws java.sql.SQLException
Waits for all writes of the given transaction in the blocking thread queue to complete before being able to complete the transaction.

Throws:
java.sql.SQLException

waitForAllWritesToComplete

protected void waitForAllWritesToComplete(DatabaseBackend backend,
                                          int transactionId)
                                   throws java.sql.SQLException
Waits for all writes of the given transaction in the blocking thread queue of the given backend to complete before being able to complete the transaction.

Throws:
java.sql.SQLException
See Also:
executeRequest(SelectRequest, DatabaseBackend)

waitForAllWritesToComplete

protected void waitForAllWritesToComplete(DatabaseBackend backend)
                                   throws java.sql.SQLException
Waits for all writes in the blocking thread queue of the given backend to complete.

Throws:
java.sql.SQLException
See Also:
executeRequest(SelectRequest, DatabaseBackend)

enableBackend

public void enableBackend(DatabaseBackend db)
                   throws java.sql.SQLException
Enables a Backend that was previously disabled.

Ask the corresponding connection manager to initialize the connections if needed.

No sanity checks are performed by this function.

Specified by:
enableBackend in class AbstractLoadBalancer
Parameters:
db - the database backend to enable
Throws:
java.sql.SQLException - if an error occurs

disableBackend

public void disableBackend(DatabaseBackend db)
                    throws java.sql.SQLException
Disables a backend that was previously enabled.

Ask the corresponding connection manager to finalize the connections if needed.

No sanity checks are performed by this function.

Specified by:
disableBackend in class AbstractLoadBalancer
Parameters:
db - the database backend to disable
Throws:
java.sql.SQLException - if an error occurs

getXmlInformation

public java.lang.String getXmlInformation()
Description copied from class: AbstractLoadBalancer
Get information about the Request Load Balancer in xml

Specified by:
getXmlInformation in class AbstractLoadBalancer
Returns:
String containing information, xml formatted
See Also:
AbstractLoadBalancer.getXmlInformation()

getXmlWaitPolicy

public java.lang.String getXmlWaitPolicy()
get xml formatted wait policy according to c-jdbc.dtd

Returns:
xml formatted string of ""

getRaidb1Xml

protected abstract java.lang.String getRaidb1Xml()
Surrounding raidb1 tags can be treated by getXmlInformation above, but more detailed content have to be returned by the method getRaidb1Xmlbelow.

Returns:
content of Raidb1 xml


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