diff options
author | Markus Alexander Kuppe | 2013-10-19 07:45:00 +0000 |
---|---|---|
committer | Markus Alexander Kuppe | 2013-10-19 07:45:00 +0000 |
commit | 010397b3629a85856aa61511a21786c034653a03 (patch) | |
tree | 48516b0642611375b00d146f7cfc368fca0181fe /protocols | |
parent | 4b8ab7f62c3e1371b022994294abd3a5ac158221 (diff) | |
download | org.eclipse.ecf-010397b3629a85856aa61511a21786c034653a03.tar.gz org.eclipse.ecf-010397b3629a85856aa61511a21786c034653a03.tar.xz org.eclipse.ecf-010397b3629a85856aa61511a21786c034653a03.zip |
NEW - bug 419327: [R_OSGi] Event Admin problems
https://bugs.eclipse.org/bugs/show_bug.cgi?id=419327
Diffstat (limited to 'protocols')
2 files changed, 77 insertions, 6 deletions
diff --git a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.java b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.java index 5ce16b804..ae082d3bb 100644 --- a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.java +++ b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.java @@ -82,6 +82,7 @@ import ch.ethz.iks.r_osgi.channels.NetworkChannelFactory; import ch.ethz.iks.r_osgi.messages.LeaseUpdateMessage; import ch.ethz.iks.r_osgi.service_discovery.ServiceDiscoveryHandler; import ch.ethz.iks.util.CollectionUtils; +import ch.ethz.iks.util.StringUtils; /** * <p> @@ -270,6 +271,11 @@ final class RemoteOSGiServiceImpl implements RemoteOSGiService, Remoting { * Channel ID --> ChannelEndpointMultiplexer */ private static Map multiplexers = new HashMap(0); + + /** + * Event topics this instance is going to ignore and not remote + */ + private static final Set topicFilters = new HashSet(0); /** * The package admin @@ -283,6 +289,17 @@ final class RemoteOSGiServiceImpl implements RemoteOSGiService, Remoting { * in case of IO problems. */ RemoteOSGiServiceImpl() throws IOException { + // [R_OSGi] Event Admin problems + // https://bugs.eclipse.org/419327 + final String topics = System.getProperty("ch.ethz.iks.r_osgi.topic.filter", ""); + final String[] strings = StringUtils.stringToArray(topics, ","); + for (int i = 0; i < strings.length; i++) { + topicFilters.add(strings[i]); + } + // [TCK][r-OSGi] NonSerializableException when running remoteserviceadmin ct + // https://bugs.eclipse.org/418740 + topicFilters.add("org/osgi/service/remoteserviceadmin/*"); + // find out own IP address try { MY_ADDRESS = InetAddress.getAllByName(InetAddress.getLocalHost() @@ -374,21 +391,27 @@ final class RemoteOSGiServiceImpl implements RemoteOSGiService, Remoting { final ServiceReference reference) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=326033 - final String[] theTopics; + Collection theTopics; Object topic = reference .getProperty(EventConstants.EVENT_TOPIC); if (topic instanceof String) - theTopics = new String[] { (String) topic }; + theTopics = Arrays + .asList(new String[] { (String) topic }); else - theTopics = (String[]) topic; + theTopics = Arrays.asList((String[]) topic); + + // Remove filtered topics + theTopics = StringUtils.rightDifference( + topicFilters, theTopics); + final LeaseUpdateMessage lu = new LeaseUpdateMessage(); lu.setType(LeaseUpdateMessage.TOPIC_UPDATE); lu.setServiceID(""); //$NON-NLS-1$ lu.setPayload(new Object[] { theTopics, null }); updateLeases(lu); - return Arrays.asList(theTopics); + return theTopics; } public void modifiedService( @@ -398,7 +421,7 @@ final class RemoteOSGiServiceImpl implements RemoteOSGiService, Remoting { final List oldTopicList = (List) oldTopics; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=326033 - final List newTopicList; + Collection newTopicList; Object topic = reference .getProperty(EventConstants.EVENT_TOPIC); if (topic instanceof String) @@ -406,6 +429,10 @@ final class RemoteOSGiServiceImpl implements RemoteOSGiService, Remoting { .asList(new String[] { (String) topic }); else newTopicList = Arrays.asList((String[]) topic); + + // Remove filtered topics + newTopicList = StringUtils.rightDifference( + topicFilters, newTopicList); final Collection removed = CollectionUtils .rightDifference(newTopicList, oldTopicList); @@ -1009,12 +1036,13 @@ final class RemoteOSGiServiceImpl implements RemoteOSGiService, Remoting { */ static String[] getTopics() { final Object[] topicLists = eventHandlerTracker.getServices(); - final List topics = new ArrayList(); + List topics = new ArrayList(); if (topicLists != null) { for (int i = 0; i < topicLists.length; i++) { topics.addAll((List) topicLists[i]); } } +// topics = (List) FilterUtils.rightDifference(topicFilters, topics); return (String[]) topics.toArray(new String[topics.size()]); } diff --git a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java index 214426d10..79f6bcec2 100644 --- a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java +++ b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java @@ -28,6 +28,10 @@ */ package ch.ethz.iks.util; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; import java.util.StringTokenizer; /** @@ -64,4 +68,43 @@ public final class StringUtils { return tokens; } + + /** + * R \ L (comparison operation allows wildcards) + * @param left A set of matchers (supports wildcard at end) + * @param right A set of inputs + * @return The subset of right with all elements removed matching left + * @since 1.0 + */ + public static Collection rightDifference(Collection left, Collection right) { + // This is O(n²) due to substring (wildcard) matching + // It's also quick and dirty (better use pattern matcher instead) + // TODO use pattern matcher + // (pattern matcher would increase the BREE dependency, but we could hide + // the FilterUtils implementation behind an interface and provide different + // service implementations) + // A trie would also allow for faster lookup. + + + // Have to convert c1 into List to support remove operation + final List result = new ArrayList(right); + + for (Iterator iterator = right.iterator(); iterator.hasNext();) { + final String f1 = (String) iterator.next(); + for (Iterator itr2 = left.iterator(); itr2.hasNext();) { + String f2 = (String) itr2.next(); + if (f2.endsWith("*")) { + f2 = f2.substring(0, f2.length() - 1); + if (f1.startsWith(f2)) { + result.remove(f1); + } + } else { + if (f1.equals(f2)) { + result.remove(f1); + } + } + } + } + return result; + } } |