Griffon 0.9.5-rc2

org.codehaus.griffon.runtime.core
[Java] Class EventRouter

java.lang.Object
  org.codehaus.griffon.runtime.core.EventRouter

public class EventRouter
extends Object

An event handling helper.

Listeners may be of type

With the exception of Maps and Closures, the naming convention for an eventHandler is "on" + eventName, Maps and Closures require handlers to be named as eventName only.

Some examples of eventHandler names are: onStartupStart, onMyCoolEvent. Event names must follow the camelCase naming convention.

Authors:
Andres Almiray


Field Summary
private static Object LOCK

private static org.slf4j.Logger LOG

private Map closureListeners

private static int count

private BlockingQueue deferredEvents

private boolean enabled

private List listeners

private Map scriptBindings

 
Constructor Summary
EventRouter()

 
Method Summary
void addEventListener(Object listener)

Adds an event listener.

void addEventListener(Map listener)

Adds a Map containing event listeners.

void addEventListener(String eventName, Closure listener)

Adds a Closure as an event listener.

void addEventListener(String eventName, RunnableWithArgs listener)

Adds a Runnable as an event listener.

private Object[] asArray(List list)

private Runnable buildPublisher(String event, List params, String mode)

private void fireEvent(Script script, String eventHandler, List params)

private void fireEvent(Map map, String eventHandler, List params)

private void fireEvent(Closure closure, String eventHandler, List params)

private void fireEvent(RunnableWithArgs runnable, String eventHandler, List params)

private void fireEvent(Object instance, String eventHandler, List params)

private static int identifier()

private void invokeHandler(Object handler, List params)

boolean isEnabled()

Returns the current enabled state.

private boolean isNestedListener(Object listener, Object subject)

private MetaClass metaClassOf(Object obj)

void publish(String eventName)

Publishes an event with optional arguments.

void publish(String eventName, List params)

Publishes an event with optional arguments.

void publishAsync(String eventName)

Publishes an event with optional arguments.

void publishAsync(String eventName, List params)

Publishes an event with optional arguments.

void publishOutside(String eventName)

Publishes an event with optional arguments.

void publishOutside(String eventName, List params)

Publishes an event with optional arguments.

void publishOutsideUI(String eventName)

Publishes an event with optional arguments.

void publishOutsideUI(String eventName, List params)

Publishes an event with optional arguments.

void removeEventListener(Object listener)

Removes an event listener.

void removeEventListener(Map listener)

Removes a Map containing event listeners.

void removeEventListener(String eventName, Closure listener)

Removes a Closure as an event listener.

void removeEventListener(String eventName, RunnableWithArgs listener)

Removes a Runnable as an event listener.

private void removeNestedListeners(Object subject)

void setEnabled(boolean enabled)

Sets the enabled state of this router.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

LOCK

private static final Object LOCK


LOG

private static final org.slf4j.Logger LOG


closureListeners

private final Map closureListeners


count

private static int count


deferredEvents

private final BlockingQueue deferredEvents


enabled

private boolean enabled


listeners

private final List listeners


scriptBindings

private final Map scriptBindings


 
Constructor Detail

EventRouter

public EventRouter()


 
Method Detail

addEventListener

public void addEventListener(Object listener)
Adds an event listener.

A listener may be a

With the exception of Maps, the naming convention for an eventHandler is "on" + eventName, Maps require handlers to be named as eventName only.

Some examples of eventHandler names are: onStartupStart, onMyCoolEvent. Event names must follow the camelCase naming convention.

Parameters:
listener - an event listener of type Script, Map or Object


addEventListener

public void addEventListener(Map listener)
Adds a Map containing event listeners.

An event listener may be a

Maps require handlers to be named as eventName only.

Some examples of eventHandler names are: StartupStart, MyCoolEvent. Event names must follow the camelCase naming convention.

Parameters:
listener - an event listener of type Script, Map or Object


addEventListener

public void addEventListener(String eventName, Closure listener)
Adds a Closure as an event listener.

Event names must follow the camelCase naming convention.

Parameters:
eventName - the name of the event
listener - the event listener


addEventListener

public void addEventListener(String eventName, RunnableWithArgs listener)
Adds a Runnable as an event listener.

Event names must follow the camelCase naming convention.

