Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2015-04-13 19:23:09 -0400
committerslewis2015-04-13 19:23:09 -0400
commit55907064e2a5bb48c32ccbadef43dd072e4e8f9f (patch)
tree9f59b6f9e417400c173af758d875e80fa11383e8
parentc4df2a7446a9eb860a0e2e1bcd9db7305037c59a (diff)
downloadorg.eclipse.ecf-55907064e2a5bb48c32ccbadef43dd072e4e8f9f.tar.gz
org.eclipse.ecf-55907064e2a5bb48c32ccbadef43dd072e4e8f9f.tar.xz
org.eclipse.ecf-55907064e2a5bb48c32ccbadef43dd072e4e8f9f.zip
Enhancement for EndpointDescriptionLocator see bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=464454 Change-Id: I0000000000000000000000000000000000000000
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java127
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionLocator.java9
2 files changed, 88 insertions, 48 deletions
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
index e06d1e00b..3a4d424b3 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
@@ -32,12 +32,14 @@ import java.util.TreeMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
import org.eclipse.ecf.discovery.IDiscoveryLocator;
import org.eclipse.ecf.discovery.IServiceEvent;
import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.IServiceListener;
import org.eclipse.ecf.discovery.identity.IServiceID;
+import org.eclipse.ecf.discovery.identity.IServiceTypeID;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.Activator;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.DebugOptions;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.LogUtility;
@@ -459,7 +461,9 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
advertiserTracker = null;
}
}
- edServiceIDMap.clear();
+ synchronized (edToServiceIDMap) {
+ edToServiceIDMap.clear();
+ }
this.executor = null;
this.context = null;
@@ -1106,62 +1110,88 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
}
}
- private Map<EndpointDescription, Set<IServiceID>> edServiceIDMap = new HashMap<EndpointDescription, Set<IServiceID>>();
+ private Map<EndpointDescription, IServiceID> edToServiceIDMap = new HashMap<EndpointDescription, IServiceID>();
- class LocatorServiceListener implements IServiceListener {
+ Set<EndpointDescription> getEDs() {
+ synchronized (edToServiceIDMap) {
+ return edToServiceIDMap.keySet();
+ }
+ }
- private IDiscoveryLocator locator;
+ EndpointDescription findED(IServiceID serviceID) {
+ synchronized (edToServiceIDMap) {
+ for (EndpointDescription ed : getEDs()) {
+ IServiceID sid = edToServiceIDMap.get(ed);
+ if (sid != null
+ && sid.getLocation().equals(serviceID.getLocation()))
+ return ed;
+ }
+ }
+ return null;
+ }
- public LocatorServiceListener(IDiscoveryLocator locator) {
- this.locator = locator;
- if (locator != null)
- this.locator.addServiceListener(this);
+ void updateED(EndpointDescription existing, EndpointDescription update,
+ IServiceID updateServiceID) {
+ synchronized (edToServiceIDMap) {
+ edToServiceIDMap.remove(existing);
+ edToServiceIDMap.put(update, updateServiceID);
}
+ }
- private Set<EndpointDescription> getEndpointDescriptions() {
- return edServiceIDMap.keySet();
+ void addED(org.osgi.service.remoteserviceadmin.EndpointDescription ed,
+ IServiceID serviceID) {
+ synchronized (edToServiceIDMap) {
+ edToServiceIDMap.put(ed, serviceID);
}
+ }
- private EndpointDescription findEDFromServiceID(IServiceID serviceID) {
- for (EndpointDescription ed : getEndpointDescriptions()) {
- Set<IServiceID> serviceIDs = edServiceIDMap.get(ed);
- if (serviceIDs == null)
- continue;
- for (IServiceID sid : serviceIDs) {
- if (sid.getLocation().equals(serviceID.getLocation()))
- return ed;
- }
- }
- return null;
+ void removeED(org.osgi.service.remoteserviceadmin.EndpointDescription ed) {
+ synchronized (edToServiceIDMap) {
+ edToServiceIDMap.remove(ed);
}
+ }
- private boolean containsED(EndpointDescription ed) {
- return edServiceIDMap.keySet().contains(ed);
+ boolean containsED(EndpointDescription ed) {
+ synchronized (edToServiceIDMap) {
+ return getEDs().contains(ed);
}
+ }
- private void updateEDServiceID(EndpointDescription existing,
- EndpointDescription update, IServiceID updateServiceID) {
- Set<IServiceID> serviceIDs = edServiceIDMap.remove(existing);
- if (serviceIDs == null)
- serviceIDs = new HashSet<IServiceID>();
- serviceIDs.add(updateServiceID);
- edServiceIDMap.put(update, serviceIDs);
+ Set<EndpointDescription> getEDsForNamespace(Namespace namespace) {
+ Set<EndpointDescription> results = new HashSet<EndpointDescription>();
+ synchronized (edToServiceIDMap) {
+ for (EndpointDescription ed : edToServiceIDMap.keySet()) {
+ IServiceID svcID = edToServiceIDMap.get(ed);
+ if (svcID.getNamespace().getName().equals(namespace.getName()))
+ results.add(ed);
+ }
+ }
+ return results;
+ }
+
+ /**
+ * @since 4.3
+ */
+ public IServiceID getNetworkDiscoveredService(
+ org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription endpointDescription) {
+ synchronized (edToServiceIDMap) {
+ return edToServiceIDMap.get(endpointDescription);
}
+ }
+
+ class LocatorServiceListener implements IServiceListener {
+
+ private IDiscoveryLocator locator;
- private void addEDServiceID(
- org.osgi.service.remoteserviceadmin.EndpointDescription ed,
- IServiceID serviceID) {
- Set<IServiceID> serviceIDs = edServiceIDMap.get(ed);
- if (serviceIDs == null)
- serviceIDs = new HashSet<IServiceID>();
- serviceIDs.add(serviceID);
- edServiceIDMap.put(ed, serviceIDs);
+ public LocatorServiceListener(IDiscoveryLocator locator) {
+ this.locator = locator;
+ if (locator != null)
+ this.locator.addServiceListener(this);
}
- private void removeEDServiceID(
- org.osgi.service.remoteserviceadmin.EndpointDescription ed,
- IServiceID serviceID) {
- edServiceIDMap.remove(ed);
+ Collection<EndpointDescription> getEndpointDescriptions() {
+ return (this.locator == null) ? Collections.EMPTY_SET
+ : getEDsForNamespace(this.locator.getServicesNamespace());
}
public void serviceDiscovered(IServiceEvent anEvent) {
@@ -1181,10 +1211,10 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
// Make sure this is an OSGi Remote Service
if (Arrays.asList(serviceID.getServiceTypeID().getServices())
.contains(RemoteConstants.DISCOVERY_SERVICE_TYPE)) {
- synchronized (edServiceIDMap) {
+ synchronized (edToServiceIDMap) {
// Try to find ED from ServiceID, whether discovered or
// undiscovered
- org.osgi.service.remoteserviceadmin.EndpointDescription ed = findEDFromServiceID(serviceID);
+ org.osgi.service.remoteserviceadmin.EndpointDescription ed = findED(serviceID);
if (discovered) {
// The IServiceInfo was discovered/added
if (ed == null) {
@@ -1202,7 +1232,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
ed, serviceID);
if (prevEd == null) {
if (!containsED(ed)) {
- addEDServiceID(ed, serviceID);
+ addED(ed, serviceID);
handleEndpointDescription(ed, true);
} else
trace("handleEndpointDescription", "endpointDescription previously discovered...ignoring"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -1221,7 +1251,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
} else {
// It was undiscovered
if (ed != null) {
- removeEDServiceID(ed, serviceID);
+ removeED(ed);
handleEndpointDescription(ed, false);
} else
trace("handleService", "Did not find serviceInfo with serviceID=" + serviceID + ". Ignoring"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -1260,7 +1290,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
}
}
if (update) {
- updateEDServiceID(ped, ed, updateServiceID);
+ updateED(ped, ed, updateServiceID);
return ed;
}
}
@@ -1295,7 +1325,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
update = true;
}
if (update) {
- updateEDServiceID(ped, endpointDescription,
+ updateED(ped, endpointDescription,
updateServiceID);
return endpointDescription;
}
@@ -1382,4 +1412,5 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription endpointDescription) {
queueEndpointEvent(endpointDescription, EndpointEvent.REMOVED);
}
+
}
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionLocator.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionLocator.java
index 8090bb616..f9fbc304c 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionLocator.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionLocator.java
@@ -1,11 +1,20 @@
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+import org.eclipse.ecf.discovery.identity.IServiceID;
+
/**
* @since 4.3
*/
public interface IEndpointDescriptionLocator {
/**
+ * Get the service ID associated with the
+ * @param endpointDescription
+ * @return
+ */
+ IServiceID getNetworkDiscoveredService(EndpointDescription endpointDescription);
+
+ /**
* Discover the given endpointDescription. This method will not block
* and will result in local EndpointEventListeners to be notified that the
* given endpointDescription is discovered.

Back to the top