src/org/objectweb/cjdbc/controller/loadbalancer/tasks/AbstractTask.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.controller.loadbalancer.tasks; 00026 00027 import java.sql.ResultSet; 00028 import java.sql.SQLException; 00029 import java.util.ArrayList; 00030 00031 import org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread; 00032 00041 public abstract class AbstractTask 00042 { 00043 // 00044 // How the code is organized ? 00045 // 1. Member variables 00046 // 2. Constructor(s) 00047 // 3. Task management 00048 // 4. Getter/Setter 00049 // 00050 00052 private int totalNb; 00053 00055 private int nbToComplete; 00056 00057 private int success = 0; 00058 private int failed = 0; 00059 private ArrayList exceptions = null; 00060 00061 // Internal tid flag used by BackendWorkerThread 00062 private boolean hasTid = false; 00063 00064 private ResultSet generatedKeysResultSet; 00065 00066 /* 00067 * Constructor 00068 */ 00069 00077 public AbstractTask(int nbToComplete, int totalNb) 00078 { 00079 this.nbToComplete = nbToComplete; 00080 this.totalNb = totalNb; 00081 success = 0; 00082 failed = 0; 00083 } 00084 00085 /* 00086 * Task management 00087 */ 00088 00095 public abstract void execute(BackendWorkerThread backendThread) 00096 throws SQLException; 00097 00101 public synchronized void notifySuccess() 00102 00103 { 00104 success++; 00105 00106 // Notify if needed 00107 if ((success == nbToComplete) || (success + failed == totalNb)) 00108 { 00109 if (failed > 0) 00110 notifyAll(); // Notify all failed threads too 00111 else 00112 notify(); 00113 } 00114 } 00115 00125 public synchronized void notifyCompletion() 00126 { 00127 totalNb--; 00128 // Notify if needed 00129 if (success + failed == totalNb) 00130 { 00131 notifyAll(); // Notify all failed threads 00132 } 00133 } 00134 00151 public synchronized boolean notifyFailure(BackendWorkerThread backendThread, 00152 long timeout, Exception e) throws SQLException 00153 { 00154 failed++; 00155 00156 // Log the exception 00157 if (exceptions == null) 00158 exceptions = new ArrayList(); 00159 exceptions.add(new SQLException("BackendThread " 00160 + backendThread.getBackend().getName() + " failed (" + e + ")")); 00161 00162 // Notify if needed 00163 if (success + failed == totalNb) 00164 { 00165 notifyAll(); // Notify all failed threads 00166 } 00167 else 00168 { 00169 try 00170 { // Wait to check if all other threads failed or not 00171 wait(timeout); 00172 } 00173 catch (InterruptedException ie) 00174 { 00175 throw new SQLException("Wait interrupted() in failed task of backend " 00176 + backendThread.getBackend().getName() + " (" + e + ")"); 00177 } 00178 } 00179 return success > 0; 00180 } 00181 00182 // 00183 // Getter/Setter 00184 // 00185 00191 public ArrayList getExceptions() 00192 { 00193 return exceptions; 00194 } 00195 00201 public int getFailed() 00202 { 00203 return failed; 00204 } 00205 00211 public int getNbToComplete() 00212 { 00213 return nbToComplete; 00214 } 00215 00221 public int getSuccess() 00222 { 00223 return success; 00224 } 00225 00232 public int getTotalNb() 00233 { 00234 return totalNb; 00235 } 00236 00243 public void setTotalNb(int totalNb) 00244 { 00245 this.totalNb = totalNb; 00246 } 00247 00255 public boolean hasTid() 00256 { 00257 return hasTid; 00258 } 00259 00267 public void setHasTid(boolean hasTid) 00268 { 00269 this.hasTid = hasTid; 00270 } 00271 00277 public ResultSet getGeneratedKeysResultSet() 00278 { 00279 return generatedKeysResultSet; 00280 } 00281 00287 public void setGeneratedKeysResultSet(ResultSet generatedKeysResultSet) 00288 { 00289 this.generatedKeysResultSet = generatedKeysResultSet; 00290 } 00291 }

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