biz.hammurapi.dispatch
Class Dispatcher

java.lang.Object
  extended by biz.hammurapi.dispatch.Dispatcher
Direct Known Subclasses:
QueuingDispatcher

public class Dispatcher
extends java.lang.Object

This class dispatches objects to invocation handlers which can accept them. Target invocation handlers are organized in "buckets" keyed by the argument class. This makes dispatching very efficient at runtime because only compatible handlers are interated over for invocation.

Author:
Pavel Vlasov

Nested Class Summary
protected static interface Dispatcher.Invocation
          Simple form of invocation used by dispatcher to chain invocations.
 
Constructor Summary
Dispatcher(java.util.Collection targets)
          Creates dispatcher.
 
Method Summary
protected  void consumeResult(java.lang.Object result)
          Consumes invocation results.
 void dispatch(java.lang.Object arg)
          Dispatches object to invocation handlers.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dispatcher

public Dispatcher(java.util.Collection targets)
Creates dispatcher.

Parameters:
targets - Collection which contains instances of InvocationTarget or InvocationHandler.
Method Detail

dispatch

public void dispatch(java.lang.Object arg)
Dispatches object to invocation handlers. Exceptions thrown by handlers are wrapped into DispatchException and that exception is dispatched as though it is a return value. It is recommended to have an invocation handler which would handle thrown exceptions, e.g. log them. Errors are propagated up.

Parameters:
arg - Instance to be dispatched.

consumeResult

protected void consumeResult(java.lang.Object result)
Consumes invocation results. This implementation simply dispatches results. Override this method to provide more advanced results handling.

Parameters:
result -

size

public int size()
Returns:
Number of handlers


Copyright © 2005 Hammurapi Group. All Rights Reserved.