Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF1
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java4
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java4
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java8
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java39
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractRemoteServiceAdmin.java265
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java18
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java9
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionWriter.java3
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportEndpoint.java82
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportReference.java4
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportRegistration.java78
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportEndpoint.java97
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportReference.java2
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportRegistration.java82
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/TopologyManager.java15
16 files changed, 465 insertions, 246 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
index 95e8b629d..9f8ddead4 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
@@ -19,6 +19,7 @@ Import-Package: org.eclipse.ecf.core;version="3.0.0",
org.eclipse.osgi.framework.eventmgr,
org.osgi.framework;version="1.3.0",
org.osgi.framework.hooks.service,
+ org.osgi.service.event,
org.osgi.service.log,
org.osgi.service.packageadmin,
org.osgi.service.remoteserviceadmin;version="1.0.0",
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java
index 37c5018a3..3a02c8dd3 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java
@@ -17,6 +17,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
@@ -582,7 +583,8 @@ public class Discovery {
}
private Map getMapFromProperties(ServiceReference ref) {
- Map results = new HashMap();
+ Map<String, Object> results = new TreeMap<String, Object>(
+ String.CASE_INSENSITIVE_ORDER);
String[] keys = ref.getPropertyKeys();
if (keys != null) {
for (int i = 0; i < keys.length; i++) {
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java
index 49a3b6d9f..a1081f11c 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java
@@ -19,6 +19,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -378,7 +379,8 @@ public class EndpointDescriptionParser {
public EndpointDescriptionHandler(ContentHandler parentHandler,
Attributes attributes, List<EndpointDescription> descriptions) {
super(parentHandler, ENDPOINT_DESCRIPTION);
- this.properties = new HashMap<String, Object>();
+ this.properties = new TreeMap<String, Object>(
+ String.CASE_INSENSITIVE_ORDER);
this.descriptions = descriptions;
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java
index 1e83846e1..e5cd61a58 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java
@@ -267,14 +267,6 @@ public class PropertiesUtil {
}
public static Map<String, Object> copyProperties(
- ServiceReference serviceReference, Map<String, Object> target) {
- String[] keys = serviceReference.getPropertyKeys();
- for (int i = 0; i < keys.length; i++)
- target.put(keys[i], serviceReference.getProperty(keys[i]));
- return target;
- }
-
- public static Map<String, Object> copyProperties(
IRemoteServiceRegistration rsRegistration,
Map<String, Object> target) {
String[] keys = rsRegistration.getPropertyKeys();
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java
index 54d6527f8..891f683e9 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java
@@ -12,11 +12,11 @@ package org.eclipse.ecf.osgi.services.remoteserviceadmin;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.TreeMap;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.discovery.IServiceProperties;
@@ -156,27 +156,34 @@ public abstract class AbstractMetadataFactory {
protected EndpointDescription decodeEndpointDescription(
IServiceProperties discoveredServiceProperties) {
- Map osgiProperties = new HashMap();
- decodeOSGiProperties(discoveredServiceProperties, osgiProperties);
+
+ Map<String, Object> endpointDescriptionProperties = new TreeMap<String, Object>(
+ String.CASE_INSENSITIVE_ORDER);
+
+ decodeOSGiProperties(discoveredServiceProperties,
+ endpointDescriptionProperties);
// remote service id
Long remoteServiceId = decodeLong(discoveredServiceProperties,
org.eclipse.ecf.remoteservice.Constants.SERVICE_ID);
- osgiProperties.put(org.eclipse.ecf.remoteservice.Constants.SERVICE_ID,
+ endpointDescriptionProperties.put(
+ org.eclipse.ecf.remoteservice.Constants.SERVICE_ID,
remoteServiceId);
// container id namespace
String containerIDNamespace = decodeString(discoveredServiceProperties,
RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE);
if (containerIDNamespace != null)
- osgiProperties.put(RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE,
+ endpointDescriptionProperties.put(
+ RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE,
containerIDNamespace);
// connect target ID
String connectTargetIDName = decodeString(discoveredServiceProperties,
RemoteConstants.ENDPOINT_CONNECTTARGET_ID);
if (connectTargetIDName != null)
- osgiProperties.put(RemoteConstants.ENDPOINT_CONNECTTARGET_ID,
+ endpointDescriptionProperties.put(
+ RemoteConstants.ENDPOINT_CONNECTTARGET_ID,
connectTargetIDName);
// ID filter
@@ -185,21 +192,22 @@ public abstract class AbstractMetadataFactory {
Object idFilterNamesval = PropertiesUtil
.convertToStringPlusValue(idFilterNames);
if (idFilterNamesval != null)
- osgiProperties.put(RemoteConstants.ENDPOINT_IDFILTER_IDS,
- idFilterNamesval);
+ endpointDescriptionProperties.put(
+ RemoteConstants.ENDPOINT_IDFILTER_IDS, idFilterNamesval);
// remote service filter
String remoteServiceFilter = decodeString(discoveredServiceProperties,
RemoteConstants.ENDPOINT_REMOTESERVICE_FILTER);
if (remoteServiceFilter != null)
- osgiProperties.put(RemoteConstants.ENDPOINT_REMOTESERVICE_FILTER,
+ endpointDescriptionProperties.put(
+ RemoteConstants.ENDPOINT_REMOTESERVICE_FILTER,
remoteServiceFilter);
// Finally, fill out other properties
decodeNonStandardServiceProperties(discoveredServiceProperties,
- osgiProperties);
+ endpointDescriptionProperties);
- return new EndpointDescription(osgiProperties);
+ return new EndpointDescription(endpointDescriptionProperties);
}
private String getPackageName(String className) {
@@ -208,8 +216,9 @@ public abstract class AbstractMetadataFactory {
return "";
return className.substring(0, lastDotIndex);
}
-
- protected void encodeOSGiServiceProperties(EndpointDescription endpointDescription, IServiceProperties result) {
+
+ protected void encodeOSGiServiceProperties(
+ EndpointDescription endpointDescription, IServiceProperties result) {
// org.osgi.framework.Constants.OBJECTCLASS =
// endpointDescription.getInterfaces();
List<String> interfaces = endpointDescription.getInterfaces();
@@ -290,12 +299,12 @@ public abstract class AbstractMetadataFactory {
remoteIntentsSupported);
}
-
+
protected void encodeServiceProperties(
EndpointDescription endpointDescription, IServiceProperties result) {
encodeOSGiServiceProperties(endpointDescription, result);
-
+
// org.eclipse.ecf.remoteservice.Constants.SERVICE_ID =
// endpointDescription.getRemoteServiceId()
long remoteServiceId = endpointDescription.getRemoteServiceId();
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractRemoteServiceAdmin.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractRemoteServiceAdmin.java
index 6bc8b3715..81672cfda 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractRemoteServiceAdmin.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractRemoteServiceAdmin.java
@@ -53,12 +53,15 @@ import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.Version;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.remoteserviceadmin.ImportReference;
import org.osgi.util.tracker.ServiceTracker;
-public abstract class AbstractRemoteServiceAdmin {
+public abstract class AbstractRemoteServiceAdmin implements
+ org.osgi.service.remoteserviceadmin.RemoteServiceAdmin {
private BundleContext context;
@@ -95,7 +98,6 @@ public abstract class AbstractRemoteServiceAdmin {
private ServiceTracker packageVersionComparatorTracker;
protected Collection<ExportRegistration> exportedRegistrations = new ArrayList<ExportRegistration>();
-
protected Collection<ImportRegistration> importedRegistrations = new ArrayList<ImportRegistration>();
public AbstractRemoteServiceAdmin(BundleContext context) {
@@ -127,6 +129,40 @@ public abstract class AbstractRemoteServiceAdmin {
packageVersionComparatorRegistration = getContext().registerService(
IPackageVersionComparator.class.getName(),
packageVersionComparator, (Dictionary) properties);
+
+ }
+
+ private Object eventAdminTrackerLock = new Object();
+ private ServiceTracker eventAdminTracker;
+
+ private EventAdmin getEventAdmin() {
+ synchronized (eventAdminTrackerLock) {
+ eventAdminTracker = new ServiceTracker(getContext(),
+ EventAdmin.class.getName(), null);
+ eventAdminTracker.open(true);
+ }
+ return (EventAdmin) eventAdminTracker.getService();
+ }
+
+ protected void postRemoteServiceAdminEvent(String topic,
+ Dictionary eventProperties) {
+ EventAdmin eventAdmin = getEventAdmin();
+ if (eventAdmin == null) {
+ logError("postRemoteServiceAdminEvent",
+ "No EventAdmin service available to send eventTopic="
+ + topic + " eventProperties=" + eventProperties);
+ return;
+ }
+ eventAdmin.postEvent(new Event(topic, eventProperties));
+ }
+
+ private void closeEventAdminTracker() {
+ synchronized (eventAdminTrackerLock) {
+ if (eventAdminTracker != null) {
+ eventAdminTracker.close();
+ eventAdminTracker = null;
+ }
+ }
}
protected BundleContext getContext() {
@@ -262,13 +298,9 @@ public abstract class AbstractRemoteServiceAdmin {
String.CASE_INSENSITIVE_ORDER);
// OSGi properties
- // OBJECTCLASS
- String[] interfaces = (String[]) PropertiesUtil.getPropertyValue(null,
- overridingProperties, org.osgi.framework.Constants.OBJECTCLASS);
- if (interfaces == null)
- interfaces = exportedInterfaces;
+ // OBJECTCLASS set to exportedInterfaces
endpointDescriptionProperties.put(
- org.osgi.framework.Constants.OBJECTCLASS, interfaces);
+ org.osgi.framework.Constants.OBJECTCLASS, exportedInterfaces);
// Service interface versions
for (int i = 0; i < exportedInterfaces.length; i++) {
@@ -308,9 +340,9 @@ public abstract class AbstractRemoteServiceAdmin {
endpointId);
// ENDPOINT_SERVICE_ID
- Long serviceId = (Long) PropertiesUtil.getPropertyValue(
- serviceReference, overridingProperties,
- org.osgi.framework.Constants.SERVICE_ID);
+ // This is always set to the value from serviceReference as per 122.5.1
+ Long serviceId = (Long) serviceReference
+ .getProperty(org.osgi.framework.Constants.SERVICE_ID);
endpointDescriptionProperties.put(
org.osgi.framework.Constants.SERVICE_ID, serviceId);
@@ -326,10 +358,18 @@ public abstract class AbstractRemoteServiceAdmin {
.put(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID,
frameworkId);
- // SERVICE_IMPORTED_CONFIGS...set to ECF constant
+ // REMOTE_CONFIGS_SUPPORTED
+ String[] remoteConfigsSupported = getSupportedConfigs(container);
+ if (remoteConfigsSupported != null)
+ endpointDescriptionProperties
+ .put(org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED,
+ remoteConfigsSupported);
+ // SERVICE_IMPORTED_CONFIGS...set to same value as remote configs
+ // supported (which is computed
+ // for the exporting ECF container
endpointDescriptionProperties
.put(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED_CONFIGS,
- RemoteConstants.ENDPOINT_SERVICE_IMPORTED_CONFIGS_VALUE);
+ remoteConfigsSupported);
// SERVICE_INTENTS
String[] intents = (String[]) PropertiesUtil
@@ -351,13 +391,6 @@ public abstract class AbstractRemoteServiceAdmin {
.put(org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_INTENTS_SUPPORTED,
remoteIntentsSupported);
- // REMOTE_CONFIGS_SUPPORTED
- String[] remoteConfigsSupported = getSupportedConfigs(container);
- if (remoteConfigsSupported != null)
- endpointDescriptionProperties
- .put(org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED,
- remoteConfigsSupported);
-
// ECF properties
// ID namespace
String idNamespace = containerID.getNamespace().getName();
@@ -467,18 +500,17 @@ public abstract class AbstractRemoteServiceAdmin {
}
}
- protected ImportRegistration handleNonOSGiService(
- EndpointDescription endpointDescription,
- IRemoteServiceContainer rsContainer) {
+ protected org.osgi.service.remoteserviceadmin.ImportRegistration handleNonOSGiService(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
// With non-OSGi service id (service id=0), we log a warning and return
// null;
- logWarning("doImportService",
+ logWarning("handleNonOSGiService",
"OSGi remote service id is 0 for endpointDescription="
+ endpointDescription);
return null;
}
- protected ImportRegistration createAndRegisterProxy(
+ protected ImportEndpoint createAndRegisterProxy(
EndpointDescription endpointDescription,
IRemoteServiceContainer rsContainer,
IRemoteServiceReference selectedRsReference) throws Exception {
@@ -508,8 +540,8 @@ public abstract class AbstractRemoteServiceAdmin {
(Dictionary) PropertiesUtil
.createDictionaryFromMap(proxyProperties));
- return new ImportRegistration(rsContainer, rsListener,
- selectedRsReference, endpointDescription, proxyRegistration);
+ return new ImportEndpoint(containerAdapter, selectedRsReference,
+ rsListener, proxyRegistration, endpointDescription);
}
protected ServiceFactory createProxyServiceFactory(
@@ -541,7 +573,7 @@ public abstract class AbstractRemoteServiceAdmin {
return result;
}
- class ProxyServiceFactory implements ServiceFactory {
+ protected class ProxyServiceFactory implements ServiceFactory {
private IRemoteService remoteService;
private Map<String, Version> interfaceVersions;
@@ -603,41 +635,45 @@ public abstract class AbstractRemoteServiceAdmin {
}
- private Map<Bundle,ProxyClassLoader> proxyClassLoaders = new HashMap<Bundle,ProxyClassLoader>();
-
+ private Map<Bundle, ProxyClassLoader> proxyClassLoaders = new HashMap<Bundle, ProxyClassLoader>();
+
private void closeProxyClassLoaderCache() {
synchronized (proxyClassLoaders) {
proxyClassLoaders.clear();
}
}
-
+
protected ClassLoader getProxyClassLoader(Bundle bundle) {
ProxyClassLoader proxyClassLoaderForBundle = null;
synchronized (proxyClassLoaders) {
proxyClassLoaderForBundle = proxyClassLoaders.get(bundle);
if (proxyClassLoaderForBundle == null) {
proxyClassLoaderForBundle = new ProxyClassLoader(bundle);
- proxyClassLoaders.put(bundle,proxyClassLoaderForBundle);
- } else proxyClassLoaderForBundle.addServiceUseCount();
+ proxyClassLoaders.put(bundle, proxyClassLoaderForBundle);
+ } else
+ proxyClassLoaderForBundle.addServiceUseCount();
}
return proxyClassLoaderForBundle;
}
protected void ungetProxyClassLoader(Bundle bundle) {
synchronized (proxyClassLoaders) {
- ProxyClassLoader proxyClassLoaderForBundle = proxyClassLoaders.get(bundle);
+ ProxyClassLoader proxyClassLoaderForBundle = proxyClassLoaders
+ .get(bundle);
if (proxyClassLoaderForBundle != null) {
int useCount = proxyClassLoaderForBundle.getServiceUseCount();
- if (useCount == 0) proxyClassLoaders.remove(bundle);
- else proxyClassLoaderForBundle.removeServiceUseCount();
+ if (useCount == 0)
+ proxyClassLoaders.remove(bundle);
+ else
+ proxyClassLoaderForBundle.removeServiceUseCount();
}
}
}
-
+
protected class ProxyClassLoader extends ClassLoader {
private Bundle loadingBundle;
private int serviceUseCount = 0;
-
+
public ProxyClassLoader(Bundle loadingBundle) {
this.loadingBundle = loadingBundle;
}
@@ -645,15 +681,15 @@ public abstract class AbstractRemoteServiceAdmin {
public Class loadClass(String name) throws ClassNotFoundException {
return loadingBundle.loadClass(name);
}
-
+
public int getServiceUseCount() {
return serviceUseCount;
}
-
+
public void addServiceUseCount() {
serviceUseCount++;
}
-
+
public void removeServiceUseCount() {
serviceUseCount--;
}
@@ -817,11 +853,11 @@ public abstract class AbstractRemoteServiceAdmin {
return resultProperties;
}
- public ExportRegistration exportService(
- ServiceReference serviceReference,
+ protected ExportEndpoint exportService(ServiceReference serviceReference,
Map<String, Object> overridingProperties,
String[] exportedInterfaces, String[] serviceIntents,
IRemoteServiceContainer rsContainer) throws Exception {
+ ID containerID = rsContainer.getContainer().getID();
trace("doExportService",
"serviceReference="
+ serviceReference
@@ -832,7 +868,7 @@ public abstract class AbstractRemoteServiceAdmin {
+ ",serviceIntents="
+ ((serviceIntents == null) ? "null" : Arrays.asList(
serviceIntents).toString()) + ",rsContainerID="
- + rsContainer.getContainer().getID());
+ + containerID);
IRemoteServiceRegistration remoteRegistration = null;
try {
// Create remote service properties
@@ -870,9 +906,9 @@ public abstract class AbstractRemoteServiceAdmin {
EndpointDescription endpointDescription = createExportEndpointDescription(
serviceReference, overridingProperties, exportedInterfaces,
serviceIntents, remoteRegistration, rsContainer);
- // Create ExportRegistration
- return createExportRegistration(remoteRegistration,
- serviceReference, endpointDescription);
+ // Create ExportEndpoint/ExportRegistration
+ return new ExportEndpoint(serviceReference, containerID,
+ remoteRegistration, endpointDescription);
} catch (Exception e) {
// If we actually created an IRemoteRegistration then unregister
if (remoteRegistration != null)
@@ -882,22 +918,11 @@ public abstract class AbstractRemoteServiceAdmin {
}
}
- protected ExportRegistration createExportRegistration(
- IRemoteServiceRegistration remoteRegistration,
- ServiceReference serviceReference,
- EndpointDescription endpointDescription) {
- return new ExportRegistration(remoteRegistration, serviceReference,
- endpointDescription);
- }
-
- public ImportRegistration importService(
+ protected ImportEndpoint importService(
EndpointDescription endpointDescription,
IRemoteServiceContainer rsContainer) throws Exception {
trace("doImportService", "endpointDescription=" + endpointDescription
+ ",rsContainerID=" + rsContainer.getContainer().getID());
- long osgiServiceId = endpointDescription.getServiceId();
- if (osgiServiceId == 0)
- return handleNonOSGiService(endpointDescription, rsContainer);
// Get interfaces from endpoint description
Collection<String> interfaces = endpointDescription.getInterfaces();
Assert.isNotNull(interfaces);
@@ -976,6 +1001,7 @@ public abstract class AbstractRemoteServiceAdmin {
closeConsumerContainerSelector();
closeHostContainerSelector();
closePackageAdminTracker();
+ closeEventAdminTracker();
synchronized (exportedRegistrations) {
exportedRegistrations.clear();
}
@@ -992,20 +1018,23 @@ public abstract class AbstractRemoteServiceAdmin {
trace("exportService", "serviceReference=" + serviceReference
+ ",properties=" + overridingProperties);
- // First get exported interfaces...try overriding properties first...or from serviceReference second
- String[] exportedInterfaces = null;
- if (overridingProperties != null)
- exportedInterfaces = (String[]) overridingProperties
- .get(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES);
+ overridingProperties = (overridingProperties == null) ? Collections.EMPTY_MAP
+ : overridingProperties;
+
+ // First get exported interfaces
+ String[] exportedInterfaces = (String[]) overridingProperties
+ .get(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES);
+ // As per 122.5.1 we only use the OBJECTCLASS value from the
+ // serviceReference, not from the overridingProperties map
if (exportedInterfaces == null)
exportedInterfaces = PropertiesUtil
.getExportedInterfaces(serviceReference);
- // If null, we don't have anything to export (log warning and return empty Collection)
- if (exportedInterfaces == null) {
- logWarning("exportService", "serviceReference=" + serviceReference
- + " does not expose any exported interfaces");
- return Collections.EMPTY_LIST;
- }
+ // If exportedInterfaces is still null, we throw
+ if (exportedInterfaces == null)
+ throw new IllegalArgumentException(
+ org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES
+ + " not set");
+
// Get optional service property for exported configs
String[] exportedConfigs = PropertiesUtil
.getStringArrayFromPropertyValue(serviceReference
@@ -1014,6 +1043,7 @@ public abstract class AbstractRemoteServiceAdmin {
// service.exported.intents.extra)
String[] serviceIntents = PropertiesUtil
.getServiceIntents(serviceReference);
+
// Get a host container selector
IHostContainerSelector hostContainerSelector = getHostContainerSelector();
if (hostContainerSelector == null) {
@@ -1037,31 +1067,58 @@ public abstract class AbstractRemoteServiceAdmin {
Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> results = new ArrayList<org.osgi.service.remoteserviceadmin.ExportRegistration>();
synchronized (exportedRegistrations) {
for (int i = 0; i < rsContainers.length; i++) {
+ ID containerID = rsContainers[i].getContainer().getID();
+ // If we've already got an export endpoint
+ // for this service reference/containerID combination,
+ // then create an ExportRegistration that uses the endpoint
+ ExportEndpoint exportEndpoint = findExistingExportEndpoint(
+ serviceReference, containerID);
+
ExportRegistration rsRegistration = null;
- try {
- rsRegistration = exportService(serviceReference,
- overridingProperties, exportedInterfaces,
- serviceIntents, rsContainers[i]);
- } catch (Exception e) {
- logError("exportService",
- "Exception exporting serviceReference="
- + serviceReference + " with properties="
- + overridingProperties + " rsContainerID="
- + rsContainers[i].getContainer().getID(), e);
- rsRegistration = new ExportRegistration(serviceReference, e);
+ if (exportEndpoint != null)
+ rsRegistration = new ExportRegistration(exportEndpoint);
+ else {
+ try {
+ rsRegistration = new ExportRegistration(exportService(
+ serviceReference, overridingProperties,
+ exportedInterfaces, serviceIntents,
+ rsContainers[i]));
+ exportedRegistrations.add(rsRegistration);
+ } catch (Exception e) {
+ logError("exportService",
+ "Exception exporting serviceReference="
+ + serviceReference
+ + " with properties="
+ + overridingProperties
+ + " rsContainerID=" + containerID, e);
+ rsRegistration = new ExportRegistration(
+ serviceReference, containerID, e);
+ }
}
results.add(rsRegistration);
- exportedRegistrations.add(rsRegistration);
}
}
return results;
}
+ private ExportEndpoint findExistingExportEndpoint(
+ ServiceReference serviceReference, ID containerID) {
+ for (ExportRegistration eReg : exportedRegistrations) {
+ ExportEndpoint exportEndpoint = eReg.getExportEndpoint(
+ serviceReference, containerID);
+ if (exportEndpoint != null)
+ return exportEndpoint;
+ }
+ return null;
+ }
+
public org.osgi.service.remoteserviceadmin.ImportRegistration importService(
org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
-
trace("importService", "endpointDescription=" + endpointDescription);
-
+
+ if (endpointDescription.getServiceId() == 0)
+ return handleNonOSGiService(endpointDescription);
+
// First check to see whether it's one of ECF's endpoint descriptions
if (endpointDescription instanceof EndpointDescription) {
EndpointDescription ed = (EndpointDescription) endpointDescription;
@@ -1088,38 +1145,37 @@ public abstract class AbstractRemoteServiceAdmin {
// If one selected then import the service to create an import
// registration
ImportRegistration importRegistration = null;
+ ID containerID = rsContainer.getContainer().getID();
synchronized (importedRegistrations) {
try {
- importRegistration = importService(ed, rsContainer);
+ ImportEndpoint importEndpoint = importService(ed,
+ rsContainer);
+ importRegistration = new ImportRegistration(importEndpoint);
+ importedRegistrations.add(importRegistration);
} catch (Exception e) {
logError("importService",
"Exception importing endpointDescription=" + ed
- + rsContainer.getContainer().getID(), e);
- importRegistration = new ImportRegistration(rsContainer, e);
+ + " with containerID=" + containerID, e);
+ importRegistration = new ImportRegistration(containerID, e);
} catch (NoClassDefFoundError e) {
logError("importService",
"NoClassDefFoundError importing endpointDescription="
- + ed + rsContainer.getContainer().getID(),
+ + ed + " with containerID=" + containerID,
e);
- importRegistration = new ImportRegistration(rsContainer, e);
+ importRegistration = new ImportRegistration(containerID, e);
}
- // If we actually created an importRegistration...whether
- // successful or not, add it to the
- // set of imported registrations
- if (importRegistration != null)
- importedRegistrations.add(importRegistration);
}
// Finally, return the importRegistration. It may be null or not.
return importRegistration;
} else {
logWarning("importService", "endpointDescription="
+ endpointDescription
- + " is not ECFEndpointDescription...ignoring");
+ + " is not ECF EndpointDescription...ignoring");
return null;
}
}
- public Collection<ImportRegistration> unimportService(
+ protected Collection<ImportRegistration> unimportService(
IRemoteServiceID remoteServiceID) {
trace("unimport", "remoteServiceID=" + remoteServiceID);
List<ImportRegistration> removedRegistrations = new ArrayList<ImportRegistration>();
@@ -1127,11 +1183,8 @@ public abstract class AbstractRemoteServiceAdmin {
for (Iterator<ImportRegistration> i = importedRegistrations
.iterator(); i.hasNext();) {
ImportRegistration importRegistration = i.next();
- IRemoteServiceReference rsReference = importRegistration
- .getRemoteServiceReference();
- if (rsReference != null) {
- IRemoteServiceID regID = rsReference.getID();
- if (regID.equals(remoteServiceID)) {
+ if (importRegistration != null) {
+ if (importRegistration.match(remoteServiceID)) {
removedRegistrations.add(importRegistration);
i.remove();
}
@@ -1160,7 +1213,7 @@ public abstract class AbstractRemoteServiceAdmin {
return new RemoteServiceListener();
}
- public Collection<ImportRegistration> unimportService(
+ protected Collection<ImportRegistration> unimportService(
EndpointDescription endpointDescription) {
trace("unimportService", "endpointDescription=" + endpointDescription);
List<ImportRegistration> removedRegistrations = new ArrayList<ImportRegistration>();
@@ -1196,7 +1249,7 @@ public abstract class AbstractRemoteServiceAdmin {
return removedRegistrations;
}
- public Collection<org.eclipse.ecf.osgi.services.remoteserviceadmin.ExportRegistration> getExportedRegistrations() {
+ protected Collection<org.eclipse.ecf.osgi.services.remoteserviceadmin.ExportRegistration> getExportedRegistrations() {
Collection<org.eclipse.ecf.osgi.services.remoteserviceadmin.ExportRegistration> results = new ArrayList<org.eclipse.ecf.osgi.services.remoteserviceadmin.ExportRegistration>();
synchronized (exportedRegistrations) {
results.addAll(exportedRegistrations);
@@ -1214,7 +1267,7 @@ public abstract class AbstractRemoteServiceAdmin {
return results;
}
- public Collection<org.eclipse.ecf.osgi.services.remoteserviceadmin.ImportRegistration> getImportedRegistrations() {
+ protected Collection<org.eclipse.ecf.osgi.services.remoteserviceadmin.ImportRegistration> getImportedRegistrations() {
Collection<org.eclipse.ecf.osgi.services.remoteserviceadmin.ImportRegistration> results = new ArrayList<org.eclipse.ecf.osgi.services.remoteserviceadmin.ImportRegistration>();
synchronized (importedRegistrations) {
results.addAll(importedRegistrations);
@@ -1236,12 +1289,12 @@ public abstract class AbstractRemoteServiceAdmin {
ServiceReference serviceReference) {
List<ExportRegistration> results = new ArrayList<ExportRegistration>();
for (ExportRegistration exportReg : exportedRegistrations)
- if (exportReg.matchesServiceReference(serviceReference))
+ if (exportReg.match(serviceReference))
results.add(exportReg);
return results.toArray(new ExportRegistration[results.size()]);
}
- public EndpointDescription[] unexportService(
+ protected EndpointDescription[] unexportService(
ServiceReference serviceReference) {
List<EndpointDescription> endpointDescriptions = new ArrayList<EndpointDescription>();
synchronized (exportedRegistrations) {
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java
index 9ad201177..959ef022e 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java
@@ -9,8 +9,6 @@
******************************************************************************/
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
-import java.util.List;
-
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.IDUtil;
import org.eclipse.ecf.remoteservice.IRemoteServiceContainer;
@@ -31,19 +29,9 @@ public class ConsumerContainerSelector extends
// Get the endpointID
ID endpointID = IDUtil.createID(endpointDescription);
- String[] remoteSupportedConfigs = null;
- List<String> edConfigurationTypes = endpointDescription
- .getConfigurationTypes();
- if (edConfigurationTypes.size() >= 1
- && edConfigurationTypes
- .get(0)
- .equals(RemoteConstants.ENDPOINT_SERVICE_IMPORTED_CONFIGS_VALUE)) {
- remoteSupportedConfigs = (String[]) endpointDescription
- .getProperties()
- .get(org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED);
- } else
- remoteSupportedConfigs = edConfigurationTypes
- .toArray(new String[edConfigurationTypes.size()]);
+ String[] remoteSupportedConfigs = (String[]) endpointDescription
+ .getProperties()
+ .get(org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED);
// Get connect targetID
ID connectTargetID = endpointDescription.getConnectTargetID();
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
index dba74512a..3bf127fbd 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
@@ -153,6 +153,15 @@ public class EndpointDescription extends
return hashCode;
}
+ public boolean isSameService(
+ org.osgi.service.remoteserviceadmin.EndpointDescription other) {
+ if (!(other instanceof EndpointDescription))
+ return false;
+ EndpointDescription o = (EndpointDescription) other;
+ return (super.isSameService(other) && o.getRemoteServiceId() == this
+ .getRemoteServiceId());
+ }
+
public String getIdNamespace() {
return idNamespace;
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionWriter.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionWriter.java
index 6804b6c9d..d58a557f3 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionWriter.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionWriter.java
@@ -228,7 +228,8 @@ public class EndpointDescriptionWriter {
if (valueType != null) {
writeValueProperty(indentLevel, name, valueType, value, writer);
return;
- } else writeUnknownProperty(indentLevel, writer, name, value);
+ } else
+ writeUnknownProperty(indentLevel, writer, name, value);
}
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportEndpoint.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportEndpoint.java
new file mode 100644
index 000000000..aa7392f21
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportEndpoint.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
+import org.osgi.framework.ServiceReference;
+
+public class ExportEndpoint {
+
+ private ServiceReference serviceReference;
+ private ID containerID;
+ private IRemoteServiceRegistration rsRegistration;
+ private ExportReference exportReference;
+ private Set<ExportRegistration> exportRegistrations;
+
+ public ExportEndpoint(ServiceReference serviceReference, ID containerID,
+ IRemoteServiceRegistration reg,
+ EndpointDescription endpointDescription) {
+ Assert.isNotNull(serviceReference);
+ Assert.isNotNull(reg);
+ Assert.isNotNull(endpointDescription);
+ this.serviceReference = serviceReference;
+ this.containerID = containerID;
+ this.rsRegistration = reg;
+ this.exportReference = new ExportReference(serviceReference,
+ endpointDescription);
+ this.exportRegistrations = new HashSet<ExportRegistration>();
+ }
+
+ ID getContainerID() {
+ return containerID;
+ }
+
+ ServiceReference getServiceReference() {
+ return serviceReference;
+ }
+
+ synchronized ExportReference getExportReference() {
+ return exportReference;
+ }
+
+ synchronized IRemoteServiceRegistration getRemoteServiceRegistration() {
+ return rsRegistration;
+ }
+
+ synchronized boolean add(ExportRegistration exportRegistration) {
+ return this.exportRegistrations.add(exportRegistration);
+ }
+
+ synchronized boolean close(ExportRegistration exportRegistration) {
+ boolean removed = this.exportRegistrations.remove(exportRegistration);
+ if (removed && exportRegistrations.size() == 0) {
+ if (rsRegistration != null) {
+ rsRegistration.unregister();
+ rsRegistration = null;
+ }
+ if (exportReference != null) {
+ exportReference.close();
+ exportReference = null;
+ }
+ }
+ return removed;
+ }
+
+ public synchronized String toString() {
+ return "ExportEndpoint [rsRegistration=" + rsRegistration
+ + ", exportReference=" + exportReference + "]";
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportReference.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportReference.java
index 33361a946..d6d204909 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportReference.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportReference.java
@@ -17,7 +17,7 @@ public class ExportReference implements
private ServiceReference serviceReference;
private EndpointDescription endpointDescription;
- protected ExportReference(ServiceReference serviceReference,
+ ExportReference(ServiceReference serviceReference,
EndpointDescription endpointDescription) {
this.serviceReference = serviceReference;
this.endpointDescription = endpointDescription;
@@ -31,7 +31,7 @@ public class ExportReference implements
return endpointDescription;
}
- public synchronized void close() {
+ synchronized void close() {
this.serviceReference = null;
this.endpointDescription = null;
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportRegistration.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportRegistration.java
index df0d71711..6ccc1d7ea 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportRegistration.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ExportRegistration.java
@@ -10,61 +10,77 @@
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
import org.osgi.framework.ServiceReference;
public class ExportRegistration implements
org.osgi.service.remoteserviceadmin.ExportRegistration {
- private IRemoteServiceRegistration rsRegistration;
- private ExportReference exportReference;
-
+ // these members are set whether this ExportRegistration
+ // is valid or not
private ServiceReference serviceReference;
+ private ID containerID;
+ // This is only null if this ExportRegistration is invalid
+ private ExportEndpoint exportEndpoint;
+ // This is only non-null if this ExportRegistration is invalid
private Throwable exception;
- public ExportRegistration(IRemoteServiceRegistration rsRegistration,
- ServiceReference proxyServiceReference,
- EndpointDescription endpointDescription) {
- Assert.isNotNull(rsRegistration);
- this.rsRegistration = rsRegistration;
- this.serviceReference = proxyServiceReference;
- this.exportReference = new ExportReference(proxyServiceReference,
- endpointDescription);
+ public ExportRegistration(ExportEndpoint exportEndpoint) {
+ Assert.isNotNull(exportEndpoint);
+ this.exportEndpoint = exportEndpoint;
+ this.serviceReference = exportEndpoint.getServiceReference();
+ this.containerID = exportEndpoint.getContainerID();
+ // Add ourselves to this exported endpoint
+ this.exportEndpoint.add(this);
}
- public ExportRegistration(ServiceReference serviceReference, Throwable t) {
+ public ExportRegistration(ServiceReference serviceReference,
+ ID containerID, Throwable t) {
this.serviceReference = serviceReference;
+ this.containerID = containerID;
this.exception = t;
}
+ public ID getContainerID() {
+ return containerID;
+ }
+
public synchronized org.osgi.service.remoteserviceadmin.ExportReference getExportReference() {
Throwable t = getException();
if (t != null)
throw new IllegalStateException(
- "Cannot get export reference as registration not properly initialized",
+ "Cannot get export reference as export registration is invalid",
t);
- return exportReference;
+ return (exportEndpoint == null) ? null : exportEndpoint
+ .getExportReference();
+ }
+
+ synchronized boolean match(ServiceReference serviceReference) {
+ return match(serviceReference, null);
+ }
+
+ synchronized boolean match(ServiceReference serviceReference, ID containerID) {
+ boolean containerIDMatch = (containerID == null) ? true
+ : this.containerID.equals(containerID);
+ return containerIDMatch
+ && this.serviceReference.equals(serviceReference);
}
- public synchronized boolean matchesServiceReference(
- ServiceReference serviceReference) {
- if (serviceReference == null)
- return false;
- return (this.serviceReference.equals(serviceReference));
+ synchronized ExportEndpoint getExportEndpoint(
+ ServiceReference serviceReference, ID containerID) {
+ return match(serviceReference, containerID) ? exportEndpoint : null;
}
- public synchronized IRemoteServiceRegistration getRemoteServiceRegistration() {
- return rsRegistration;
+ synchronized IRemoteServiceRegistration getRemoteServiceRegistration() {
+ return (exportEndpoint == null) ? null : exportEndpoint
+ .getRemoteServiceRegistration();
}
public synchronized void close() {
- if (rsRegistration != null) {
- rsRegistration.unregister();
- rsRegistration = null;
- }
- if (exportReference != null) {
- exportReference.close();
- exportReference = null;
+ if (exportEndpoint != null) {
+ exportEndpoint.close(this);
+ exportEndpoint = null;
}
exception = null;
}
@@ -74,9 +90,9 @@ public class ExportRegistration implements
}
public synchronized String toString() {
- return "ExportRegistration[rsRegistration=" + rsRegistration
- + ", exportReference=" + exportReference
- + ", serviceReference=" + serviceReference + ", exception="
+ return "ExportRegistration[containerID=" + containerID
+ + ", serviceReference=" + serviceReference
+ + ", exportEndpoint=" + exportEndpoint + ", exception="
+ exception + "]";
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportEndpoint.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportEndpoint.java
new file mode 100644
index 000000000..b926a172e
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportEndpoint.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRemoteServiceID;
+import org.eclipse.ecf.remoteservice.IRemoteServiceListener;
+import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public class ImportEndpoint {
+
+ private IRemoteServiceContainerAdapter rsContainerAdapter;
+ private IRemoteServiceListener rsListener;
+ private IRemoteServiceReference rsReference;
+ private ServiceRegistration proxyRegistration;
+ private ImportReference importReference;
+ private Set<ImportRegistration> importRegistrations;
+
+ public ImportEndpoint(IRemoteServiceContainerAdapter rsContainerAdapter,
+ IRemoteServiceReference rsReference,
+ IRemoteServiceListener rsListener,
+ ServiceRegistration proxyRegistration,
+ EndpointDescription endpointDescription) {
+ this.rsContainerAdapter = rsContainerAdapter;
+ this.rsReference = rsReference;
+ this.rsListener = rsListener;
+ this.proxyRegistration = proxyRegistration;
+ this.importReference = new ImportReference(
+ proxyRegistration.getReference(), endpointDescription);
+ // Add the remoteservice listener to the container adapter, so that the
+ // rsListener
+ // notified asynchronously if our underlying remote service reference is
+ // unregistered locally
+ // due to disconnect or remote ejection
+ this.rsContainerAdapter.addRemoteServiceListener(this.rsListener);
+ this.importRegistrations = new HashSet<ImportRegistration>();
+ }
+
+ synchronized boolean add(ImportRegistration importRegistration) {
+ return this.importRegistrations.add(importRegistration);
+ }
+
+ synchronized boolean close(ImportRegistration importRegistration) {
+ boolean removed = this.importRegistrations.remove(importRegistration);
+ if (removed && importRegistrations.size() == 0) {
+ if (proxyRegistration != null) {
+ proxyRegistration.unregister();
+ proxyRegistration = null;
+ }
+ if (rsContainerAdapter != null) {
+ if (rsReference != null) {
+ rsContainerAdapter.ungetRemoteService(rsReference);
+ rsReference = null;
+ }
+ // remove remote service listener
+ if (rsListener != null) {
+ rsContainerAdapter.removeRemoteServiceListener(rsListener);
+ rsListener = null;
+ }
+ rsContainerAdapter = null;
+ }
+ if (importReference != null) {
+ importReference.close();
+ importReference = null;
+ }
+ }
+ return removed;
+ }
+
+ synchronized ImportReference getImportReference() {
+ return importReference;
+ }
+
+ synchronized boolean match(IRemoteServiceID remoteServiceID) {
+ if (remoteServiceID == null || rsReference == null)
+ return false;
+ return rsReference.getID().equals(remoteServiceID);
+ }
+
+ public synchronized String toString() {
+ return "ImportEndpoint [rsReference=" + rsReference
+ + ", proxyRegistration=" + proxyRegistration
+ + ", importReference=" + importReference + "]";
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportReference.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportReference.java
index b733876e6..12c456cd0 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportReference.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportReference.java
@@ -31,7 +31,7 @@ public class ImportReference implements
return endpointDescription;
}
- public synchronized void close() {
+ synchronized void close() {
this.importedServiceReference = null;
this.endpointDescription = null;
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportRegistration.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportRegistration.java
index 7d224708d..88780cd05 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportRegistration.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportRegistration.java
@@ -10,55 +10,36 @@
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
import org.eclipse.core.runtime.Assert;
-import org.eclipse.ecf.remoteservice.IRemoteServiceContainer;
-import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
-import org.eclipse.ecf.remoteservice.IRemoteServiceListener;
-import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
-import org.osgi.framework.ServiceRegistration;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.remoteservice.IRemoteServiceID;
public class ImportRegistration implements
org.osgi.service.remoteserviceadmin.ImportRegistration {
- private IRemoteServiceContainer rsContainer;
- private IRemoteServiceListener rsListener;
- private IRemoteServiceReference rsReference;
- private ServiceRegistration importRegistration;
- private ImportReference importReference;
+ private ImportEndpoint importEndpoint;
+
+ private ID containerID;
private Throwable throwable;
- public ImportRegistration(IRemoteServiceContainer rsContainer,
- IRemoteServiceListener rsListener,
- IRemoteServiceReference rsReference,
- EndpointDescription endpointDescription,
- ServiceRegistration importRegistration) {
- this.rsContainer = rsContainer;
- Assert.isNotNull(rsContainer);
- this.rsListener = rsListener;
- Assert.isNotNull(rsListener);
- this.rsReference = rsReference;
- Assert.isNotNull(rsReference);
- this.importRegistration = importRegistration;
- this.importReference = new ImportReference(
- importRegistration.getReference(), endpointDescription);
- // Add the remoteservice listener to the container adapter, so that the
- // rsListener
- // notified asynchronously if our underlying remote service reference is
- // unregistered locally
- // due to disconnect or remote ejection
- rsContainer.getContainerAdapter().addRemoteServiceListener(rsListener);
+ public ImportRegistration(ImportEndpoint importEndpoint) {
+ Assert.isNotNull(importEndpoint);
+ this.importEndpoint = importEndpoint;
+ this.importEndpoint.add(this);
}
- public ImportRegistration(IRemoteServiceContainer rsContainer, Throwable t) {
- this.rsContainer = rsContainer;
+ public ImportRegistration(ID containerID, Throwable t) {
+ this.containerID = containerID;
this.throwable = t;
}
- public synchronized IRemoteServiceReference getRemoteServiceReference() {
- return rsReference;
+ public ID getContainerID() {
+ return containerID;
}
- public synchronized IRemoteServiceContainer getRemoteServiceContainer() {
- return rsContainer;
+ synchronized boolean match(IRemoteServiceID remoteServiceID) {
+ if (importEndpoint == null)
+ return false;
+ return importEndpoint.match(remoteServiceID);
}
public synchronized ImportReference getImportReference() {
@@ -67,29 +48,14 @@ public class ImportRegistration implements
throw new IllegalStateException(
"Cannot get import reference as registration not properly initialized",
t);
- return importReference;
+ return importEndpoint == null ? null : importEndpoint
+ .getImportReference();
}
public synchronized void close() {
- if (importRegistration != null) {
- importRegistration.unregister();
- importRegistration = null;
- }
- if (rsContainer != null) {
- IRemoteServiceContainerAdapter containerAdapter = rsContainer
- .getContainerAdapter();
- if (rsReference != null)
- containerAdapter.ungetRemoteService(rsReference);
- rsReference = null;
- // remove remote service listener
- if (rsListener != null)
- containerAdapter.removeRemoteServiceListener(rsListener);
- rsListener = null;
- rsContainer = null;
- }
- if (importReference != null) {
- importReference.close();
- importReference = null;
+ if (importEndpoint != null) {
+ importEndpoint.close(this);
+ importEndpoint = null;
}
throwable = null;
}
@@ -99,8 +65,8 @@ public class ImportRegistration implements
}
public synchronized String toString() {
- return "ImportRegistration [rsReference=" + rsReference
- + ", importReference=" + importReference + ", throwable="
+ return "ImportRegistration [containerID=" + containerID
+ + ", importEndpoint=" + importEndpoint + ", exception="
+ throwable + "]";
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/TopologyManager.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/TopologyManager.java
index 29b6e362a..eab88debd 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/TopologyManager.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/TopologyManager.java
@@ -11,9 +11,9 @@ package org.eclipse.ecf.osgi.services.remoteserviceadmin;
import java.util.Collection;
import java.util.Dictionary;
-import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.Discovery;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.PropertiesUtil;
@@ -169,13 +169,14 @@ public class TopologyManager extends AbstractTopologyManager implements
+ ". Remote service NOT EXPORTED");
return;
}
-
+
// prepare export properties
- Map<String, Object> exportProperties = new HashMap<String, Object>();
- exportProperties.put(
- org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES,
- exportedInterfaces);
-
+ Map<String, Object> exportProperties = new TreeMap<String, Object>(
+ String.CASE_INSENSITIVE_ORDER);
+ exportProperties
+ .put(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES,
+ exportedInterfaces);
+
// Export the remote service using the selected remote service admin
Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> registrations = rsa
.exportService(serviceReference, exportProperties);

Back to the top