Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec Class Reference

Inheritance diagram for org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec:

Inheritance graph
[legend]
Collaboration diagram for org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 RAIDb1ec (VirtualDatabase vdb, WaitForCompletionPolicy waitForCompletionPolicy, ErrorCheckingPolicy errorCheckingPolicy, int nbOfConcurrentReads) throws Exception
void enableBackend (DatabaseBackend db, boolean writeEnabled) throws SQLException
synchronized void disableBackend (DatabaseBackend db) throws SQLException
String getXmlImpl ()

Protected Attributes

ArrayList backendReadThreads
int nbOfConcurrentReads
ErrorCheckingPolicy errorCheckingPolicy

Static Protected Attributes

Trace logger

Detailed Description

RAIDb-1 load balancer.

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

Author:
Emmanuel Cecchet
Version:
1.0

Definition at line 50 of file RAIDb1ec.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec.RAIDb1ec VirtualDatabase  vdb,
WaitForCompletionPolicy  waitForCompletionPolicy,
ErrorCheckingPolicy  errorCheckingPolicy,
int  nbOfConcurrentReads
throws Exception
 

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?
errorCheckingPolicy policy to apply for error checking.
nbOfConcurrentReads number of concurrent reads allowed
Exceptions:
Exception if an error occurs

Definition at line 79 of file RAIDb1ec.java.

00083   {
00084     super(vdb, waitForCompletionPolicy);
00085     backendReadThreads = new ArrayList();
00086     this.errorCheckingPolicy = errorCheckingPolicy;
00087     this.nbOfConcurrentReads = nbOfConcurrentReads;
00088   }


Member Function Documentation

synchronized void org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec.disableBackend DatabaseBackend  db  )  throws SQLException [virtual]
 

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.

Parameters:
db the database backend to disable
Exceptions:
SQLException if an error occurs

Reimplemented from org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.

Definition at line 167 of file RAIDb1ec.java.

