Public Member Functions | |
VirtualDatabaseShutdownThread (VirtualDatabase vdb, int level) | |
Protected Member Functions | |
void | closeVirtualDatabase () |
void | disableAllBackends () |
void | terminateVirtualDatabaseWorkerThreads () |
void | waitForClientsToDisconnect () |
void | waitForTransactionsAndWritesToComplete () |
Protected Attributes | |
VirtualDatabase | virtualDatabase |
Definition at line 44 of file VirtualDatabaseShutdownThread.java.
|
Prepare the thread for shutting down.
Definition at line 55 of file VirtualDatabaseShutdownThread.java. 00056 {
00057 super(level);
00058 this.virtualDatabase = vdb;
00059 }
|
|
Close the virtual database channel. Definition at line 64 of file VirtualDatabaseShutdownThread.java. References org.objectweb.cjdbc.common.log.Trace.info(), and org.objectweb.cjdbc.common.log.Trace.warn(). 00065 { 00066 if (virtualDatabase.isDistributed()) 00067 { 00068 logger.info("Shutting down group communication"); 00069 try 00070 { 00071 ((DistributedVirtualDatabase) virtualDatabase).quitChannel(); 00072 } 00073 catch (Exception e) 00074 { 00075 logger 00076 .warn( 00077 "An error occured while shutting down the group communication channel", 00078 e); 00079 } 00080 } 00081 }
|
|
Disable all database backends with a checkpoint named after the current time if a recovery log is available. Definition at line 87 of file VirtualDatabaseShutdownThread.java. References org.objectweb.cjdbc.common.log.Trace.error(). 00088 { 00089 if (virtualDatabase.getRequestManager().getRecoveryLog() != null) 00090 { 00091 try 00092 { // disable and checkpoint for recovery log 00093 virtualDatabase.storeBackendsInfo(); 00094 virtualDatabase.disableAllBackendsWithCheckpoint(new Date().toString()); 00095 } 00096 catch (Exception ve) 00097 { 00098 logger.error(Translate 00099 .get("controller.shutdown.backends.exception", ve)); 00100 } 00101 } 00102 else 00103 { // no recovery log, so just disable backends 00104 try 00105 { 00106 virtualDatabase.disableAllBackends(); 00107 } 00108 catch (Exception vde) 00109 { 00110 logger.error(Translate.get("controller.shutdown.backends.exception", 00111 vde)); 00112 } 00113 } 00114 }
|
|
Terminate the VirtualDatabaseWorkerThreads Definition at line 119 of file VirtualDatabaseShutdownThread.java. References org.objectweb.cjdbc.common.log.Trace.debug(), org.objectweb.cjdbc.common.log.Trace.info(), org.objectweb.cjdbc.common.log.Trace.isDebugEnabled(), and org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread.shutdown(). 00120 { 00121 ArrayList threads = virtualDatabase.getActiveThreads(); 00122 logger.info(Translate.get("controller.shutdown.active.threads", threads 00123 .size())); 00124 VirtualDatabaseWorkerThread wt; 00125 synchronized (threads) 00126 { 00127 for (int i = 0; i < threads.size(); i++) 00128 { 00129 if (logger.isDebugEnabled()) 00130 logger.debug(Translate.get("controller.shutdown.database.thread", 00131 new String[]{virtualDatabase.getVirtualDatabaseName(), 00132 String.valueOf(i)})); 00133 wt = ((VirtualDatabaseWorkerThread) threads.get(i)); 00134 wt.shutdown(); 00135 } 00136 } 00137 virtualDatabase.getActiveThreads().clear(); 00138 }
|
|
Wait for all VirtualDatabaseWorkerThreads to terminate when all clients have disconnected. Definition at line 144 of file VirtualDatabaseShutdownThread.java. 00145 { 00146 boolean wait = true; 00147 while (wait) 00148 { 00149 ArrayList threads = virtualDatabase.getActiveThreads(); 00150 synchronized (threads) 00151 { 00152 int nbThreads = threads.size(); 00153 logger.debug(Translate.get("controller.shutdown.active.threads", "" 00154 + nbThreads)); 00155 if (nbThreads == 0) 00156 { 00157 wait = false; 00158 } 00159 } 00160 if (wait) 00161 { 00162 synchronized (this) 00163 { 00164 try 00165 { 00166 wait(1000); 00167 } 00168 catch (InterruptedException e) 00169 { 00170 // Ignore 00171 } 00172 } 00173 } 00174 } 00175 }
|
|
Wait for currently open transactions and pending writes to complete (in this order: 1.transaction, 2.writes). Definition at line 181 of file VirtualDatabaseShutdownThread.java. 00182 { 00183 try 00184 { 00185 virtualDatabase.getRequestManager().getScheduler() 00186 .suspendNewTransactionsForCheckpoint(); 00187 } 00188 catch (SQLException e) 00189 { 00190 logger 00191 .error( 00192 "An error occured while waiting for current transactions to complete.", 00193 e); 00194 } 00195 try 00196 { 00197 virtualDatabase.getRequestManager().getScheduler().suspendWrites(); 00198 } 00199 catch (SQLException e) 00200 { 00201 logger.error( 00202 "An error occured while waiting for pending writes to complete.", e); 00203 } 00204 }
|