org.apache.droids
Class AbstractDroid

Package class diagram package AbstractDroid
java.lang.Object
  extended by org.apache.droids.AbstractDroid
All Implemented Interfaces:
Runnable, Droid
Direct Known Subclasses:
HelloCrawler

public abstract class AbstractDroid
extends Object
implements Droid


Constructor Summary
AbstractDroid()
           
 
Method Summary
 void finishedWorker(long id)
          Notification that we finished a given worker.
 Core getCore()
          Return the core configuration for the current Droid.
 int getFreeSlots()
          Get number of slots that we have currently open to accept new workers.
 int getMaxThreads()
          Get number of maximum allowed threads
 ThreadPoolExecutor getPool()
          Get our pool.
protected  Queue getQueue()
          Get the queue implementation that we want to use.
 int getRunningThreads()
          Get number of currently running threads
 ConcurrentHashMap<Long,Worker> getRunningWorker()
          Return the map of running workers
 String getTaskDate()
          When did the task showed up the first time in the queue
abstract  Worker getWorker()
          Get the default worker for the class.
 void setCore(Core core)
          Set the fully configured core and inject it in the
 void setFreeSlots(int freeSlots)
          Set number of slots that we have currently open to accept new workers
 void setMaxThreads(int maxThreads)
          Adjust number of allowed threads
 void setPool(ThreadPoolExecutor pool)
          Set our pool.
 void setQueue(Queue queue)
          Which implementation of a queue are we using.
 void setRunningThreads(int runningThreads)
          To set the number of running threads.
 void setRunningWorker(ConcurrentHashMap<Long,Worker> runningWorker)
          Set the map of running workers
 void setTaskDate(String taskDate)
          When did the task showed up the first time in the queue
protected  void shutdownAndAwaitTermination()
          Shutdown all threads, close the pools and leave.
abstract  long startWorkers()
          Will start a new worker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.droids.api.Droid
initQueue, run
 

Constructor Detail

AbstractDroid

public AbstractDroid()
Method Detail

finishedWorker

public void finishedWorker(long id)
                    throws DroidsException
Description copied from interface: Droid
Notification that we finished a given worker. The implementation would normally remove the worker from the pool and start a new worker instead (if needed). If not needed this method normally invokes/requests the shutdown of the main process.

Specified by:
finishedWorker in interface Droid
Parameters:
id - the id of the worker that has finished
Throws:
DroidsException

startWorkers

public abstract long startWorkers()
Will start a new worker.

Returns:
the id of the worker we just started.

getWorker

public abstract Worker getWorker()
                          throws DroidsException
Get the default worker for the class.

Returns:
Worker that should do the job.
Throws:
DroidsException

getCore

public Core getCore()
Description copied from interface: Droid
Return the core configuration for the current Droid. The core contains all configured objects ready to use.

Specified by:
getCore in interface Droid
Returns:
ready to use configured core

setCore

public void setCore(Core core)
Set the fully configured core and inject it in the

Parameters:
core -

getPool

public ThreadPoolExecutor getPool()
Get our pool.

Returns:
our pool

setPool

public void setPool(ThreadPoolExecutor pool)
Set our pool.

Parameters:
pool - the new pool.

getRunningWorker

public ConcurrentHashMap<Long,Worker> getRunningWorker()
Return the map of running workers

Returns:
map of running workers

setRunningWorker

public void setRunningWorker(ConcurrentHashMap<Long,Worker> runningWorker)
Set the map of running workers

Parameters:
runningWorker - new map of running workers

setRunningThreads

public void setRunningThreads(int runningThreads)
To set the number of running threads.

Parameters:
runningThreads -

getRunningThreads

public int getRunningThreads()
Get number of currently running threads

Returns:
number of currently running threads

getTaskDate

public String getTaskDate()
When did the task showed up the first time in the queue

Returns:
the date when the task registered with the queue

setTaskDate

public void setTaskDate(String taskDate)
When did the task showed up the first time in the queue

Parameters:
taskDate - the date when the task registered with the queue

getFreeSlots

public int getFreeSlots()
Get number of slots that we have currently open to accept new workers.

Returns:
number of slots that are waiting to serve

setFreeSlots

public void setFreeSlots(int freeSlots)
Set number of slots that we have currently open to accept new workers

Parameters:
freeSlots - number of slots that are waiting to serve

setMaxThreads

public void setMaxThreads(int maxThreads)
Adjust number of allowed threads

Parameters:
maxThreads -

getMaxThreads

public int getMaxThreads()
Get number of maximum allowed threads

Returns:
the number of maximum threads that we allow

setQueue

public void setQueue(Queue queue)
Description copied from interface: Droid
Which implementation of a queue are we using. Setter method to make sure different implementation can override the method.

Not all implementations are using a queue at all.

Specified by:
setQueue in interface Droid
Parameters:
queue - queue implementation

getQueue

protected Queue getQueue()
Get the queue implementation that we want to use.

Returns:
queue that is used for this droid

shutdownAndAwaitTermination

protected void shutdownAndAwaitTermination()
Shutdown all threads, close the pools and leave. If it is not working by asking nice to shutdown just kill all threads.



Copyright © 2008 The Apache Software Foundation