|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--net.larsan.urd.util.EventInvoker
An event invocation handler is a generic broadcatser for events to use with a java.lang.reflect.Proxy.
An invocation handler does not check any validity on listener registration but will report errors using an error
handler during runtime.
This class should be used as a proxy for the listeners. The using code can get hold of the event invoker
through the proxys getInvocationHandler method like so:
Proxy prox = (Proxy)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { listenerClass }, new EventInvoker());
EventInvoker inv = (EventInvoker)prx.getInvocationHandler(prox);
This class will try to route incoming events to all it's listeners, should this behaviour need changing
a subclass can override the empty acceptBroadcast method to filter wich listeners to target.
This class is synchronized so that listener add/remove does not interfere with ongoing broadcasting.
| Constructor Summary | |
EventInvoker()
Create invocation handler. |
|
EventInvoker(int size)
Create invocation handler with a initial size. |
|
| Method Summary | |
void |
addListener(java.lang.Object listener)
Add a listener to this event broadcaster. |
void |
clear()
Clear this handler of all listeners. |
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
Handle fired event, this broadcasts the event to all listeners. |
void |
removeListener(java.lang.Object listener)
Remove a listerer from this broadcaster. |
void |
setErrorHandler(ErrorHandler handler)
Set the error handler. |
int |
size()
Get the current number of listeners registered with this invoker |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public EventInvoker(int size)
size - Initial size of listener collectionpublic EventInvoker()
| Method Detail |
public void addListener(java.lang.Object listener)
equals method.
listener - listener object to addpublic void removeListener(java.lang.Object listener)
equals mthoed
returns true used with the parameter.
listener - listener to removepublic int size()
public void clear()
public void setErrorHandler(ErrorHandler handler)
handler - Error handler for this broadcaster
public java.lang.Object invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
invoke in interface java.lang.reflect.InvocationHandlerproxy - Proxy which the event invocation originated onmethod - Event method that was calledargs - Event method parameter array
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||