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

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

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

Inheritance graph
[legend]
List of all members.

Public Member Functions

 AbstractTask (int nbToComplete, int totalNb)
void execute (BackendWorkerThread backendThread) throws SQLException
abstract void executeTask (BackendWorkerThread backendThread) throws SQLException
synchronized void notifySuccess ()
synchronized void notifyCompletion ()
synchronized boolean notifyFailure (BackendWorkerThread backendThread, long timeout, Exception e) throws SQLException
ArrayList getExceptions ()
synchronized int getExecutionStarted ()
int getFailed ()
int getNbToComplete ()
int getSuccess ()
int getTotalNb ()
void setTotalNb (int totalNb)
boolean hasTid ()
void setHasTid (boolean hasTid)
ResultSet getGeneratedKeysResultSet ()
void setGeneratedKeysResultSet (ResultSet generatedKeysResultSet)
synchronized boolean setExpiredTimeout ()

Detailed Description

Defines an abstract task to be processed by a BackendWorkerThread.

Author:
Emmanuel Cecchet

Jaco Swart

Version:
1.0

Definition at line 42 of file AbstractTask.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.AbstractTask int  nbToComplete,
int  totalNb
 

Sets the number of threads among the total number of threads that must successfully complete the execution of this AbstractTask before returning.

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

Definition at line 87 of file AbstractTask.java.

00088   {
00089     this.nbToComplete = nbToComplete;
00090     this.totalNb = totalNb;
00091     success = 0;
00092     failed = 0;
00093     executionStarted = 0;
00094   }


Member Function Documentation

void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.execute BackendWorkerThread  backendThread  )  throws SQLException
 

The task code executed by the backendThread.

Parameters:
backendThread The backend thread executing this task
Exceptions:
SQLException if an error occurs

Definition at line 106 of file AbstractTask.java.

00107   {
00108     synchronized (this)
00109     {
00110       // If the task has expired and nobody has executed it yet, we ignore it
00111       // else we have to play it.
00112       // Note that the exception corresponding to the timeout is set by the
00113       // caller of setExpiredTimeout.
00114       if (timeoutExpired && (executionStarted == 0))
00115         return;
00116       this.executionStarted++;
00117     }
00118     executeTask(backendThread);
00119     // Completed executions are handled by the task internal code that calls
00120     // notifyFailure or notifySuccess.
00121   }

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

The implementation specific task code to be executed by backendThread.

Parameters:
backendThread The backend thread executing this task
Exceptions:
SQLException if an error occurs

Implemented in org.objectweb.cjdbc.controller.loadbalancer.tasks.BeginTask, org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask, org.objectweb.cjdbc.controller.loadbalancer.tasks.KillThreadTask, org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask, org.objectweb.cjdbc.controller.loadbalancer.tasks.RollbackTask, org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask, org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask, org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask, and org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.

ArrayList org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getExceptions  ) 
 

Returns the exceptions lists.

Returns:
an ArrayList

Definition at line 234 of file AbstractTask.java.

00235   {
00236     return exceptions;
00237   }

synchronized int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getExecutionStarted  ) 
 

Returns the number of threads that have started the execution of the task.

Returns:
Returns the number of started executions.

Definition at line 244 of file AbstractTask.java.

00245   {
00246     return executionStarted;
00247   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getFailed  ) 
 

Returns the failed.

Returns:
an int value

Definition at line 254 of file AbstractTask.java.

Referenced by org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.rollback(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.rollback(), and org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.rollback().

00255   {
00256     return failed;
00257   }

ResultSet org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getGeneratedKeysResultSet  ) 
 

Returns the generatedKeysResultSet value.

Returns:
Returns the generatedKeysResultSet.

Definition at line 330 of file AbstractTask.java.

00331   {
00332     return generatedKeysResultSet;
00333   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getNbToComplete  ) 
 

Returns the number of threads that must succeed before returning.

Returns:
an int value

Definition at line 264 of file AbstractTask.java.

00265   {
00266     return nbToComplete;
00267   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getSuccess  ) 
 

Returns the success.

Returns:
an int value

Definition at line 274 of file AbstractTask.java.

Referenced by org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.commit(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.RollbackTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.BeginTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.rollback(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.rollback(), and org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.rollback().

00275   {
00276     return success;
00277   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getTotalNb  ) 
 

Returns the total number of threads.

Returns:
an int value
See also:
setTotalNb

Definition at line 285 of file AbstractTask.java.

00286   {
00287     return totalNb;
00288   }

boolean org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.hasTid  ) 
 

Returns true if this task has a tid attached to it.

Used internally by BackendWorkerThread.

Returns:
Returns the hasTid.

Definition at line 308 of file AbstractTask.java.

00309   {
00310     return hasTid;
00311   }

synchronized void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyCompletion  ) 
 

