biz.hammurapi.dispatch
Class QueuingDispatcher

java.lang.Object
  extended by biz.hammurapi.dispatch.Dispatcher
      extended by biz.hammurapi.dispatch.QueuingDispatcher

public class QueuingDispatcher
extends Dispatcher

This class puts results to a queue, which is processed by a worker. An internal thread is used to push jobs to worker or execute jobs if worker is null.

Author:
Pavel Vlasov

Nested Class Summary
protected  class QueuingDispatcher.DispatchJob
           
 
Nested classes/interfaces inherited from class biz.hammurapi.dispatch.Dispatcher
Dispatcher.Invocation
 
Field Summary
protected  java.util.LinkedList queue
           
 
Constructor Summary
QueuingDispatcher(java.util.Collection targets, biz.hammurapi.util.Worker worker)
          Constructor
 
Method Summary
 void dispatch(java.lang.Object arg)
          Puts argument to dispatching queue.
 void join()
          Blocks until all jobs are processed.
protected  void postJobToQueue(java.lang.Runnable foreignJob)
          Allows subclasses to post non-dispatching jobs to the queue.
 void stop()
          Processes all jobs and stops queue processing thread.
 
Methods inherited from class biz.hammurapi.dispatch.Dispatcher
consumeResult, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queue

protected java.util.LinkedList queue
Constructor Detail

QueuingDispatcher

public QueuingDispatcher(java.util.Collection targets,
                         biz.hammurapi.util.Worker worker)
Constructor

Parameters:
targets -
worker - Worker to delegate dispatching jobs to. Can be null.
Method Detail

postJobToQueue

protected void postJobToQueue(java.lang.Runnable foreignJob)
Allows subclasses to post non-dispatching jobs to the queue.

Parameters:
job -

dispatch

public void dispatch(java.lang.Object arg)
Puts argument to dispatching queue. The queue is processed by an internal thread, which posts dispatching jobs to worker or processes them itself if worker is null.

Overrides:
dispatch in class Dispatcher
Parameters:
arg - Instance to be dispatched.

join

public void join()
          throws java.lang.InterruptedException
Blocks until all jobs are processed.

Throws:
java.lang.InterruptedException

stop

public void stop()
          throws java.lang.InterruptedException
Processes all jobs and stops queue processing thread.

Throws:
java.lang.InterruptedException


Copyright © 2005 Hammurapi Group. All Rights Reserved.