Skip to content

Commit

Permalink
Fix for osgi#76
Browse files Browse the repository at this point in the history
Maintain a mapping to BundleContexts instead of Bundles to avoid the
issue of them becoming invalid.

Signed-off-by: Elias N Vasylenko <[email protected]>
  • Loading branch information
Sophos-Elias-Vasylenko committed Jan 5, 2017
1 parent ffca230 commit 9f6ed3a
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,7 +90,7 @@ public final class XRayWebPlugin extends AbstractWebConsolePlugin implements Bun
private BundleContext context;
private LogReaderService logReader;
private LogService log;
private MultiMap<String, Bundle> listeners = new MultiMap<String, Bundle>();
private MultiMap<String, BundleContext> listenerContexts = new MultiMap<String, BundleContext>();
private ServiceRegistration<ListenerHook> lhook;
private volatile ServiceComponentRuntime scr;
private volatile ConfigurationAdmin cfg;
Expand Down Expand Up @@ -340,18 +341,20 @@ Result build(String[] ignoredServices) throws InvalidSyntaxException {
bundles.put(bundle, data);
}

for (String name : new HashSet<String>(listeners.keySet())) {
for (String name : new HashSet<String>(listenerContexts.keySet())) {
ServiceDef icon = services.get(name);
if (icon == null) {
icon = new ServiceDef();
services.put(name, icon);
icon.name = name;
icon.shortName = from(TITLE_LENGTH, name);
}
for (Bundle b : listeners.get(name))

List<Bundle> listeners = getListeners(name);
for (Bundle b : listeners)
doClassspace(bundles, b, name, icon);

for (Iterator<Bundle> i = listeners.get(name).iterator(); i.hasNext();) {
for (Iterator<Bundle> i = listeners.iterator(); i.hasNext();) {
Bundle b = i.next();
BundleDef bdef = bundles.get(b);
if (bdef == null)
Expand Down Expand Up @@ -738,12 +741,28 @@ synchronized void unsetCfg(ConfigurationAdmin cfg) {
this.cfg = cfg;
}

private synchronized List<Bundle> getListeners(String name) {
List<BundleContext> namedContexts = listenerContexts.get(name);
List<Bundle> listeners;

if (namedContexts == null) {
listeners = Collections.emptyList();
} else {
listeners = new ArrayList<Bundle>(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());
}
}
}
Expand All @@ -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());
}
}
}
Expand Down

0 comments on commit 9f6ed3a

Please sign in to comment.