Parameters:
eventName - the name of the event
listener - the event listener


asArray

private Object[] asArray(List list)


buildPublisher

private Runnable buildPublisher(String event, List params, String mode)


fireEvent

private void fireEvent(Script script, String eventHandler, List params)


fireEvent

private void fireEvent(Map map, String eventHandler, List params)


fireEvent

private void fireEvent(Closure closure, String eventHandler, List params)


fireEvent

private void fireEvent(RunnableWithArgs runnable, String eventHandler, List params)


fireEvent

private void fireEvent(Object instance, String eventHandler, List params)


identifier

private static int identifier()


invokeHandler

private void invokeHandler(Object handler, List params)


isEnabled

public boolean isEnabled()
Returns the current enabled state.
Returns:
true if the router is enabled; false otherwise.


isNestedListener

private boolean isNestedListener(Object listener, Object subject)


metaClassOf

private MetaClass metaClassOf(Object obj)


publish

public void publish(String eventName)
Publishes an event with optional arguments.

Event listeners will be notified in the same thread that originated the event.
Parameters:
eventName - the name of the event


publish

public void publish(String eventName, List params)
Publishes an event with optional arguments.

Event listeners will be notified in the same thread that originated the event.
Parameters:
eventName - the name of the event
params - the event's arguments


publishAsync

public void publishAsync(String eventName)
Publishes an event with optional arguments.

Event listeners are guaranteed to be notified in a different thread than the publisher's, always.
Parameters:
eventName - the name of the event


publishAsync

public void publishAsync(String eventName, List params)
Publishes an event with optional arguments.

Event listeners are guaranteed to be notified in a different thread than the publisher's, always.
Parameters:
eventName - the name of the event
params - the event's arguments


publishOutside

@Deprecated
public void publishOutside(String eventName)
Publishes an event with optional arguments.

Event listeners are guaranteed to be notified outside of the UI thread always.
deprecated:
use #eventOutsideUI() instead
Parameters:
eventName - the name of the event


publishOutside

@Deprecated
public void publishOutside(String eventName, List params)
Publishes an event with optional arguments.

Event listeners are guaranteed to be notified outside of the UI thread always.
deprecated:
use #eventOutsideUI() instead
Parameters:
eventName - the name of the event
params - the event's arguments


publishOutsideUI

public void publishOutsideUI(String eventName)
Publishes an event with optional arguments.

Event listeners are guaranteed to be notified outside of the UI thread always.
Parameters:
eventName - the name of the event


publishOutsideUI

public void publishOutsideUI(String eventName, List params)
Publishes an event with optional arguments.

Event listeners are guaranteed to be notified outside of the UI thread always.
Parameters:
eventName - the name of the event
params - the event's arguments


removeEventListener

public void removeEventListener(Object listener)
Removes an event listener.

A listener may be a

With the exception of Maps, the naming convention for an eventHandler is "on" + eventName, Maps require handlers to be named as eventName only.

Some examples of eventHandler names are: onStartupStart, onMyCoolEvent. Event names must follow the camelCase naming convention.

Parameters:
listener - an event listener of type Script, Map or Object


removeEventListener

public void removeEventListener(Map listener)
Removes a Map containing event listeners.

An event listener may be a

Maps require handlers to be named as eventName only.

Some examples of eventHandler names are: StartupStart, MyCoolEvent. Event names must follow the camelCase naming convention.

Parameters:
listener - an event listener of type Script, Map or Object


removeEventListener

public void removeEventListener(String eventName, Closure listener)
Removes a Closure as an event listener.

Event names must follow the camelCase naming convention.

Parameters:
eventName - the name of the event
listener - the event listener


removeEventListener

public void removeEventListener(String eventName, RunnableWithArgs listener)
Removes a Runnable as an event listener.

Event names must follow the camelCase naming convention.

Parameters:
eventName - the name of the event
listener - the event listener


removeNestedListeners

private void removeNestedListeners(Object subject)


setEnabled

public void setEnabled(boolean enabled)
Sets the enabled state of this router.

A disabled router will simply discard all events that are sent to it, in other words listeners will never be notified. Discarded events cannot be recovered, even if the router is enabled at a later point in time.
Parameters:
enabled - the value for the enabled state


 

Groovy Documentation