Author: jm
Date: 2012-04-11 12:02:57 -0700 (Wed, 11 Apr 2012)
New Revision: 28795
Modified:
core3/impl/trunk/event-impl/impl/src/main/java/org/cytoscape/event/internal/CyEventHelperImpl.java
core3/impl/trunk/event-impl/impl/src/main/java/org/cytoscape/event/internal/CyListenerAdapter.java
Log:
Fixes #616: Silenced sources are now stored in a WeakHashMap so they get
cleaned up automatically
Modified:
core3/impl/trunk/event-impl/impl/src/main/java/org/cytoscape/event/internal/CyEventHelperImpl.java
===================================================================
---
core3/impl/trunk/event-impl/impl/src/main/java/org/cytoscape/event/internal/CyEventHelperImpl.java
2012-04-11 18:20:53 UTC (rev 28794)
+++
core3/impl/trunk/event-impl/impl/src/main/java/org/cytoscape/event/internal/CyEventHelperImpl.java
2012-04-11 19:02:57 UTC (rev 28795)
@@ -39,11 +39,10 @@
import org.cytoscape.event.CyEventHelper;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
+import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -55,17 +54,19 @@
private static final Logger logger =
LoggerFactory.getLogger(CyEventHelperImpl.class);
+ private static final Object DUMMY = new Object();
+
private final CyListenerAdapter normal;
private final Map<Object,Map<Class<?>,PayloadAccumulator<?,?,?>>>
sourceAccMap;
private final ScheduledExecutorService payloadEventMonitor;
- private final Set<Object> silencedSources;
+ private final Map<Object, Object> silencedSources;
private boolean havePayload;
-
+
public CyEventHelperImpl(final CyListenerAdapter normal) {
this.normal = normal;
sourceAccMap = new
LinkedHashMap<Object,Map<Class<?>,PayloadAccumulator<?,?,?>>>();
payloadEventMonitor =
Executors.newSingleThreadScheduledExecutor();
- silencedSources = new HashSet<Object>();
+ silencedSources = new WeakHashMap<Object, Object>();
havePayload = false;
// This thread just flushes any accumulated payload events.
@@ -95,7 +96,7 @@
return;
logger.info("silencing event source: " +
eventSource.toString());
normal.silenceEventSource(eventSource);
- silencedSources.add(eventSource);
+ silencedSources.put(eventSource, DUMMY);
}
@Override
@@ -116,7 +117,7 @@
return;
}
- if ( silencedSources.contains(source))
+ if ( silencedSources.containsKey(source))
return;
synchronized (this) {
Modified:
core3/impl/trunk/event-impl/impl/src/main/java/org/cytoscape/event/internal/CyListenerAdapter.java
===================================================================
---
core3/impl/trunk/event-impl/impl/src/main/java/org/cytoscape/event/internal/CyListenerAdapter.java
2012-04-11 18:20:53 UTC (rev 28794)
+++
core3/impl/trunk/event-impl/impl/src/main/java/org/cytoscape/event/internal/CyListenerAdapter.java
2012-04-11 19:02:57 UTC (rev 28795)
@@ -31,12 +31,9 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import java.util.Arrays;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
+import java.util.WeakHashMap;
import org.cytoscape.event.CyEvent;
import org.osgi.framework.BundleContext;
@@ -52,9 +49,11 @@
private static final Logger logger =
LoggerFactory.getLogger(CyListenerAdapter.class);
private static final ServiceComparator serviceComparator = new
ServiceComparator();
+ private static final Object DUMMY = new Object();
+
private final Map<Class<?>,ServiceTracker> serviceTrackers;
private final BundleContext bc;
- private final Set<Object> silencedSources;
+ private final Map<Object, Object> silencedSources;
private final StringBuilder traceString;
private final boolean printEventTrace;
private int fireCount;
@@ -67,7 +66,7 @@
public CyListenerAdapter(BundleContext bc) {
this.bc = bc;
serviceTrackers = new HashMap<Class<?>,ServiceTracker>();
- silencedSources = new HashSet<Object>();
+ silencedSources = new WeakHashMap<Object, Object>();
// used only for printing a coherent event trace
fireCount = 0;
@@ -86,7 +85,7 @@
if ( event == null )
return;
- if ( silencedSources.contains( event.getSource() ) )
+ if ( silencedSources.containsKey( event.getSource() ) )
return;
final Class<?> listenerClass = event.getListenerClass();
@@ -161,7 +160,7 @@
}
void silenceEventSource(Object eventSource) {
- silencedSources.add(eventSource);
+ silencedSources.put(eventSource, DUMMY);
}
void unsilenceEventSource(Object eventSource) {
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.