/** * Removes an {@link EventListenerProxy} from this object. * This is used by subclasses that wish to map between java style event listeners * and gstreamer signals. * * @param listenerClass The class of listener the proxy was added for. * @param listener The listener the proxy was added for. * @return The proxy that was removed, or null if no proxy was found. */ protected synchronized EventListenerProxy removeListenerProxy(Class<? extends EventListener> listenerClass, EventListener listener) { Map<EventListener, EventListenerProxy> map = getListenerMap().get(listenerClass); if (map == null) { return null; } EventListenerProxy proxy = map.remove(listener); /* * Reclaim memory if this listener class is no longer used */ if (map.isEmpty()) { listenerMap.remove(listenerClass); if (listenerMap.isEmpty()) { listenerMap = null; } } return proxy; }
/** * Adds an {@link EventListenerProxy} on this object. * This is used by subclasses that wish to map between java style event listeners * and gstreamer signals. * * @param listenerClass Class of the listener being added. * @param listener The listener being added. * @param proxy Proxy for the event listener. */ protected synchronized void addListenerProxy(Class<? extends EventListener> listenerClass, EventListener listener, EventListenerProxy proxy) { Map<EventListener, EventListenerProxy> map = getListenerMap().get(listenerClass); /* * Create the map for this class if it doesn't exist */ if (map == null) { map = new HashMap<EventListener, EventListenerProxy>(); getListenerMap().put(listenerClass, map); } map.put(listener, proxy); }
@TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getListener", args = {} ) public void testGetListener() { EventListener el = new Mock_EventListener(); EventListenerProxy elp = new Mock_EventListenerProxy(el); assertSame(el, elp.getListener()); }
/** * Extracts a real listener from the proxy listener. * It is necessary because default proxy class is not serializable. * * @return a real listener */ public final L extract(L listener) { while (listener instanceof EventListenerProxy) { EventListenerProxy<L> proxy = (EventListenerProxy<L>) listener; listener = proxy.getListener(); } return listener; }
private Map<Class<? extends EventListener>, Map<EventListener, EventListenerProxy>> getListenerMap() { if (listenerMap == null) { listenerMap = new HashMap<Class<? extends EventListener>, Map<EventListener, EventListenerProxy>>(); } return listenerMap; }