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, RollbackTask, 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

Field Summary
private  java.util.ArrayList exceptions
           
private  int failed
           
private  int nbToComplete
          Number of threads that must succeed before returning.
private  int success
           
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
abstract  void execute(BackendWorkerThread backendThread)
          The task code to be executed by backendThread.
 java.util.ArrayList getExceptions()
          Returns the exceptions lists.
 int getFailed()
          Returns the failed.
 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 notifyFailure(BackendWorkerThread backendThread, long timeout, java.sql.SQLException e)
          Notifies that the specified backendThread failed to execute this task.
 void notifySuccess()
          Notifies the successful completion of this task.
 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.


success

private int success

failed

private int failed

exceptions

private java.util.ArrayList exceptions
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 abstract void execute(BackendWorkerThread backendThread)
                      throws java.sql.SQLException
The 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.


notifyFailure

public boolean notifyFailure(BackendWorkerThread backendThread,
                             long timeout,
                             java.sql.SQLException 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

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()


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