Public Member Functions | |
RAIDb2ec (VirtualDatabase vdb, WaitForCompletionPolicy waitForCompletionPolicy, CreateTablePolicy createTablePolicy, 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 |
This class is an abstract call because the read requests coming from the request manager are NOT treated here but in the subclasses. This class deals with backend enable/disable for backendReadThreads creation/termination.
Definition at line 51 of file RAIDb2ec.java.
|
Creates a new RAIDb-1 Round Robin request load balancer. A new backend worker thread is created for each backend.
Definition at line 82 of file RAIDb2ec.java. 00087 { 00088 super(vdb, waitForCompletionPolicy, createTablePolicy); 00089 backendReadThreads = new ArrayList(); 00090 this.errorCheckingPolicy = errorCheckingPolicy; 00091 this.nbOfConcurrentReads = nbOfConcurrentReads; 00092 }
|
|
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.
Reimplemented from org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2. Definition at line 171 of file RAIDb2ec.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(). 00173 { 00174 int nbOfThreads = backendBlockingThreads.size(); 00175 00176 // Find the right blocking thread 00177 for (int i = 0; i < nbOfThreads; i++) 00178 { 00179 BackendWorkerThread thread = (BackendWorkerThread) backendBlockingThreads 00180 .get(i); 00181 if (thread.getBackend().equals(db)) 00182 { 00183 logger.info(Translate.get( 00184 "loadbalancer.backend.workerthread.blocking.remove", db.getName())); 00185 00186 // Remove it from the backendBlockingThread list 00187 try 00188 { 00189 backendBlockingThreadsRWLock.acquireWrite(); 00190 } 00191 catch (InterruptedException e) 00192 { 00193 String msg = Translate.get( 00194 "loadbalancer.backendlist.acquire.writelock.failed", e); 00195 logger.error(msg); 00196 throw new SQLException(msg); 00197 } 00198 backendBlockingThreads.remove(thread); 00199 backendBlockingThreadsRWLock.releaseWrite(); 00200 00201 synchronized (thread) 00202 { 00203 // Kill the thread 00204 thread.addPriorityTask(new KillThreadTask(1, 1)); 00205 thread.notify(); 00206 } 00207 break; 00208 } 00209 } 00210 00211 // Find the right non-blocking thread 00212 nbOfThreads = backendNonBlockingThreads.size(); 00213 for (int i = 0; i < nbOfThreads; i++) 00214 { 00215 BackendWorkerThread thread = (BackendWorkerThread) backendNonBlockingThreads 00216 .get(i); 00217 if (thread.getBackend().equals(db)) 00218 { 00219 logger.info(Translate.get( 00220 "loadbalancer.backend.workerthread.non.blocking.remove", db 00221 .getName())); 00222 00223 // Remove it from the backendNonBlockingThreads list 00224 try 00225 { 00226 backendNonBlockingThreadsRWLock.acquireWrite(); 00227 } 00228 catch (InterruptedException e) 00229 { 00230 String msg = Translate.get( 00231 "loadbalancer.backendlist.acquire.writelock.failed", e); 00232 logger.error(msg); 00233 throw new SQLException(msg); 00234 } 00235 backendNonBlockingThreads.remove(thread); 00236 backendNonBlockingThreadsRWLock.releaseWrite(); 00237 00238 synchronized (thread) 00239 { 00240 // Kill the thread 00241 thread.addPriorityTask(new KillThreadTask(1, 1)); 00242 thread.notify(); 00243 } 00244 break; 00245 } 00246 } 00247 00248 db.disable(); 00249 if (db.isInitialized()) 00250 db.finalizeConnections(); 00251 }
|
|
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.
Reimplemented from org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2. Definition at line 110 of file RAIDb2ec.java. References org.objectweb.cjdbc.common.util.ReadPrioritaryFIFOWriteLock.acquireWrite(), and org.objectweb.cjdbc.common.util.ReadPrioritaryFIFOWriteLock.releaseWrite(). 00112 { 00113 // Create 2 worker threads for writes 00114 BackendWorkerThread blockingThread = new BackendWorkerThread(db, this); 00115 BackendWorkerThread nonBlockingThread = new BackendWorkerThread(db, this); 00116 00117 // Add first to the blocking thread list 00118 try 00119 { 00120 backendBlockingThreadsRWLock.acquireWrite(); 00121 } 00122 catch (InterruptedException e) 00123 { 00124 String msg = Translate.get( 00125 "loadbalancer.backendlist.acquire.writelock.failed", e); 00126 logger.error(msg); 00127 throw new SQLException(msg); 00128 } 00129 backendBlockingThreads.add(blockingThread); 00130 backendBlockingThreadsRWLock.releaseWrite(); 00131 blockingThread.start(); 00132 logger.info(Translate.get("loadbalancer.backend.workerthread.blocking.add", 00133 db.getName())); 00134 00135 // Then add to the non-blocking thread list 00136 try 00137 { 00138 backendNonBlockingThreadsRWLock.acquireWrite(); 00139 } 00140 catch (InterruptedException e) 00141 { 00142 String msg = Translate.get( 00143 "loadbalancer.backendlist.acquire.writelock.failed", e); 00144 logger.error(msg); 00145 throw new SQLException(msg); 00146 } 00147 backendNonBlockingThreads.add(nonBlockingThread); 00148 backendNonBlockingThreadsRWLock.releaseWrite(); 00149 nonBlockingThread.start(); 00150 logger.info(Translate.get( 00151 "loadbalancer.backend.workerthread.non.blocking.add", db.getName())); 00152 00153 if (!db.isInitialized()) 00154 db.initializeConnections(); 00155 db.enableRead(); 00156 if (writeEnabled) 00157 db.enableWrite(); 00158 }
|
|
Reimplemented from org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2. Definition at line 256 of file RAIDb2ec.java. References org.objectweb.cjdbc.controller.loadbalancer.policies.WaitForCompletionPolicy.getXml(). 00257 { 00258 StringBuffer info = new StringBuffer(); 00259 info.append("<" + DatabasesXmlTags.ELT_RAIDb_2ec + " " 00260 + DatabasesXmlTags.ATT_nbOfConcurrentReads + "=\"" 00261 + this.nbOfConcurrentReads + "\">"); 00262 this.getRaidb2Xml(); 00263 if (waitForCompletionPolicy != null) 00264 info.append(waitForCompletionPolicy.getXml()); 00265 info.append("</" + DatabasesXmlTags.ELT_RAIDb_2ec + ">"); 00266 return info.toString(); 00267 }
|
|
Initial value: Trace
.getLogger("org.objectweb.cjdbc.controller.loadbalancer.RAIDb2ec")
Reimplemented from org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2. Definition at line 62 of file RAIDb2ec.java. |