org.objectweb.cjdbc.controller.loadbalancer.singledb
Class SingleDB

java.lang.Object
  extended byjavax.management.StandardMBean
      extended byorg.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
          extended byorg.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
              extended byorg.objectweb.cjdbc.controller.loadbalancer.singledb.SingleDB
All Implemented Interfaces:
AbstractLoadBalancerMBean, javax.management.DynamicMBean, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, XmlComponent

public class SingleDB
extends AbstractLoadBalancer

Single Database request load balancer.

The requests coming from the request controller are directly forwarded to the single backend. This load balancer does not support multiple backends.

Version:
1.0
Author:
Emmanuel Cecchet , Vadim Kassin , Jaco Swart , Jean-Bernard van Zuylen

Nested Class Summary
 
Nested classes inherited from class javax.management.StandardMBean
 
Field Summary
private  DatabaseBackend backend
           
private static Trace logger
           
 
Fields inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
macroHandler, parsingGranularity, raidbLevel, totalOrderQueue, vdb
 
Fields inherited from class org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
 
Fields inherited from class javax.management.StandardMBean
 
Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION
 
Constructor Summary
SingleDB(VirtualDatabase vdb)
          Creates a new SingleDB instance.
 
Method Summary
 void begin(TransactionMarkerMetaData tm)
          Begins a new transaction.
 void commit(TransactionMarkerMetaData tm)
          Commits a transaction.
 void disableBackend(DatabaseBackend db)
          Disables a backend that was previously enabled.
 void enableBackend(DatabaseBackend db, boolean writeEnabled)
          Enables a backend that was previously disabled.
 ControllerResultSet execReadOnlyReadStoredProcedure(StoredProcedure proc, MetadataCache metadataCache)
          Call a read-only stored procedure that returns a ResultSet.
 ControllerResultSet execReadRequest(SelectRequest request, MetadataCache metadataCache)
          Performs a read request.
 ControllerResultSet execReadStoredProcedure(StoredProcedure proc, MetadataCache metadataCache)
          Call a stored procedure that returns a ResultSet.
 int execWriteRequest(AbstractWriteRequest request)
          Performs a write request on the backend.
 ControllerResultSet execWriteRequestWithKeys(AbstractWriteRequest request, MetadataCache metadataCache)
          Perform a write request and return a ResultSet containing the auto generated keys.
 int execWriteStoredProcedure(StoredProcedure proc)
          Call a stored procedure that performs an update.
 java.lang.String getInformation()
          Gets information about the request load balancer
 int getNumberOfEnabledBackends()
          Get the number of currently enabled backends. 0 means that no backend is available.
 java.lang.String getXmlImpl()
          Get information about the Request Load Balancer in xml
 void releaseSavepoint(TransactionMarkerMetaData tm, java.lang.String name)
          Release a savepoint from a transaction
 void rollback(TransactionMarkerMetaData tm)
          Rollbacks a transaction.
 void rollback(TransactionMarkerMetaData tm, java.lang.String savepointName)
          Rollback a transaction to a savepoint
 void setSavepoint(TransactionMarkerMetaData tm, java.lang.String name)
          Set a savepoint to a transaction.
 void setWeight(java.lang.String name, int w)
          Associate a weight to a backend identified by its logical name.
 
Methods inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
executeReadStoredProcedureOnBackend, executeSelectRequestOnBackend, executeUpdateRequestOnBackend, executeUpdateRequestOnBackendWithKeys, executeWriteStoredProcedureOnBackend, getAssociatedString, getConnectionAndBeginTransaction, getParsingGranularity, getRAIDbLevel, getXml, handleMacros, removeHeadFromAndNotifyTotalOrderQueue, setMacroHandler, setParsingGranularity, setRAIDbLevel, waitForTotalOrder
 
Methods inherited from class org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
addNotificationListener, getDescription, getDescription, getDescription, getDescription, getDescription, getDescription, getNotificationInfo, getParameterName, getParameterName, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class javax.management.StandardMBean
cacheMBeanInfo, getAttribute, getAttributes, getCachedMBeanInfo, getClassName, getConstructors, getDescription, getImpact, getImplementation, getImplementationClass, getMBeanInfo, getMBeanInterface, invoke, setAttribute, setAttributes, setImplementation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

backend

private DatabaseBackend backend

logger

private static Trace logger
Constructor Detail

SingleDB

public SingleDB(VirtualDatabase vdb)
         throws java.lang.Exception
Creates a new SingleDB instance.

Parameters:
vdb - the VirtualDatabase this load balancer belongs to
Throws:
java.lang.Exception - if there is not exactly one backend attached to the VirtualDatabase
Method Detail

