com.debianmirror.server
Class WorkerCache

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.debianmirror.server.WorkerCache
All Implemented Interfaces:
java.lang.Runnable

public class WorkerCache
extends java.lang.Thread

The WorkerCache hold a bunch of already started Worker threads. This way the delay of creating a new thread is minimized. It also controls how many Worker threads are running concurrently.

Author:
E01 - Tobias Hertkorn, Jonas Jagerhok, Jamie Fitz-Gerald

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WorkerCache(WorkerImplFactory factory)
          Creates a new WorkerCache.
 
Method Summary
 void addWorker(Worker worker)
          Inserts the given Worker (back) into this WorkerCache.
 Worker getWorker()
          Returns an idle worker from the workerList.
 void killCache()
          Kills the cache gracefully.
 void run()
          Main method of the thread.
 void setMaxIdleWorkers(int mIW)
          Sets the maxIdleWorkers.
 void setMinIdleWorkers(int mIW)
          Sets the minIdleWorkers.
 
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
 

Constructor Detail

WorkerCache

public WorkerCache(WorkerImplFactory factory)
Creates a new WorkerCache. This WorkerCache will employ Workers using the WorkerImplFactory.

Parameters:
factory -
Method Detail

setMinIdleWorkers

public void setMinIdleWorkers(int mIW)
Sets the minIdleWorkers.

Parameters:
mIW - the desired numbers of minimal idleWorkers.

setMaxIdleWorkers

public void setMaxIdleWorkers(int mIW)
Sets the maxIdleWorkers.


getWorker

public Worker getWorker()

Returns an idle worker from the workerList.

Returns:
an idle worker

addWorker

public void addWorker(Worker worker)

Inserts the given Worker (back) into this WorkerCache.
That is if the WorkerCache is not full yet.
Mostly used by the Worker after it is done with the assigned work.


killCache

public void killCache()
Kills the cache gracefully.


run

public void run()
Main method of the thread. When started it creates the initial workers.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread


Copyright © 2004, Apt-Got Group