org.objectweb.cjdbc.controller.loadbalancer
Class BackendWorkerThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread
All Implemented Interfaces:
java.lang.Runnable

public class BackendWorkerThread
extends java.lang.Thread

Process sequentially a set of tasks and send them to a backend.

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
private  DatabaseBackend backend
           
private  AbstractTask currentlyProcessingTask
           
private  java.lang.Long currentTaskTid
           
private  boolean isKilled
           
private  AbstractLoadBalancer loadBalancer
           
private  Trace logger
           
private  java.util.ArrayList taskList
           
private  java.util.ArrayList tidList
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BackendWorkerThread(DatabaseBackend backend, AbstractLoadBalancer loadBalancer)
          Creates a new BackendWorkerThread.
BackendWorkerThread(java.lang.String name, DatabaseBackend backend, AbstractLoadBalancer loadBalancer)
          Creates a new BackendWorkerThread.
 
Method Summary
 void addPriorityTask(AbstractTask task)
          Adds a task upfront to the task list so that this task will be the next executed task.
 void addPriorityTask(AbstractTask task, long transactionId)
          Adds a task upfront to the task list so that this task will be the next executed task.
 void addTask(AbstractTask task)
          Adds a task at the end of the task list.
 void addTask(AbstractTask task, long transactionId)
          Adds a task at the end of the task list.
 DatabaseBackend getBackend()
          Returns the backend.
 Trace getLogger()
          Returns the logger for tracing.
 boolean hasTaskForTransaction(java.lang.Long tid)
          Returns true if the thread has pending tasks for the given transaction.
 void insertTaskAfterLastWriteForTransaction(AbstractTask task, java.lang.Long transactionId)
          Adds a task just after the last write task for the given transaction in the task list.
 void kill()
          Kills this thread after the next task processing and forces the load balancer to disable the backend.
private  void kill(boolean forceDisable)
          Kills this thread after the next task processing.
 void killWithoutDisablingBackend()
          Kills this thread after the next task processing.
 void run()
          Process the tasklist and call wait() (on itself) when the tasklist becomes empty.
 void waitForAllTasksToComplete()
          Waits for all current tasks to complete.
 void waitForAllTasksToComplete(long transactionId)
          Waits for all tasks of the specified transaction to complete.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

loadBalancer

private AbstractLoadBalancer loadBalancer

backend

private DatabaseBackend backend

taskList

private java.util.ArrayList taskList

tidList

private java.util.ArrayList tidList

isKilled

private boolean isKilled

currentlyProcessingTask

private AbstractTask currentlyProcessingTask

currentTaskTid

private java.lang.Long currentTaskTid

logger

private Trace logger
Constructor Detail

BackendWorkerThread

public BackendWorkerThread(DatabaseBackend backend,
                           AbstractLoadBalancer loadBalancer)
                    throws java.sql.SQLException
Creates a new BackendWorkerThread.

Parameters:
backend - the backend this thread is associated to.
loadBalancer - the load balancer instanciating this thread
Throws:
java.sql.SQLException - if an error occurs

BackendWorkerThread

public BackendWorkerThread(java.lang.String name,
                           DatabaseBackend backend,
                           AbstractLoadBalancer loadBalancer)
                    throws java.sql.SQLException
Creates a new BackendWorkerThread.

Parameters:
name - the name to give to the thread
backend - the backend this thread is associated to.
loadBalancer - the load balancer instanciating this thread
Throws:
java.sql.SQLException - if an error occurs
Method Detail

addTask

public void addTask(AbstractTask task)
Adds a task at the end of the task list. Warning! This method is not synchronized and the caller must synchronize on the thread before calling this method.

Parameters:
task - the task to add

addTask

public void addTask(AbstractTask task,
                    long transactionId)
Adds a task at the end of the task list. Warning! This method is not synchronized and the caller must synchronize on the thread before calling this method.

Parameters:
task - the task to add
transactionId - transaction id in which this task execute

insertTaskAfterLastWriteForTransaction

public void insertTaskAfterLastWriteForTransaction(AbstractTask task,
                                                   java.lang.Long transactionId)
Adds a task just after the last write task for the given transaction in the task list. Warning! This method is not synchronized and the caller must synchronize on the thread before calling this method.

This method is usually used to insert a commit/rollback task when asynchrony is allowed between backends.

Parameters:
task - the task to add
transactionId - transaction id in which this task execute

addPriorityTask

public void addPriorityTask(AbstractTask task)
Adds a task upfront to the task list so that this task will be the next executed task. Warning! This method is not synchronized and the caller must synchronize on the thread before calling this method.

Parameters:
task - the task to add

addPriorityTask

public void addPriorityTask(AbstractTask task,
                            long transactionId)
Adds a task upfront to the task list so that this task will be the next executed task. Warning! This method is not synchronized and the caller must synchronize on the thread before calling this method

Parameters:
task - the task to add
transactionId - transaction id in which this task execute

hasTaskForTransaction

public boolean hasTaskForTransaction(java.lang.Long tid)
Returns true if the thread has pending tasks for the given transaction.

Parameters:
tid - the transaction identifier
Returns:
true if the task list contains task(s) for transaction tid.

waitForAllTasksToComplete

public void waitForAllTasksToComplete(long transactionId)
Waits for all tasks of the specified transaction to complete.

Parameters:
transactionId - the transaction identifier

waitForAllTasksToComplete

public void waitForAllTasksToComplete()
Waits for all current tasks to complete.


kill

public void kill()
Kills this thread after the next task processing and forces the load balancer to disable the backend. It also marks all remaining tasks in the task list as failed.


killWithoutDisablingBackend

public void killWithoutDisablingBackend()
Kills this thread after the next task processing. It also marks all remaining tasks in the task list as failed.


kill

private void kill(boolean forceDisable)
Kills this thread after the next task processing. It also marks all remaining tasks in the task list as failed.

Parameters:
forceDisable - true if the task must call the load balancer to disable the backend

run

public void run()
Process the tasklist and call wait() (on itself) when the tasklist becomes empty.


getBackend

public DatabaseBackend getBackend()
Returns the backend.

Returns:
a DatabaseBackend instance

getLogger

public Trace getLogger()
Returns the logger for tracing.

Returns:
a Trace instance


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