|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ref.Reference<T>
java.lang.ref.WeakReference
dsto.dfc.util.WeakEventListener
public class WeakEventListener
A 'weak' event listener proxy that does not preclude garbage collection of the listener. Similar in concept to a weak reference, this class acts as a proxy to a contained listener. The contained listener is held with a weak reference, allowing it to be garbage collected if the listener registration is the only thing pointing to it.
This can be especially useful when transient classes (such as commands) need to listen to global or static classes.
Example - add a property change listener to a bean:
WeakEventListener.createListener (PropertyChangeListener.class, bean, listener);
Beans.addListener(java.lang.Class, java.lang.Object, java.lang.Object)
Field Summary | |
---|---|
protected static dsto.dfc.util.WeakEventListener.CleanupThread |
cleanupThread
Cleans up GC's WeakEventListener's. |
protected Class |
listenerInterface
The event listener interface (eg PropertyChangeListener). |
protected Object |
proxy
|
protected Object |
source
The thing being listened to. |
Constructor Summary | |
---|---|
WeakEventListener(Class listenerInterface,
Object source,
Object listener)
Create a proxy weak event listener. |
Method Summary | |
---|---|
static WeakEventListener |
createListener(Class listenerInterface,
Object source,
Object listener)
Shortcut to automatically create a WeakEventListener instance and register its proxy with the event source. |
protected Object |
createProxy()
|
void |
dispose()
Manually dispose the obvject and remove the proxy listener. |
protected static dsto.dfc.util.WeakEventListener.CleanupThread |
getCleanupThread()
Get or create the cleanup thread instance. |
Object |
getProxy()
The actual proxy created to receive calls to the listener interface. |
Object |
invoke(Object proxyInstance,
Method method,
Object[] args)
|
Methods inherited from class java.lang.ref.Reference |
---|
clear, enqueue, get, isEnqueued |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static dsto.dfc.util.WeakEventListener.CleanupThread cleanupThread
protected Object source
protected Class listenerInterface
protected Object proxy
Constructor Detail |
---|
public WeakEventListener(Class listenerInterface, Object source, Object listener)
getProxy()
to
retrieve the actual proxy instance of listenerInterface. Most clients
will use createListener(java.lang.Class, java.lang.Object, java.lang.Object)
instead to automatically create a
WeakEventListener instance and register its proxy with the event
source.
listenerInterface
- The event listener interface (eg
PropertyChangeListener).source
- The event source (ie the thing being listened to).listener
- The actual listener instance (must implement the
listener interface).Method Detail |
---|
protected Object createProxy()
public void dispose()
public static WeakEventListener createListener(Class listenerInterface, Object source, Object listener)
listenerInterface
- The event listener interface (eg
PropertyChangeListener).source
- The event source (ie the thing being listened to).listener
- The actual listener instance (must implement the
listener interface).
public Object getProxy()
protected static dsto.dfc.util.WeakEventListener.CleanupThread getCleanupThread()
public Object invoke(Object proxyInstance, Method method, Object[] args) throws Throwable
invoke
in interface InvocationHandler
Throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |