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

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask
Direct Known Subclasses:
BeginTask, CommitTask, KillThreadTask, ReadStoredProcedureTask, ReleaseSavepointTask, RollbackTask, RollbackToSavepointTask, SavepointTask, SelectRequestTask, WriteRequestTask, WriteRequestWithKeysTask, WriteStoredProcedureTask

public abstract class AbstractTask
extends java.lang.Object

Defines an abstract task to be processed by a BackendWorkerThread.

Version:
1.0
Author:
Emmanuel Cecchet , Jaco Swart

Field Summary
private  java.util.ArrayList exceptions
          List of exceptions of failed nodes
private  int executionStarted
          Number of thread that have started the execution of the task
private  int failed
          Number of backendThread that have failed
private  java.sql.ResultSet generatedKeysResultSet
           
private  boolean hasTid
           
private  int nbToComplete
          Number of threads that must succeed before returning.
private  int success
          Number of backendThread that have succeeded
private  boolean timeoutExpired
           
private  int totalNb
          Total number of threads.
 
Constructor Summary
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.
 
Method Summary
 void execute(BackendWorkerThread backendThread)
          The task code executed by the backendThread.
abstract  void executeTask(BackendWorkerThread backendThread)
          The implementation specific task code to be executed by backendThread.
 java.util.ArrayList getExceptions()
          Returns the exceptions lists.
 int getExecutionStarted()
          Returns the number of threads that have started the execution of the task.
 int getFailed()
          Returns the failed.
 java.sql.ResultSet getGeneratedKeysResultSet()
          Returns the generatedKeysResultSet value.
 int getNbToComplete()
          Returns the number of threads that must succeed before returning.
 int getSuccess()
          Returns the success.
 int getTotalNb()
          Returns the total number of threads.
 boolean hasCompleted()
          Returns true if the task has been sucessfully completed by nbToComplete nodes (set in the constructor) of if everyone has completed (succesfully or not), false otherwise.
 boolean hasFullyCompleted()
          Returns true if the task has completed (succesfully or not) or false if we are still expecting answers from some backends.
 boolean hasTid()
          Returns true if this task has a tid attached to it.
 void notifyCompletion()
          This is used to notify the completion of this task without success or failure.
 boolean notifyFailure(BackendWorkerThread backendThread, long timeout, java.lang.Exception e)
          Notifies that the specified backendThread failed to execute this task.
 void notifySuccess()
          Notifies the successful completion of this task.
 boolean setExpiredTimeout()
          Set the flag to tell that the timeout has expired on this task.
 void setGeneratedKeysResultSet(java.sql.ResultSet generatedKeysResultSet)
          Sets the generatedKeysResultSet value.
 void setHasTid(boolean hasTid)
          Sets the hasTid value.
 void setTotalNb(int totalNb)
          Sets the total number of threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

totalNb

private int totalNb
Total number of threads.


nbToComplete

private int nbToComplete
Number of threads that must succeed before returning.


executionStarted

private int executionStarted
Number of thread that have started the execution of the task


success

private int success
Number of backendThread that have succeeded


failed

private int failed
Number of backendThread that have failed


exceptions

private java.util.ArrayList exceptions
List of exceptions of failed nodes


hasTid

private boolean hasTid

generatedKeysResultSet

private java.sql.ResultSet generatedKeysResultSet

timeoutExpired

private boolean timeoutExpired
Constructor Detail

AbstractTask

public 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
Method Detail

execute

public void execute(BackendWorkerThread backendThread)
             throws java.sql.SQLException
The task code executed by the backendThread.

Parameters:
backendThread - The backend thread executing this task
Throws:
java.sql.SQLException - if an error occurs

executeTask

public abstract void executeTask(BackendWorkerThread backendThread)
                          throws java.sql.SQLException
The implementation specific task code to be executed by backendThread.

Parameters:
backendThread - The backend thread executing this task
Throws:
java.sql.SQLException - if an error occurs

notifySuccess

public void notifySuccess()
Notifies the successful completion of this task.


notifyCompletion

public void 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.


notifyFailure

public boolean notifyFailure(BackendWorkerThread backendThread,
                             long timeout,
                             java.lang.Exception e)
                      throws java.sql.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
Throws:
java.sql.SQLException - if an error occured in the notification process

getExceptions

public java.util.ArrayList getExceptions()
Returns the exceptions lists.

Returns:
an ArrayList

getExecutionStarted

public int getExecutionStarted()
Returns the number of threads that have started the execution of the task.

Returns:
Returns the number of started executions.

getFailed

public int getFailed()
Returns the failed.

Returns:
an int value

getNbToComplete

public int getNbToComplete()
Returns the number of threads that must succeed before returning.

Returns:
an int value

getSuccess

public int getSuccess()
Returns the success.

Returns:
an int value

getTotalNb

public int getTotalNb()
Returns the total number of threads.

Returns:
an int value
See Also:
setTotalNb(int)

setTotalNb

public void setTotalNb(int totalNb)
Sets the total number of threads.

Parameters:
totalNb - the total number of threads to set
See Also:
getTotalNb()

hasCompleted

public boolean hasCompleted()
Returns true if the task has been sucessfully completed by nbToComplete nodes (set in the constructor) of if everyone has completed (succesfully or not), false otherwise.

Returns:
true if the task execution is complete
See Also:
AbstractTask(int, int)

hasFullyCompleted

public boolean hasFullyCompleted()
Returns true if the task has completed (succesfully or not) or false if we are still expecting answers from some backends.

Returns:
true if the task execution is complete

hasTid

public boolean hasTid()
Returns true if this task has a tid attached to it.

Used internally by BackendWorkerThread.

Returns:
Returns the hasTid.

setHasTid

public void setHasTid(boolean hasTid)
Sets the hasTid value.

Used internally by BackendWorkerThread.

Parameters:
hasTid - The hasTid to set.

getGeneratedKeysResultSet

public java.sql.ResultSet getGeneratedKeysResultSet()
Returns the generatedKeysResultSet value.

Returns:
Returns the generatedKeysResultSet.

setGeneratedKeysResultSet

public void setGeneratedKeysResultSet(java.sql.ResultSet generatedKeysResultSet)
Sets the generatedKeysResultSet value.

Parameters:
generatedKeysResultSet - The generatedKeysResultSet to set.

setExpiredTimeout

public boolean 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.


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.