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

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

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

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 WriteRequestTask (int nbToComplete, int totalNb, AbstractWriteRequest request)
void executeTask (BackendWorkerThread backendThread) throws SQLException
int getResult ()
String toString ()

Detailed Description

Executes an AbstractWriteRequest statement.

Author:
Emmanuel Cecchet

Julie Marguerite

Jaco Swart

Version:
1.0

Definition at line 50 of file WriteRequestTask.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.WriteRequestTask int  nbToComplete,
int  totalNb,
AbstractWriteRequest  request
 

Creates a new WriteRequestTask.

Parameters:
nbToComplete number of threads that must succeed before returning
totalNb total number of threads
request an AbstractWriteRequest

Definition at line 62 of file WriteRequestTask.java.

00064   {
00065     super(nbToComplete, totalNb);
00066     this.request = request;
00067   }


Member Function Documentation

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

Executes a write request 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 75 of file WriteRequestTask.java.

References org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.addTable(), org.objectweb.cjdbc.common.log.Trace.debug(), org.objectweb.cjdbc.common.log.Trace.error(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.getConnection(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionForTransactionAndLazyBeginIfNeeded(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionManager(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getDatabaseSchema(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getName(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getSQLShortFormLength(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getSuccess(), org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.getTable(), org.objectweb.cjdbc.common.log.Trace.isDebugEnabled(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.isDisabling(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyCompletion(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyFailure(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifySuccess(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.releaseConnection(), and org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.removeTable().

00077   {
00078     DatabaseBackend backend = backendThread.getBackend();
00079 
00080     AbstractConnectionManager cm = backend.getConnectionManager(request
00081         .getLogin());
00082     if (cm == null)
00083     {
00084       SQLException se = new SQLException(
00085           "No Connection Manager for Virtual Login:" + request.getLogin());
00086       try
00087       {
00088         notifyFailure(backendThread, 1, se);
00089       }
00090       catch (SQLException ignore)
00091       {
00092       }
00093       throw se;
00094     }
00095 
00096     Trace logger = backendThread.getLogger();
00097     if (request.isAutoCommit())
00098     {
00099       if (backend.isDisabling())
00100       {
00101         // Backend is disabling, we do not execute queries except the one in the
00102         // transaction we already started. Just notify the completion for the
00103         // others.
00104         notifyCompletion();
00105         return;
00106       }
00107 
00108       // Use a connection just for this request
00109       Connection c = null;
00110       try
00111       {
00112         c = cm.getConnection();
00113       }
00114       catch (UnreachableBackendException e1)
00115       {
00116         SQLException se = new SQLException("Backend " + backend.getName()
00117             + " is no more reachable.");
00118         try
00119         {
00120           notifyFailure(backendThread, 1, se);
00121         }
00122         catch (SQLException ignore)
00123         {
00124         }
00125         // Disable this backend (it is no more in sync) by killing the backend
00126         // thread
00127         backendThread.kill();
00128         logger.error("Disabling backend " + backend.getName()
00129             + " because it is no more reachable.");
00130         throw se;
00131       }
00132 
00133       // Sanity check
00134       if (c == null)
00135       {
00136         SQLException se = new SQLException("No more connections");
00137         try
00138         { // All backends failed, just ignore
00139           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00140               se))
00141           {
00142             return;
00143           }
00144         }
00145         catch (SQLException ignore)
00146         {
00147         }
00148         // Disable this backend (it is no more in sync) by killing the backend
00149         // thread
00150         backendThread.kill();
00151         String msg = "Request '"
00152             + request.getSQLShortForm(backend.getSQLShortFormLength())
00153             + "' failed on backend " + backend.getName() + " but "
00154             + getSuccess() + " succeeded (" + se + ")";
00155         logger.error(msg);
00156         throw new SQLException(msg);
00157       }
00158 
00159       // Execute Query
00160       try
00161       {
00162         result = AbstractLoadBalancer.executeUpdateRequestOnBackend(request,
00163             backend, c);
00164 
00165         // Update schema
00166         if (request.isCreate())
00167         { // Add the table to the schema
00168           DatabaseSchema dbs = backend.getDatabaseSchema();
00169           if (dbs != null)
00170           {
00171             DatabaseTable t = ((CreateRequest) request).getDatabaseTable();
00172             if (t != null)
00173             {
00174               dbs.addTable(t);
00175               if (logger.isDebugEnabled())
00176                 logger.debug("Added table '" + request.getTableName()
00177                     + "' to backend database schema");
00178             }
00179           }
00180         }
00181         else if (request.isDrop())
00182         { // Delete the table from the schema
00183           DatabaseSchema dbs = backend.getDatabaseSchema();
00184           if (dbs != null)
00185           {
00186             DatabaseTable t = dbs.getTable(request.getTableName());
00187             if (t != null)
00188             {
00189               dbs.removeTable(t);
00190               if (logger.isDebugEnabled())
00191                 logger.debug("Removed table '" + request.getTableName()
00192                     + "' from backend database schema");
00193             }
00194           }
00195         }
00196       }
00197       catch (Exception e)
00198       {
00199         try
00200         { // All backends failed, just ignore
00201           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00202               e))
00203             return;
00204         }
00205         catch (SQLException ignore)
00206         {
00207         }
00208         // Disable this backend (it is no more in sync) by killing the backend
00209         // thread
00210         backendThread.kill();
00211         String msg = "Request '"
00212             + request.getSQLShortForm(backend.getSQLShortFormLength())
00213             + "' failed on backend " + backend.getName() + " but "
00214             + getSuccess() + " succeeded (" + e + ")";
00215 
00216         if (logger.isDebugEnabled())
00217           logger.debug(msg, e);
00218         else
00219           logger.error(msg);
00220         throw new SQLException(msg);
00221       }
00222       finally
00223       {
00224         cm.releaseConnection(c);
00225       }
00226     }
00227     else
00228     { // Re-use the connection used by this transaction
00229       Connection c;
00230       long tid = request.getTransactionId();
00231       Long lTid = new Long(tid);
00232 
00233       try
00234       {
00235         c = backend.getConnectionForTransactionAndLazyBeginIfNeeded(lTid, cm);
00236       }
00237       catch (UnreachableBackendException ube)
00238       {
00239         SQLException se = new SQLException("Backend " + backend.getName()
00240             + " is no more reachable.");
00241         try
00242         {
00243           notifyFailure(backendThread, 1, se);
00244         }
00245         catch (SQLException ignore)
00246         {
00247         }
00248         // Disable this backend (it is no more in sync) by killing the backend
00249         // thread
00250         backendThread.kill();
00251         logger.error("Disabling backend " + backend.getName()
00252             + " because it is no more reachable.");
00253         throw se;
00254       }
00255       catch (NoTransactionStartWhenDisablingException e)
00256       {
00257         // Backend is disabling, we do not execute queries except the one in the
00258         // transaction we already started. Just notify the completion for the
00259         // others.
00260         notifyCompletion();
00261         return;
00262       }
00263       catch (SQLException e1)
00264       {
00265         SQLException se = new SQLException(
00266             "Unable to get connection for transaction " + tid);
00267         try
00268         { // All backends failed, just ignore
00269           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00270               se))
00271             return;
00272         }
00273         catch (SQLException ignore)
00274         {
00275         }
00276         // Disable this backend (it is no more in sync) by killing the
00277         // backend thread
00278         backendThread.kill();
00279         String msg = "Request '"
00280             + request.getSQLShortForm(backend.getSQLShortFormLength())
00281             + "' failed on backend " + backend.getName() + " but "
00282             + getSuccess() + " succeeded (" + se + ")";
00283         logger.error(msg);
00284         throw new SQLException(msg);
00285       }
00286 
00287       // Sanity check
00288       if (c == null)
00289       { // Bad connection
00290         SQLException se = new SQLException(
00291             "Unable to retrieve connection for transaction " + tid);
00292         try
00293         { // All backends failed, just ignore
00294           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00295               se))
00296             return;
00297         }
00298         catch (SQLException ignore)
00299         {
00300         }
00301         // Disable this backend (it is no more in sync) by killing the
00302         // backend thread
00303         backendThread.kill();
00304         String msg = "Request '"
00305             + request.getSQLShortForm(backend.getSQLShortFormLength())
00306             + "' failed on backend " + backend.getName() + " but "
00307             + getSuccess() + " succeeded (" + se + ")";
00308         logger.error(msg);
00309         throw new SQLException(msg);
00310       }
00311 
00312       // Execute Query
00313       try
00314       {
00315         result = AbstractLoadBalancer.executeUpdateRequestOnBackend(request,
00316             backend, c);
00317 
00318         // Update schema
00319         if (request.isCreate())
00320         { // Add the table to the schema
00321           DatabaseSchema dbs = backend.getDatabaseSchema();
00322           if (dbs != null)
00323           {
00324             DatabaseTable t = ((CreateRequest) request).getDatabaseTable();
00325             if (t != null)
00326             {
00327               dbs.addTable(t);
00328               if (logger.isDebugEnabled())
00329                 logger.debug("Added table '" + request.getTableName()
00330                     + "' to backend database schema");
00331             }
00332           }
00333         }
00334         else if (request.isDrop())
00335         { // Delete the table from the schema
00336           DatabaseSchema dbs = backend.getDatabaseSchema();
00337           if (dbs != null)
00338           {
00339             DatabaseTable t = dbs.getTable(request.getTableName());
00340             if (t != null)
00341             {
00342               dbs.removeTable(t);
00343               if (logger.isDebugEnabled())
00344                 logger.debug("Removed table '" + request.getTableName()
00345                     + "' from backend database schema");
00346             }
00347           }
00348         }
00349       }
00350       catch (Exception e)
00351       {
00352         try
00353         { // All backends failed, just ignore
00354           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00355               e))
00356             return;
00357         }
00358         catch (SQLException ignore)
00359         {
00360         }
00361         // Disable this backend (it is no more in sync) by killing the backend
00362         // thread
00363         backendThread.kill();
00364         String msg = "Request '"
00365             + request.getSQLShortForm(backend.getSQLShortFormLength())
00366             + "' failed on backend " + backend.getName() + " but "
00367             + getSuccess() + " succeeded (" + e + ")";
00368         if (logger.isDebugEnabled())
00369           logger.debug(msg, e);
00370         else
00371           logger.error(msg);
00372         throw new SQLException(msg);
00373       }
00374     }
00375     notifySuccess();
00376   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.getResult  ) 
 

Returns the result.

Returns:
int

Definition at line 383 of file WriteRequestTask.java.

00384   {
00385     return result;
00386   }

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

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

Definition at line 391 of file WriteRequestTask.java.

00392   {
00393     if (request.isAutoCommit())
00394       return "WriteAutocommit Task (" + request.getSQL() + ")";
00395     else
00396       return "Write Task from transaction:" + request.getTransactionId() + "("
00397           + request.getSQL() + ")";
00398   }


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