sk.baka.ambient.commons
Class SimpleBus

java.lang.Object
  extended by sk.baka.ambient.commons.SimpleBus

public final class SimpleBus
extends Object

A simple message delivery bus. All events are invoked asynchronously in the message loop.

Author:
Martin Vysny

Constructor Summary
SimpleBus()
           
 
Method Summary
 void addHandler(Object handler)
          Registers this handler.
 void addHandler(Object handler, Class<?> messageType)
          Registers given handler only to given message type.
 void clear()
          Removes all handlers and cleans up the object.
<T> T
getInvocator(Class<T> messageType, boolean async)
          Returns an event invocator.
 void removeHandler(Object handler)
          Unregisters this handler.
 void removeHandler(Object handler, Class<?> messageType)
          Unregisters given handler only to given message type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleBus

public SimpleBus()
Method Detail

addHandler

public void addHandler(Object handler)
Registers this handler. The handler is registered to all message types that given object implements. If this is not desired, use addHandler(Object, Class).

Parameters:
handler - the handler to register.

addHandler

public void addHandler(Object handler,
                       Class<?> messageType)
Registers given handler only to given message type. The handler must implement the messageType interface otherwise ClassCastException is thrown.

Parameters:
messageType - the message interface
handler - handler that implements given interface.

removeHandler

public void removeHandler(Object handler)
Unregisters this handler. The handler is unregistered from all message types that given object implements. If this is not desired, use removeHandler(Object, Class).

Parameters:
handler - the handler to unregister.

removeHandler

public void removeHandler(Object handler,
                          Class<?> messageType)
Unregisters given handler only to given message type. The handler must implement the messageType interface otherwise ClassCastException is thrown.

Parameters:
messageType - the message interface
handler - handler that implements given interface.

getInvocator

public <T> T getInvocator(Class<T> messageType,
                          boolean async)
Returns an event invocator. Any call to a method causes appropriate handlers to be invoked.

Type Parameters:
T - the interface type
Parameters:
messageType - the interface class
async - if true then the invocation is dispatched using a Handler. If false then the invocation is forced immediately. In this case, the invocator methods should be called in the handler event thread.
Returns:
invocator instance, must not be null.

clear

public void clear()
Removes all handlers and cleans up the object.



Copyright © 2007-2008. All Rights Reserved.