src/org/objectweb/cjdbc/controller/scheduler/raidb2/RAIDb2PessimisticTransactionLevelScheduler.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.controller.scheduler.raidb2; 00026 00027 import java.sql.SQLException; 00028 00029 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest; 00030 import org.objectweb.cjdbc.common.sql.ParsingGranularities; 00031 import org.objectweb.cjdbc.common.sql.SelectRequest; 00032 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 00033 import org.objectweb.cjdbc.controller.requestmanager.RAIDbLevels; 00034 import org.objectweb.cjdbc.controller.scheduler.AbstractScheduler; 00035 import org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock; 00036 00045 public class RAIDb2PessimisticTransactionLevelScheduler 00046 extends 00047 AbstractScheduler 00048 { 00049 00050 // 00051 // How the code is organized ? 00052 // 00053 // 1. Member variables 00054 // 2. Constructor 00055 // 3. Request handling 00056 // 4. Transaction management 00057 // 5. Debug/Monitoring 00058 // 00059 00060 private long requestId; 00061 private TransactionExclusiveLock lock = new TransactionExclusiveLock(); 00062 00063 // 00064 // Constructor 00065 // 00066 00070 public RAIDb2PessimisticTransactionLevelScheduler() 00071 { 00072 super(RAIDbLevels.RAIDb2, ParsingGranularities.NO_PARSING); 00073 } 00074 00075 // 00076 // Request Handling 00077 // 00078 00085 public final void scheduleReadRequest(SelectRequest request) 00086 throws SQLException 00087 { 00088 synchronized (this) 00089 { 00090 request.setId(requestId++); 00091 } 00092 } 00093 00097 public final void readCompletedNotify(SelectRequest request) 00098 { 00099 } 00100 00106 public void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request) 00107 throws SQLException 00108 { 00109 if (request.isCreate()) 00110 { 00111 synchronized (this) 00112 { 00113 request.setId(requestId++); 00114 } 00115 return; 00116 } 00117 00118 if (lock.acquire(request)) 00119 { 00120 synchronized (this) 00121 { 00122 request.setId(requestId++); 00123 } 00124 if (logger.isDebugEnabled()) 00125 logger.debug("Request " + request.getId() + " scheduled for write (" 00126 + getPendingWrites() + " pending writes)"); 00127 } 00128 else 00129 { 00130 if (logger.isWarnEnabled()) 00131 logger.warn("Request " + request.getId() + " timed out (" 00132 + request.getTimeout() + " s)"); 00133 throw new SQLException("Timeout (" + request.getTimeout() 00134 + ") for request: " + request.getId()); 00135 } 00136 } 00137 00141 public final synchronized void notifyWriteCompleted( 00142 AbstractWriteRequest request) 00143 { 00144 // Requests outside transaction delimiters must release the lock 00145 // as soon as they have executed 00146 if (request.isAutoCommit() && (!request.isCreate())) 00147 releaseLock(request.getTransactionId()); 00148 } 00149 00150 // 00151 // Transaction Management 00152 // 00153 00157 protected final void commitTransaction(long transactionId) 00158 { 00159 releaseLock(transactionId); 00160 } 00161 00165 protected final void rollbackTransaction(long transactionId) 00166 { 00167 releaseLock(transactionId); 00168 } 00169 00175 private void releaseLock(long transactionId) 00176 { 00177 // Are we the lock owner ? 00178 if (lock.isLocked()) 00179 { 00180 if (lock.getLocker() == transactionId) 00181 lock.release(); 00182 00183 // Note that the following warnings could be safely ignored if the 00184 // transaction commiting/rollbacking (releasing the lock) has not done any 00185 // conflicting write 00186 else if (logger.isDebugEnabled()) 00187 logger.debug("Transaction " + transactionId 00188 + " wants to release the lock held by transaction " 00189 + lock.getLocker()); 00190 } 00191 else if (logger.isDebugEnabled()) 00192 logger.warn("Transaction " + transactionId 00193 + " tries to release a lock that has not been acquired."); 00194 } 00195 00196 // 00197 // Debug/Monitoring 00198 // 00199 00203 public String getXmlImpl() 00204 { 00205 return "<" + DatabasesXmlTags.ELT_RAIDb2Scheduler + " " 00206 + DatabasesXmlTags.ATT_level + "=\"" 00207 + DatabasesXmlTags.VAL_pessimisticTransaction + "\"/>"; 00208 } 00209 00210 }

CJDBCversion1.0.4に対してTue Oct 12 15:16:03 2004に生成されました。 doxygen 1.3.8