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

org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask Class Reference

Inheritance diagram for org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask:

Inheritance graph
[legend]
Collaboration diagram for org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CommitTask (int nbToComplete, int totalNb, long timeout, String login, long transactionId)
void executeTask (BackendWorkerThread backendThread) throws SQLException
String toString ()

Detailed Description

Task to commit a transaction.

Author:
Emmanuel Cecchet

Julie Marguerite

Version:
1.0

Definition at line 41 of file CommitTask.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.CommitTask int  nbToComplete,
int  totalNb,
long  timeout,
String  login,
long  transactionId
 

Commits a transaction given a login and a transaction id.

Parameters:
nbToComplete number of threads that must succeed before returning
totalNb total number of threads
timeout request timeout in ms
login the login used by the connection
transactionId a unique transaction identifier

Definition at line 61 of file CommitTask.java.

00063   {
00064     super(nbToComplete, totalNb);
00065     this.login = login;
00066     this.transactionId = transactionId;
00067     this.timeout = timeout;
00068   }


Member Function Documentation

void org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.executeTask BackendWorkerThread  backendThread  )  throws SQLException [virtual]
 

Commits a transaction with the given backend thread.

Parameters:
backendThread the backend thread that will execute the task
Exceptions:
SQLException if an error occurs

Implements org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.

Definition at line 76 of file CommitTask.java.

References org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionManager(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getName(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getSuccess(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyFailure(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifySuccess(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.releaseConnection(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.retrieveConnection(), and org.objectweb.cjdbc.controller.backend.DatabaseBackend.stopTransaction().

00077   {
00078     DatabaseBackend db = backendThread.getBackend();
00079     Long lTid = new Long(transactionId);
00080 
00081     AbstractConnectionManager cm = db.getConnectionManager(login);
00082     if (cm == null)
00083     {
00084       SQLException se = new SQLException(
00085           "No Connection Manager for Virtual Login:" + login);
00086       try
00087       {
00088         notifyFailure(backendThread, 1, se);
00089       }
00090       catch (SQLException ignore)
00091       {
00092 
00093       }
00094       throw se;
00095     }
00096     Connection c = cm.retrieveConnection(transactionId);
00097 
00098     // Sanity check
00099     if (c == null)
00100     { // Bad connection
00101       db.stopTransaction(lTid);
00102       SQLException se = new SQLException(
00103           "Unable to retrieve connection for transaction " + transactionId);
00104 
00105       try
00106       { // All backends failed, just ignore
00107         if (!notifyFailure(backendThread, timeout, se))
00108           return;
00109       }
00110       catch (SQLException ignore)
00111       {
00112       }
00113       // Disable this backend (it is no more in sync) by killing the backend
00114       // thread
00115       backendThread.kill();
00116       String msg = "Failed to commit transaction " + transactionId
00117           + " on backend " + db.getName() + " but " + getSuccess()
00118           + " succeeded (" + se + ")";
00119       backendThread.getLogger().error(msg);
00120       throw new SQLException(msg);
00121     }
00122 
00123     // Execute Query
00124     try
00125     {
00126       c.commit();
00127       c.setAutoCommit(true);
00128     }
00129     catch (Exception e)
00130     {
00131       try
00132       {
00133         if (!notifyFailure(backendThread, timeout, new SQLException(e
00134             .getMessage())))
00135           return;
00136       }
00137       catch (SQLException ignore)
00138       {
00139       }
00140       // Disable this backend (it is no more in sync) by killing the backend
00141       // thread
00142       backendThread.kill();
00143       String msg = "Failed to commit transaction " + transactionId
00144           + " on backend " + db.getName() + " but " + getSuccess()
00145           + " succeeded (" + e + ")";
00146       backendThread.getLogger().error(msg);
00147       throw new SQLException(msg);
00148     }
00149     finally
00150     {
00151       cm.releaseConnection(transactionId);
00152       db.stopTransaction(lTid);
00153     }
00154     notifySuccess();
00155   }

String org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.toString  ) 
 

See also:
java.lang.Object#toString()

Definition at line 160 of file CommitTask.java.

00161   {
00162     return "CommitTask (" + transactionId + ")";
00163   }


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