diff --git a/osgi.enroute.webconsole.xray.provider/src/osgi/enroute/webconsole/xray/provider/XRayWebPlugin.java b/osgi.enroute.webconsole.xray.provider/src/osgi/enroute/webconsole/xray/provider/XRayWebPlugin.java index e73d1b7..cd6f396 100644 --- a/osgi.enroute.webconsole.xray.provider/src/osgi/enroute/webconsole/xray/provider/XRayWebPlugin.java +++ b/osgi.enroute.webconsole.xray.provider/src/osgi/enroute/webconsole/xray/provider/XRayWebPlugin.java @@ -8,6 +8,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Dictionary; import java.util.Enumeration; import java.util.Formatter; @@ -89,7 +90,7 @@ public final class XRayWebPlugin extends AbstractWebConsolePlugin implements Bun private BundleContext context; private LogReaderService logReader; private LogService log; - private MultiMap listeners = new MultiMap(); + private MultiMap listenerContexts = new MultiMap(); private ServiceRegistration lhook; private volatile ServiceComponentRuntime scr; private volatile ConfigurationAdmin cfg; @@ -340,7 +341,7 @@ Result build(String[] ignoredServices) throws InvalidSyntaxException { bundles.put(bundle, data); } - for (String name : new HashSet(listeners.keySet())) { + for (String name : new HashSet(listenerContexts.keySet())) { ServiceDef icon = services.get(name); if (icon == null) { icon = new ServiceDef(); @@ -348,10 +349,12 @@ Result build(String[] ignoredServices) throws InvalidSyntaxException { icon.name = name; icon.shortName = from(TITLE_LENGTH, name); } - for (Bundle b : listeners.get(name)) + + List listeners = getListeners(name); + for (Bundle b : listeners) doClassspace(bundles, b, name, icon); - for (Iterator i = listeners.get(name).iterator(); i.hasNext();) { + for (Iterator i = listeners.iterator(); i.hasNext();) { Bundle b = i.next(); BundleDef bdef = bundles.get(b); if (bdef == null) @@ -738,12 +741,28 @@ synchronized void unsetCfg(ConfigurationAdmin cfg) { this.cfg = cfg; } + private synchronized List getListeners(String name) { + List namedContexts = listenerContexts.get(name); + List listeners; + + if (namedContexts == null) { + listeners = Collections.emptyList(); + } else { + listeners = new ArrayList(namedContexts.size()); + for (BundleContext namedContext : namedContexts) { + listeners.add(namedContext.getBundle()); + } + } + + return listeners; + } + private synchronized void addListenerInfo(ListenerInfo o) { String filter = o.getFilter(); if (filter != null) { Matcher m = LISTENER_INFO_PATTERN.matcher(filter); while (m.find()) { - listeners.add(m.group(1), o.getBundleContext().getBundle()); + listenerContexts.add(m.group(1), o.getBundleContext()); } } } @@ -753,7 +772,7 @@ private synchronized void removeListenerInfo(ListenerInfo o) { if (filter != null) { Matcher m = LISTENER_INFO_PATTERN.matcher(filter); while (m.find()) { - listeners.remove(m.group(1), o.getBundleContext().getBundle()); + listenerContexts.remove(m.group(1), o.getBundleContext()); } } }