execReadRequest

public ControllerResultSet execReadRequest(SelectRequest request,
                                           MetadataCache metadataCache)
                                    throws java.sql.SQLException
Performs 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
metadataCache - MetadataCache (null if none)
Returns:
the corresponding java.sql.ResultSet
Throws:
java.sql.SQLException - if an error occurs

execWriteRequest

public int execWriteRequest(AbstractWriteRequest request)
                     throws java.sql.SQLException
Performs a write request on the backend.

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 ControllerResultSet execWriteRequestWithKeys(AbstractWriteRequest request,
                                                    MetadataCache metadataCache)
                                             throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Perform a write request and return a ResultSet containing the auto generated keys.

Specified by:
execWriteRequestWithKeys in class AbstractLoadBalancer
Parameters:
request - an AbstractWriteRequest
metadataCache - MetadataCache (null if none)
Returns:
auto generated keys
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execWriteRequestWithKeys(AbstractWriteRequest, MetadataCache)

execReadOnlyReadStoredProcedure

public ControllerResultSet execReadOnlyReadStoredProcedure(StoredProcedure proc,
                                                           MetadataCache metadataCache)
                                                    throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Call a read-only stored procedure that returns a ResultSet. The stored procedure will be executed by one node only.

Specified by:
execReadOnlyReadStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
metadataCache - MetadataCache (null if none)
Returns:
a ControllerResultSet value
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execReadOnlyReadStoredProcedure(StoredProcedure, MetadataCache)

execReadStoredProcedure

public ControllerResultSet execReadStoredProcedure(StoredProcedure proc,
                                                   MetadataCache metadataCache)
                                            throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Call a stored procedure that returns a ResultSet. This stored procedure can possibly perform writes and will therefore be executed by all nodes.

Specified by:
execReadStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
metadataCache - MetadataCache (null if none)
Returns:
a ControllerResultSet value
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execReadStoredProcedure(StoredProcedure, MetadataCache)

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.common.sql.StoredProcedure)

begin

public 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

rollback

public void rollback(TransactionMarkerMetaData tm,
                     java.lang.String savepointName)
              throws java.sql.SQLException
Rollback a transaction to a savepoint

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

releaseSavepoint

public void releaseSavepoint(TransactionMarkerMetaData tm,
                             java.lang.String name)
                      throws java.sql.SQLException
Release a savepoint from a transaction

Specified by:
releaseSavepoint in class AbstractLoadBalancer
Parameters:
tm - The transaction marker metadata
name - The name of the savepoint ro release
Throws:
java.sql.SQLException - if an error occurs

setSavepoint

public void setSavepoint(TransactionMarkerMetaData tm,
                         java.lang.String name)
                  throws AllBackendsFailedException,
                         java.sql.SQLException
Set a savepoint to a transaction.

Specified by:
setSavepoint in class AbstractLoadBalancer
Parameters:
tm - The transaction marker metadata
name - The name of the new savepoint
Throws:
AllBackendsFailedException - if no backend succeeded in setting the savepoint.
java.sql.SQLException - if an error occurs

enableBackend

public void enableBackend(DatabaseBackend db,
                          boolean writeEnabled)
                   throws java.sql.SQLException
Enables a backend that was previously disabled. Asks the corresponding connection manager to initialize the connections if needed.

Specified by:
enableBackend in class AbstractLoadBalancer
Parameters:
db - the database backend to enable
writeEnabled - True if the backend must be enabled for writes
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. Asks the corresponding connection manager to finalize the connections if needed.

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

setWeight

public void setWeight(java.lang.String name,
                      int w)
               throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Associate a weight to a backend identified by its logical name.

Specified by:
setWeight in interface AbstractLoadBalancerMBean
Overrides:
setWeight in class AbstractLoadBalancer
Parameters:
name - the backend name
w - the weight
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.setWeight(String, int)

getNumberOfEnabledBackends

public int getNumberOfEnabledBackends()
Description copied from class: AbstractLoadBalancer
Get the number of currently enabled backends. 0 means that no backend is available.

Specified by:
getNumberOfEnabledBackends in class AbstractLoadBalancer
Returns:
number of currently enabled backends
See Also:
AbstractLoadBalancer.getNumberOfEnabledBackends()

getInformation

public java.lang.String getInformation()
Gets information about the request load balancer

Specified by:
getInformation in interface AbstractLoadBalancerMBean
Specified by:
getInformation in class AbstractLoadBalancer
Returns:
String containing information

getXmlImpl

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

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


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