References org.objectweb.cjdbc.common.util.ReadPrioritaryFIFOWriteLock.acquireWrite(), org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.addPriorityTask(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.equals(), org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.getBackend(), and org.objectweb.cjdbc.common.util.ReadPrioritaryFIFOWriteLock.releaseWrite().

00169   {
00170     int nbOfThreads = backendBlockingThreads.size();
00171 
00172     // Find the right blocking thread
00173     for (int i = 0; i < nbOfThreads; i++)
00174     {
00175       BackendWorkerThread thread = (BackendWorkerThread) backendBlockingThreads
00176           .get(i);
00177       if (thread.getBackend().equals(db))
00178       {
00179         logger.info(Translate.get(
00180             "loadbalancer.backend.workerthread.blocking.remove", db.getName()));
00181 
00182         // Remove it from the backendBlockingThread list
00183         try
00184         {
00185           backendBlockingThreadsRWLock.acquireWrite();
00186         }
00187         catch (InterruptedException e)
00188         {
00189           String msg = Translate.get(
00190               "loadbalancer.backendlist.acquire.writelock.failed", e);
00191           logger.error(msg);
00192           throw new SQLException(msg);
00193         }
00194         backendBlockingThreads.remove(thread);
00195         backendBlockingThreadsRWLock.releaseWrite();
00196 
00197         synchronized (thread)
00198         {
00199           // Kill the thread
00200           thread.addPriorityTask(new KillThreadTask(1, 1));
00201           thread.notify();
00202         }
00203         break;
00204       }
00205     }
00206 
00207     // Find the right non-blocking thread
00208     nbOfThreads = backendNonBlockingThreads.size();
00209     for (int i = 0; i < nbOfThreads; i++)
00210     {
00211       BackendWorkerThread thread = (BackendWorkerThread) backendNonBlockingThreads
00212           .get(i);
00213       if (thread.getBackend().equals(db))
00214       {
00215         logger.info(Translate.get(
00216             "loadbalancer.backend.workerthread.non.blocking.remove", db
00217                 .getName()));
00218 
00219         // Remove it from the backendNonBlockingThreads list
00220         try
00221         {
00222           backendNonBlockingThreadsRWLock.acquireWrite();
00223         }
00224         catch (InterruptedException e)
00225         {
00226           String msg = Translate.get(
00227               "loadbalancer.backendlist.acquire.writelock.failed", e);
00228           logger.error(msg);
00229           throw new SQLException(msg);
00230         }
00231         backendNonBlockingThreads.remove(thread);
00232         backendNonBlockingThreadsRWLock.releaseWrite();
00233 
00234         synchronized (thread)
00235         {
00236           // Kill the thread
00237           thread.addPriorityTask(new KillThreadTask(1, 1));
00238           thread.notify();
00239         }
00240         break;
00241       }
00242     }
00243 
00244     db.disable();
00245     if (db.isInitialized())
00246       db.finalizeConnections();
00247   }

void org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec.enableBackend DatabaseBackend  db,
boolean  writeEnabled
throws SQLException [virtual]
 

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.

Parameters:
db the database backend to enable
writeEnabled True if the backend must be enabled for writes
Exceptions:
SQLException if an error occurs

Reimplemented from org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.

Definition at line 106 of file RAIDb1ec.java.

References org.objectweb.cjdbc.common.util.ReadPrioritaryFIFOWriteLock.acquireWrite(), and org.objectweb.cjdbc.common.util.ReadPrioritaryFIFOWriteLock.releaseWrite().

00108   {
00109     // Create 2 worker threads for writes
00110     BackendWorkerThread blockingThread = new BackendWorkerThread(db, this);
00111     BackendWorkerThread nonBlockingThread = new BackendWorkerThread(db, this);
00112 
00113     // Add first to the blocking thread list
00114     try
00115     {
00116       backendBlockingThreadsRWLock.acquireWrite();
00117     }
00118     catch (InterruptedException e)
00119     {
00120       String msg = Translate.get(
00121           "loadbalancer.backendlist.acquire.writelock.failed", e);
00122       logger.error(msg);
00123       throw new SQLException(msg);
00124     }
00125     backendBlockingThreads.add(blockingThread);
00126     backendBlockingThreadsRWLock.releaseWrite();
00127     blockingThread.start();
00128     logger.info(Translate.get("loadbalancer.backend.workerthread.blocking.add",
00129         db.getName()));
00130 
00131     // Then add to the non-blocking thread list
00132     try
00133     {
00134       backendNonBlockingThreadsRWLock.acquireWrite();
00135     }
00136     catch (InterruptedException e)
00137     {
00138       String msg = Translate.get(
00139           "loadbalancer.backendlist.acquire.writelock.failed", e);
00140       logger.error(msg);
00141       throw new SQLException(msg);
00142     }
00143     backendNonBlockingThreads.add(nonBlockingThread);
00144     backendNonBlockingThreadsRWLock.releaseWrite();
00145     nonBlockingThread.start();
00146     logger.info(Translate.get(
00147         "loadbalancer.backend.workerthread.non.blocking.add", db.getName()));
00148 
00149     if (!db.isInitialized())
00150       db.initializeConnections();
00151     db.enableRead();
00152     if (writeEnabled)
00153       db.enableWrite();
00154   }

String org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec.getXmlImpl  )  [virtual]
 

See also:
org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer.getXmlImpl

Reimplemented from org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.

Definition at line 252 of file RAIDb1ec.java.

References org.objectweb.cjdbc.controller.loadbalancer.policies.WaitForCompletionPolicy.getXml().

00253   {
00254     StringBuffer info = new StringBuffer();
00255     info.append("<" + DatabasesXmlTags.ELT_RAIDb_1ec + " "
00256         + DatabasesXmlTags.ATT_nbOfConcurrentReads + "=\""
00257         + this.nbOfConcurrentReads + "\">");
00258     this.getRaidb1Xml();
00259     if (waitForCompletionPolicy != null)
00260       info.append(waitForCompletionPolicy.getXml());
00261     info.append("</" + DatabasesXmlTags.ELT_RAIDb_1ec + ">");
00262     return info.toString();
00263   }


Member Data Documentation

Trace org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec.logger [static, protected]
 

Initial value:

 Trace
                                           .getLogger("org.objectweb.cjdbc.controller.loadbalancer.RAIDb1ec")

Reimplemented from org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.

Definition at line 61 of file RAIDb1ec.java.


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:04:05 2005 for C-JDBC by  doxygen 1.3.9.1