org.ourgrid.mygrid.replicaexecutor
Class ReplicaExecutorThreadManager

java.lang.Object
  extended by java.lang.Thread
      extended by org.ourgrid.mygrid.replicaexecutor.ReplicaExecutorThreadManager
All Implemented Interfaces:
java.lang.Runnable, Shutdownable

public class ReplicaExecutorThreadManager
extends java.lang.Thread
implements Shutdownable

This class takes care of a thread pool. Threads inside the pool are in charge of executing replicas. Description: A thread pool that contains all ReplicaExecutorThread objects.

Version:
1.0 Created on 12/07/2004

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int FAKE
          Fake execution identifier
static int MG
          Real execution identifier
static int THREAD_POOL_SIZE
          Amount of threads in the pool TODO This number should be calculated in a dynamic way based on the number of available GuMs
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ReplicaExecutorThreadManager(EBReplicaExecutorFacade ebReplicaExecutorFacade)
          Simple constructor.
ReplicaExecutorThreadManager(EBReplicaExecutorFacade ebReplicaExecutorFacade, int type, int threadPoolSize)
          Main constructor
 
Method Summary
 java.util.Collection<ReplicaExecutor> getReplicaExecutorThreads()
          Provides a Collection that contains all ReplicaExecutorThread objects.
 ReplicaExecutor obtainReplicaExecutorThread(ReplicaEntry replica, GumClient gumClient)
          Provides a replicaExecutorThread
 void releaseReplicaExecutorThread(ReplicaEntry replica)
          Releases a thread to the pool
 void replicaFinished(ReplicaEntry replica)
          Registers that a replica has finished
 void shutdown()
          Shuts down all threads in the pool, including the pool itself
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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

MG

public static final int MG
Real execution identifier

See Also:
Constant Field Values

FAKE

public static final int FAKE
Fake execution identifier

See Also:
Constant Field Values

THREAD_POOL_SIZE

public static int THREAD_POOL_SIZE
Amount of threads in the pool TODO This number should be calculated in a dynamic way based on the number of available GuMs

Constructor Detail

ReplicaExecutorThreadManager

public ReplicaExecutorThreadManager(EBReplicaExecutorFacade ebReplicaExecutorFacade)
Simple constructor.

Parameters:
ebReplicaExecutorFacade - The EBReplicaExecutorFacade

ReplicaExecutorThreadManager

public ReplicaExecutorThreadManager(EBReplicaExecutorFacade ebReplicaExecutorFacade,
                                    int type,
                                    int threadPoolSize)
Main constructor

Parameters:
ebReplicaExecutorFacade - The EBReplicaExecutorFacade
type - Defines whether this class must use either FakeReplicaExecutorThread (usually for tests) or MGReplicaExecutorThread (for real execution)
threadPoolSize - The number of threads in the threadPool
Method Detail

obtainReplicaExecutorThread

public ReplicaExecutor obtainReplicaExecutorThread(ReplicaEntry replica,
                                                   GumClient gumClient)
                                            throws ReplicaExecutorThreadException
Provides a replicaExecutorThread

Parameters:
replica - Replica to be executed by the ReplicaExecutorThread
gumClient - Grid machine where the replica will be executed.
Returns:
A ReplicaExecutorThread object to execute the replica.
Throws:
ReplicaExecutorThreadException

releaseReplicaExecutorThread

public void releaseReplicaExecutorThread(ReplicaEntry replica)
                                  throws ReplicaExecutorThreadException
Releases a thread to the pool

Parameters:
replica - Replica associated with the ReplicaExecutorThread to be released.
Throws:
ReplicaExecutorThreadException

getReplicaExecutorThreads

public java.util.Collection<ReplicaExecutor> getReplicaExecutorThreads()
Provides a Collection that contains all ReplicaExecutorThread objects.

Returns:
A Collection that contains all ReplicaExecutorThread objects.

shutdown

public void shutdown()
Shuts down all threads in the pool, including the pool itself

Specified by:
shutdown in interface Shutdownable

replicaFinished

public void replicaFinished(ReplicaEntry replica)
Registers that a replica has finished

Parameters:
replica - The replica that has finished.