de.phleisch.app.itsucks.core.impl
Class DispatcherImpl

java.lang.Object
  extended by de.phleisch.app.itsucks.core.impl.DispatcherImpl
All Implemented Interfaces:
Dispatcher, org.springframework.context.ApplicationContextAware
Direct Known Subclasses:
DispatcherThread

public class DispatcherImpl
extends java.lang.Object
implements org.springframework.context.ApplicationContextAware, Dispatcher

The dispatcher is the central class to start an job. It contains a JobManager which holds and manages all Jobs and a Worker Pool which contains a thread pool to do the work.

Author:
olli

Constructor Summary
DispatcherImpl()
           
 
Method Summary
 void addJob(Job pJob)
          Adds an single job to the dispatcher.
 void addJobFilter(JobFilter pJobFilter)
          Adds an additional job filter.
 void addJobFilter(java.util.List<JobFilter> pJobFilter)
          Adds an list of job filter.
protected  void doPauseLoop()
           
 EventContext getContext()
          Returns the context for this dispatcher and all included jobs.
 int getDispatchDelay()
          Gets the waiting time between starting two jobs.
 EventDispatcher getEventManager()
          Returns the event manager instance.
 FilterJobManagerImpl getJobManager()
          Returns the job manager instance.
 java.lang.String getName()
           
protected  Job getNextOpenJob()
          Get next open job from the job list
 WorkerPool getWorkerPool()
          Returns the worker pool instance.
 boolean isPaused()
           
 boolean isRunning()
           
 void pause()
          Pause assigning new jobs to working threads.
 void processJobs()
          Start processing the jobs in the job list and delegate it to free worker threads.
 void setApplicationContext(org.springframework.context.ApplicationContext pContext)
           
 void setContext(EventContext pContext)
           
 void setDispatchDelay(int pDispatchDelay)
          Sets the waiting time between starting two jobs.
 void setEventManager(EventDispatcher pEventManager)
           
 void setFilterJobManager(FilterJobManagerImpl pJobManager)
           
 void setName(java.lang.String pName)
          Sets a name for the dispatcher.
 void setWorkerPool(WorkerPool pWorkerPool)
           
 void stop()
          Set the flag to stop the dispatcher
 void unpause()
          Resume assigning new jobs to working threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DispatcherImpl

public DispatcherImpl()
Method Detail

getName

public java.lang.String getName()
Specified by:
getName in interface Dispatcher
Returns:
The name of the dispatcher.

setName

public void setName(java.lang.String pName)
Description copied from interface: Dispatcher
Sets a name for the dispatcher.

Specified by:
setName in interface Dispatcher

processJobs

public void processJobs()
Description copied from interface: Dispatcher
Start processing the jobs in the job list and delegate it to free worker threads. Returns when all jobs are done.

Specified by:
processJobs in interface Dispatcher

getNextOpenJob

protected Job getNextOpenJob()
Get next open job from the job list

Returns:

doPauseLoop

protected void doPauseLoop()

stop

public void stop()
Description copied from interface: Dispatcher
Set the flag to stop the dispatcher

Specified by:
stop in interface Dispatcher

pause

public void pause()
Description copied from interface: Dispatcher
Pause assigning new jobs to working threads.

Specified by:
pause in interface Dispatcher

unpause

public void unpause()
Description copied from interface: Dispatcher
Resume assigning new jobs to working threads.

Specified by:
unpause in interface Dispatcher

isPaused

public boolean isPaused()
Specified by:
isPaused in interface Dispatcher
Returns:
true when the dispatcher is in paused.

getJobManager

public FilterJobManagerImpl getJobManager()
Description copied from interface: Dispatcher
Returns the job manager instance.

Specified by:
getJobManager in interface Dispatcher
Returns:

setFilterJobManager

public void setFilterJobManager(FilterJobManagerImpl pJobManager)

getWorkerPool

public WorkerPool getWorkerPool()
Description copied from interface: Dispatcher
Returns the worker pool instance.

Specified by:
getWorkerPool in interface Dispatcher
Returns:

setWorkerPool

public void setWorkerPool(WorkerPool pWorkerPool)

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext pContext)
                           throws org.springframework.beans.BeansException
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

getEventManager

public EventDispatcher getEventManager()
Description copied from interface: Dispatcher
Returns the event manager instance.

Specified by:
getEventManager in interface Dispatcher
Returns:

getContext

public EventContext getContext()
Description copied from interface: Dispatcher
Returns the context for this dispatcher and all included jobs.

Specified by:
getContext in interface Dispatcher
Returns:

setContext

public void setContext(EventContext pContext)

getDispatchDelay

public int getDispatchDelay()
Description copied from interface: Dispatcher
Gets the waiting time between starting two jobs.

Specified by:
getDispatchDelay in interface Dispatcher

setDispatchDelay

public void setDispatchDelay(int pDispatchDelay)
Description copied from interface: Dispatcher
Sets the waiting time between starting two jobs.

Specified by:
setDispatchDelay in interface Dispatcher

isRunning

public boolean isRunning()
Specified by:
isRunning in interface Dispatcher
Returns:
true when the dispatcher is running.

addJob

public void addJob(Job pJob)
Description copied from interface: Dispatcher
Adds an single job to the dispatcher. The job must be in state STATE_OPEN.

Specified by:
addJob in interface Dispatcher

addJobFilter

public void addJobFilter(JobFilter pJobFilter)
Description copied from interface: Dispatcher
Adds an additional job filter.

Specified by:
addJobFilter in interface Dispatcher

addJobFilter

public void addJobFilter(java.util.List<JobFilter> pJobFilter)
Description copied from interface: Dispatcher
Adds an list of job filter.

Specified by:
addJobFilter in interface Dispatcher

setEventManager

public void setEventManager(EventDispatcher pEventManager)


Copyright © 2010. All Rights Reserved.