This is used to notify the completion of this task without success or failure. This is usually used when the task has been discarded for example by a backend that is currently disabling but still needs to execute the remaining queries in open transactions.

Therefore, this only decrements by one the number of threads that needs to complete.

Definition at line 159 of file AbstractTask.java.

Referenced by org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.executeTask(), and org.objectweb.cjdbc.controller.loadbalancer.tasks.BeginTask.executeTask().

00160   {
00161     totalNb--;
00162     // Notify if needed
00163     if (success + failed == totalNb)
00164     {
00165       notifyAll(); // Notify all failed threads
00166     }
00167   }

synchronized boolean org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyFailure BackendWorkerThread  backendThread,
long  timeout,
Exception  e
throws SQLException
 

Notifies that the specified backendThread failed to execute this task. If all nodes failed, this method return false meaning that the problem was due to the task and not to the thread. If the method returns true, it can mean that this thread failed and is no more coherent, therefore the backend associated to this thread should be disabled.

Parameters:
backendThread the backend thread that has failed
timeout time in milliseconds to wait for other threads to signal success or failure
e the exception causing the failure
Returns:
true if at least one node succeeded to execute this task, false if all threads failed
Exceptions:
SQLException if an error occured in the notification process

Definition at line 185 of file AbstractTask.java.

Referenced by org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.RollbackTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.executeTask(), and org.objectweb.cjdbc.controller.loadbalancer.tasks.BeginTask.executeTask().

00187   {
00188     failed++;
00189 
00190     // Log the exception
00191     if (exceptions == null)
00192       exceptions = new ArrayList();
00193     if (e instanceof SQLException)
00194     {
00195       SQLException sqlEx = (SQLException) e;
00196       exceptions
00197           .add(SQLExceptionFactory.getSQLException(sqlEx,"BackendThread "
00198               + backendThread.getBackend().getName() + " failed ("
00199               + sqlEx.getMessage() + ")"));
00200     }
00201     else
00202       exceptions.add(new SQLException("BackendThread "
00203           + backendThread.getBackend().getName() + " failed (" + e + ")"));
00204 
00205     // Notify if needed
00206     if (success + failed == totalNb)
00207     {
00208       notifyAll(); // Notify all failed threads
00209     }
00210     else
00211     {
00212       try
00213       { // Wait to check if all other threads failed or not
00214         wait(timeout);
00215       }
00216       catch (InterruptedException ie)
00217       {
00218         throw new SQLException("Wait interrupted() in failed task of backend "
00219             + backendThread.getBackend().getName() + " (" + e + ")");
00220       }
00221     }
00222     return success > 0;
00223   }

synchronized void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifySuccess  ) 
 

Notifies the successful completion of this task.

Definition at line 135 of file AbstractTask.java.

Referenced by org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.RollbackTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.executeTask(), org.objectweb.cjdbc.controller.loadbalancer.tasks.KillThreadTask.executeTask(), and org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.executeTask().

00137   {
00138     success++;
00139 
00140     // Notify if needed
00141     if ((success == nbToComplete) || (success + failed == totalNb))
00142     {
00143       if (failed > 0)
00144         notifyAll(); // Notify all failed threads too
00145       else
00146         notify();
00147     }
00148   }

synchronized boolean org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.setExpiredTimeout  ) 
 

Set the flag to tell that the timeout has expired on this task. If no backend has started the task execution then the task will be canceled and the method will return true. Otherwise, all backends will execute the request and the method will return false.

Returns:
true if BackendThreads will ignore the task, false if all backends will execute the task.

Definition at line 354 of file AbstractTask.java.

Referenced by org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.rollback(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.rollback(), and org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.rollback().

00355   {
00356     this.timeoutExpired = true;
00357     return executionStarted == 0;
00358   }

void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.setGeneratedKeysResultSet ResultSet  generatedKeysResultSet  ) 
 

Sets the generatedKeysResultSet value.

Parameters:
generatedKeysResultSet The generatedKeysResultSet to set.

Definition at line 340 of file AbstractTask.java.

00341   {
00342     this.generatedKeysResultSet = generatedKeysResultSet;
00343   }

void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.setHasTid boolean  hasTid  ) 
 

Sets the hasTid value.

Used internally by BackendWorkerThread.

Parameters:
hasTid The hasTid to set.

Definition at line 320 of file AbstractTask.java.

00321   {
00322     this.hasTid = hasTid;
00323   }

void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.setTotalNb int  totalNb  ) 
 

Sets the total number of threads.

Parameters:
totalNb the total number of threads to set
See also:
getTotalNb

Definition at line 296 of file AbstractTask.java.

00297   {
00298     this.totalNb = totalNb;
00299   }


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