Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/osgi
diff options
context:
space:
mode:
authorslewis2015-04-14 03:16:34 +0000
committerslewis2015-04-14 03:16:34 +0000
commitf7495e3b942387c7cef8c91bfad73da6e4bb18a6 (patch)
treefac3f65d6ee6ef94af013433b3ddfba6674db258 /osgi
parent3e1408d2ce5958a8645bba6cfe7f94538c81f2ba (diff)
downloadorg.eclipse.ecf-f7495e3b942387c7cef8c91bfad73da6e4bb18a6.tar.gz
org.eclipse.ecf-f7495e3b942387c7cef8c91bfad73da6e4bb18a6.tar.xz
org.eclipse.ecf-f7495e3b942387c7cef8c91bfad73da6e4bb18a6.zip
Enhancement for EndpointDescriptionLocator see bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=464454 Change-Id: I0000000000000000000000000000000000000000
Diffstat (limited to 'osgi')
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java96
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionLocator.java9
2 files changed, 55 insertions, 50 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 3a4d424b3..4e10a2bee 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
@@ -95,7 +95,6 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
// For processing synchronous notifications asynchronously
private EventManager eventManager;
private ListenerQueue eventQueue;
- private LocatorServiceListener localLocatorServiceListener;
// ECF IDiscoveryLocator tracker
private ServiceTracker locatorServiceTracker;
@@ -255,7 +254,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
.getService(reference);
if (listener == null)
return null;
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> allDiscoveredEndpointDescriptions = getAllDiscoveredEndpointDescriptions();
+ Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> allDiscoveredEndpointDescriptions = getEDs();
for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : allDiscoveredEndpointDescriptions) {
EndpointDescriptionLocator.EndpointListenerHolder[] endpointListenerHolders = getMatchingEndpointListenerHolders(
new ServiceReference[] { reference }, ed);
@@ -299,7 +298,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
.getService(reference);
if (listener == null)
return null;
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> allDiscoveredEndpointDescriptions = getAllDiscoveredEndpointDescriptions();
+ Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> allDiscoveredEndpointDescriptions = getEDs();
for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : allDiscoveredEndpointDescriptions) {
EndpointDescriptionLocator.EndpointEventListenerHolder[] endpointEventListenerHolders = getMatchingEndpointEventListenerHolders(
new ServiceReference[] { reference }, ed,
@@ -333,7 +332,6 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
endpointEventListenerTracker.open();
locatorListeners = new HashMap();
- localLocatorServiceListener = new LocatorServiceListener(null);
// Create locator service tracker, so new IDiscoveryLocators can
// be used to discover endpoint descriptions
locatorServiceTracker = new ServiceTracker(context,
@@ -347,8 +345,9 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
| Bundle.STARTING, bundleTrackerCustomizer);
// This may trigger local endpoint description discovery
bundleTracker.open();
-
- this.endpointLocatorReg = this.context.registerService(IEndpointDescriptionLocator.class, this, null);
+
+ this.endpointLocatorReg = this.context.registerService(
+ IEndpointDescriptionLocator.class, this, null);
}
private void logError(String methodName, String message, Throwable e) {
@@ -397,11 +396,6 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
}
}
- if (localLocatorServiceListener != null) {
- localLocatorServiceListener.close();
- localLocatorServiceListener = null;
- }
-
if (endpointListenerTracker != null) {
endpointListenerTracker.close();
endpointListenerTracker = null;
@@ -545,22 +539,6 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
}
}
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> getAllDiscoveredEndpointDescriptions() {
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> result = new ArrayList();
- if (localLocatorServiceListener == null)
- return result;
- // Get local first
- result.addAll(localLocatorServiceListener.getEndpointDescriptions());
- synchronized (locatorListeners) {
- for (IDiscoveryLocator l : locatorListeners.keySet()) {
- LocatorServiceListener locatorListener = locatorListeners
- .get(l);
- result.addAll(locatorListener.getEndpointDescriptions());
- }
- }
- return result;
- }
-
void queueEndpointEvent(
org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
int type) {
@@ -1040,9 +1018,10 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
if (endpointDescriptions.size() > 0) {
bundleDescriptionMap.put(new Long(bundle.getBundleId()),
endpointDescriptions);
- for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : endpointDescriptions)
- localLocatorServiceListener.handleEndpointDescription(ed,
- true);
+ for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : endpointDescriptions) {
+ addED(ed, null);
+ handleEndpointDescription(ed, true);
+ }
}
}
@@ -1094,9 +1073,10 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> endpointDescriptions = bundleDescriptionMap
.remove(new Long(bundle.getBundleId()));
if (endpointDescriptions != null)
- for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : endpointDescriptions)
- localLocatorServiceListener.handleEndpointDescription(ed,
- false);
+ for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : endpointDescriptions) {
+ removeED(ed);
+ handleEndpointDescription(ed, false);
+ }
}
public void close() {
@@ -1162,7 +1142,9 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
synchronized (edToServiceIDMap) {
for (EndpointDescription ed : edToServiceIDMap.keySet()) {
IServiceID svcID = edToServiceIDMap.get(ed);
- if (svcID.getNamespace().getName().equals(namespace.getName()))
+ if (svcID != null
+ && svcID.getNamespace().getName()
+ .equals(namespace.getName()))
results.add(ed);
}
}
@@ -1172,13 +1154,24 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
/**
* @since 4.3
*/
- public IServiceID getNetworkDiscoveredService(
+ public IServiceID getNetworkDiscoveredServiceID(
org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription endpointDescription) {
synchronized (edToServiceIDMap) {
return edToServiceIDMap.get(endpointDescription);
}
}
+ void handleEndpointDescription(EndpointDescription endpointDescription,
+ boolean discovered) {
+ if (discovered) {
+ queueEndpointEvent(endpointDescription, EndpointEvent.ADDED);
+ queueEndpointDescription(endpointDescription, discovered);
+ } else {
+ queueEndpointEvent(endpointDescription, EndpointEvent.REMOVED);
+ queueEndpointDescription(endpointDescription, discovered);
+ }
+ }
+
class LocatorServiceListener implements IServiceListener {
private IDiscoveryLocator locator;
@@ -1206,7 +1199,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
if (locator == null)
return;
trace("handleService", "fwk=" + getFrameworkUUID() + " serviceInfo=" + serviceInfo //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + ", discovered=" + discovered+", locator="+locator); //$NON-NLS-1$ //$NON-NLS-2$
+ + ", discovered=" + discovered + ", locator=" + locator); //$NON-NLS-1$ //$NON-NLS-2$
IServiceID serviceID = serviceInfo.getServiceID();
// Make sure this is an OSGi Remote Service
if (Arrays.asList(serviceID.getServiceTypeID().getServices())
@@ -1325,8 +1318,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
update = true;
}
if (update) {
- updateED(ped, endpointDescription,
- updateServiceID);
+ updateED(ped, endpointDescription, updateServiceID);
return endpointDescription;
}
}
@@ -1334,17 +1326,6 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
return null;
}
- void handleEndpointDescription(EndpointDescription endpointDescription,
- boolean discovered) {
- if (discovered) {
- queueEndpointEvent(endpointDescription, EndpointEvent.ADDED);
- queueEndpointDescription(endpointDescription, discovered);
- } else {
- queueEndpointEvent(endpointDescription, EndpointEvent.REMOVED);
- queueEndpointDescription(endpointDescription, discovered);
- }
- }
-
private DiscoveredEndpointDescription getDiscoveredEndpointDescription(
IServiceID serviceId, IServiceInfo serviceInfo,
boolean discovered) {
@@ -1394,6 +1375,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
*/
public void discoverEndpoint(
org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription endpointDescription) {
+ addED(endpointDescription, null);
queueEndpointEvent(endpointDescription, EndpointEvent.ADDED);
}
@@ -1402,6 +1384,7 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
*/
public void updateEndpoint(
org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription endpointDescription) {
+ updateED(endpointDescription, endpointDescription, null);
queueEndpointEvent(endpointDescription, EndpointEvent.MODIFIED);
}
@@ -1410,7 +1393,22 @@ public class EndpointDescriptionLocator implements IEndpointDescriptionLocator {
*/
public void undiscoverEndpoint(
org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription endpointDescription) {
+ removeED(endpointDescription);
queueEndpointEvent(endpointDescription, EndpointEvent.REMOVED);
}
+ /**
+ * @since 4.3
+ */
+ public org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription[] getDiscoveredEndpoints() {
+ List<org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription> results = new ArrayList<org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription>();
+ for (EndpointDescription ed : getEDs()) {
+ if (ed instanceof org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription)
+ results.add((org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription) ed);
+ }
+ return results
+ .toArray(new org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription[results
+ .size()]);
+ }
+
}
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 f9fbc304c..4fa550d20 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
@@ -8,11 +8,18 @@ import org.eclipse.ecf.discovery.identity.IServiceID;
public interface IEndpointDescriptionLocator {
/**
+ * Get endpoints discovered by this endpoint locator
+ * @return EndpointDescription[] of previously discovered endpoint. Will not return null,
+ * but may return empty array.
+ */
+ EndpointDescription[] getDiscoveredEndpoints();
+
+ /**
* Get the service ID associated with the
* @param endpointDescription
* @return
*/
- IServiceID getNetworkDiscoveredService(EndpointDescription endpointDescription);
+ IServiceID getNetworkDiscoveredServiceID(EndpointDescription endpointDescription);
/**
* Discover the given endpointDescription. This method will not block

Back to the top