Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2011-01-01 19:57:25 -0500
committerslewis2011-01-01 19:57:25 -0500
commitf5257193bf743a4765e41280c547d708858b9374 (patch)
treef624296520576a48e484ea4cf427ad6d49a2d8cd /incubation
parentfee5e5c4ed44fbfb97db812afbc6c40619abdca1 (diff)
downloadorg.eclipse.ecf-f5257193bf743a4765e41280c547d708858b9374.tar.gz
org.eclipse.ecf-f5257193bf743a4765e41280c547d708858b9374.tar.xz
org.eclipse.ecf-f5257193bf743a4765e41280c547d708858b9374.zip
rsa refactoring
Diffstat (limited to 'incubation')
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java111
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java78
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java3
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java4
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java6
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportEndpoint.java5
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ImportRegistration.java1
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/LocatorServiceListener.java10
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java515
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/TopologyManager.java146
10 files changed, 474 insertions, 405 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
index 6e3ad3dc8..4d076168e 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
@@ -10,7 +10,10 @@
package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import java.util.UUID;
import javax.xml.parsers.SAXParserFactory;
@@ -19,13 +22,16 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.ecf.core.IContainerManager;
import org.eclipse.ecf.core.util.LogHelper;
import org.eclipse.ecf.core.util.SystemLogService;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionLocator;
import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionAdvertiser;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionLocator;
import org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionAdvertiser;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin;
import org.eclipse.ecf.osgi.services.remoteserviceadmin.TopologyManager;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
@@ -46,10 +52,13 @@ public class Activator implements BundleActivator {
return instance;
}
+ private Map<Bundle, RemoteServiceAdmin> remoteServiceAdmins = new TreeMap<Bundle, RemoteServiceAdmin>();
+ private ServiceRegistration remoteServiceAdminRegistration;
+
private EndpointDescriptionLocator endpointDescriptionLocator;
private EndpointDescriptionAdvertiser endpointDescriptionAdvertiser;
private ServiceRegistration endpointDescriptionAdvertiserRegistration;
-
+
private TopologyManager topologyManager;
/*
@@ -62,37 +71,19 @@ public class Activator implements BundleActivator {
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Activator.instance = this;
+ startRemoteServiceAdmin();
+
endpointDescriptionLocator = new EndpointDescriptionLocator(context);
+
startEndpointDescriptionAdvertiser();
+
topologyManager = new TopologyManager(context);
- // start topology manager
+ // start topology manager first
topologyManager.start();
// start endpointDescriptionLocator
endpointDescriptionLocator.start();
}
- private void startEndpointDescriptionAdvertiser() {
- final Properties properties = new Properties();
- properties.put(Constants.SERVICE_RANKING,
- new Integer(Integer.MIN_VALUE));
- endpointDescriptionAdvertiser = new EndpointDescriptionAdvertiser(
- endpointDescriptionLocator);
- endpointDescriptionAdvertiserRegistration = getContext()
- .registerService(
- IEndpointDescriptionAdvertiser.class.getName(),
- endpointDescriptionAdvertiser, (Dictionary) properties);
- }
-
- private void stopEndpointDescriptionAdvertiser() {
- if (endpointDescriptionAdvertiserRegistration != null) {
- endpointDescriptionAdvertiserRegistration.unregister();
- endpointDescriptionAdvertiserRegistration = null;
- }
- if (endpointDescriptionAdvertiser != null) {
- endpointDescriptionAdvertiser.close();
- endpointDescriptionAdvertiser = null;
- }
- }
/*
* (non-Javadoc)
*
@@ -108,6 +99,7 @@ public class Activator implements BundleActivator {
topologyManager.close();
topologyManager = null;
}
+ stopRemoteServiceAdmin();
stopEndpointDescriptionAdvertiser();
stopSAXParserTracker();
stopLogServiceTracker();
@@ -116,6 +108,75 @@ public class Activator implements BundleActivator {
Activator.instance = null;
}
+ private void startRemoteServiceAdmin() {
+ Properties rsaProps = new Properties();
+ rsaProps.put(RemoteServiceAdmin.SERVICE_PROP, new Boolean(true));
+ remoteServiceAdminRegistration = context.registerService(
+ org.osgi.service.remoteserviceadmin.RemoteServiceAdmin.class
+ .getName(), new ServiceFactory() {
+ public Object getService(Bundle bundle,
+ ServiceRegistration registration) {
+ RemoteServiceAdmin rsa = new RemoteServiceAdmin(
+ getContext());
+ synchronized (remoteServiceAdmins) {
+ remoteServiceAdmins.put(bundle, rsa);
+ }
+ return rsa;
+ }
+
+ public void ungetService(Bundle bundle,
+ ServiceRegistration registration, Object service) {
+
+ RemoteServiceAdmin rsa = null;
+ synchronized (remoteServiceAdmins) {
+ rsa = remoteServiceAdmins.get(bundle);
+ }
+ if (rsa != null)
+ rsa.close();
+ }
+ }, rsaProps);
+ }
+
+ private void stopRemoteServiceAdmin() {
+ if (remoteServiceAdminRegistration != null) {
+ remoteServiceAdminRegistration.unregister();
+ remoteServiceAdminRegistration = null;
+ }
+ synchronized (remoteServiceAdmins) {
+ for (Iterator<Bundle> i = remoteServiceAdmins.keySet().iterator(); i
+ .hasNext();) {
+ RemoteServiceAdmin rsa = remoteServiceAdmins.get(i.next());
+ if (rsa != null) {
+ rsa.close();
+ i.remove();
+ }
+ }
+ }
+ }
+
+ private void startEndpointDescriptionAdvertiser() {
+ final Properties properties = new Properties();
+ properties.put(Constants.SERVICE_RANKING,
+ new Integer(Integer.MIN_VALUE));
+ endpointDescriptionAdvertiser = new EndpointDescriptionAdvertiser(
+ endpointDescriptionLocator);
+ endpointDescriptionAdvertiserRegistration = getContext()
+ .registerService(
+ IEndpointDescriptionAdvertiser.class.getName(),
+ endpointDescriptionAdvertiser, (Dictionary) properties);
+ }
+
+ private void stopEndpointDescriptionAdvertiser() {
+ if (endpointDescriptionAdvertiserRegistration != null) {
+ endpointDescriptionAdvertiserRegistration.unregister();
+ endpointDescriptionAdvertiserRegistration = null;
+ }
+ if (endpointDescriptionAdvertiser != null) {
+ endpointDescriptionAdvertiser.close();
+ endpointDescriptionAdvertiser = null;
+ }
+ }
+
public String getFrameworkUUID() {
if (context == null)
return null;
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java
index d72883a45..e1371db00 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java
@@ -13,7 +13,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.DebugOptions;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.LogUtility;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.util.tracker.ServiceTracker;
public abstract class AbstractTopologyManager {
@@ -25,16 +26,13 @@ public abstract class AbstractTopologyManager {
private ServiceTracker endpointDescriptionAdvertiserTracker;
private Object endpointDescriptionAdvertiserTrackerLock = new Object();
- private RemoteServiceAdmin remoteServiceAdmin;
- private Object remoteServiceAdminLock = new Object();
+ private ServiceTracker remoteServiceAdminTracker;
+ private Object remoteServiceAdminTrackerLock = new Object();
public AbstractTopologyManager(BundleContext context) {
this.context = context;
}
- public void start() throws Exception {
- }
-
protected BundleContext getContext() {
return context;
}
@@ -59,55 +57,55 @@ public abstract class AbstractTopologyManager {
endpointDescriptionAdvertiserTracker = null;
}
}
- context = null;
- }
-
- protected org.osgi.service.remoteserviceadmin.RemoteServiceAdmin selectExportRemoteServiceAdmin(
- ServiceReference serviceReference, String[] exportedInterfaces) {
- synchronized (remoteServiceAdminLock) {
- if (remoteServiceAdmin == null)
- remoteServiceAdmin = new RemoteServiceAdmin(getContext());
+ synchronized (remoteServiceAdminTrackerLock) {
+ if (remoteServiceAdminTracker != null) {
+ remoteServiceAdminTracker.close();
+ remoteServiceAdminTracker = null;
+ }
}
- return remoteServiceAdmin;
+ context = null;
}
- protected RemoteServiceAdmin selectUnexportRemoteServiceAdmin(
- ServiceReference serviceReference) {
- synchronized (remoteServiceAdminLock) {
- return remoteServiceAdmin;
- }
+ protected void logWarning(String methodName, String message) {
+ LogUtility.logWarning(methodName, DebugOptions.TOPOLOGY_MANAGER,
+ this.getClass(), message);
}
- protected RemoteServiceAdmin selectImportRemoteServiceAdmin(
- EndpointDescription endpoint) {
- synchronized (remoteServiceAdminLock) {
- if (remoteServiceAdmin == null)
- remoteServiceAdmin = new RemoteServiceAdmin(getContext());
+ protected Filter createRSAFilter() {
+ String filterString = "(&("
+ + org.osgi.framework.Constants.OBJECTCLASS
+ + "="
+ + org.osgi.service.remoteserviceadmin.RemoteServiceAdmin.class
+ .getName()
+ + ")("
+ + org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.SERVICE_PROP
+ + "=*))";
+ try {
+ return getContext().createFilter(filterString);
+ } catch (InvalidSyntaxException e) {
+ // Should never happen
+ return null;
}
- return remoteServiceAdmin;
}
- protected RemoteServiceAdmin selectUnimportRemoteServiceAdmin(
- EndpointDescription endpoint) {
- synchronized (remoteServiceAdminLock) {
- if (remoteServiceAdmin == null)
- remoteServiceAdmin = new RemoteServiceAdmin(getContext());
+ protected org.osgi.service.remoteserviceadmin.RemoteServiceAdmin getRemoteServiceAdmin() {
+ synchronized (remoteServiceAdminTrackerLock) {
+ if (remoteServiceAdminTracker == null) {
+ remoteServiceAdminTracker = new ServiceTracker(getContext(),
+ createRSAFilter(), null);
+ remoteServiceAdminTracker.open(true);
+ }
}
- return remoteServiceAdmin;
- }
-
- protected void logWarning(String methodName, String message) {
- LogUtility.logWarning(methodName, DebugOptions.TOPOLOGY_MANAGER,
- this.getClass(), message);
+ return (org.osgi.service.remoteserviceadmin.RemoteServiceAdmin) remoteServiceAdminTracker
+ .getService();
}
protected void advertiseEndpointDescription(
EndpointDescription endpointDescription) {
IEndpointDescriptionAdvertiser advertiser = getEndpointDescriptionAdvertiser();
if (advertiser == null) {
- logError(
- "advertiseExportedRegistration",
- "No endpoint description advertiser available to advertise endpointDescription="
+ logWarning("advertiseExportedRegistration",
+ "No endpoint description advertiser available for endpointDescription="
+ endpointDescription);
return;
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java
index b6372849c..fd771442b 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java
@@ -26,7 +26,8 @@ public class EndpointDescriptionAdvertiser implements
private EndpointDescriptionLocator endpointDescriptionLocator;
- public EndpointDescriptionAdvertiser(EndpointDescriptionLocator endpointDescriptionLocator) {
+ public EndpointDescriptionAdvertiser(
+ EndpointDescriptionLocator endpointDescriptionLocator) {
this.endpointDescriptionLocator = endpointDescriptionLocator;
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
index 25020cbd4..05a81b15c 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
@@ -167,8 +167,8 @@ public class EndpointDescriptionLocator {
// Register the endpoint listener tracker, so that endpoint listeners
// that are subsequently added
// will then be notified of discovered endpoints
- endpointListenerTrackerCustomizer = new EndpointListenerTrackerCustomizer(context,
- this);
+ endpointListenerTrackerCustomizer = new EndpointListenerTrackerCustomizer(
+ context, this);
endpointListenerTracker = new ServiceTracker(context,
EndpointListener.class.getName(),
endpointListenerTrackerCustomizer);
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java
index 63cf373f8..0362c9850 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java
@@ -22,7 +22,8 @@ public class EndpointListenerTrackerCustomizer implements
private BundleContext context;
private EndpointDescriptionLocator endpointDescriptionLocator;
- public EndpointListenerTrackerCustomizer(BundleContext context, EndpointDescriptionLocator endpointDescriptionLocator) {
+ public EndpointListenerTrackerCustomizer(BundleContext context,
+ EndpointDescriptionLocator endpointDescriptionLocator) {
this.context = context;
this.endpointDescriptionLocator = endpointDescriptionLocator;
}
@@ -30,7 +31,8 @@ public class EndpointListenerTrackerCustomizer implements
public Object addingService(ServiceReference reference) {
Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> allDiscoveredEndpointDescriptions = endpointDescriptionLocator
.getAllDiscoveredEndpointDescriptions();
- if (context == null) return null;
+ if (context == null)
+ return null;
EndpointListener listener = (EndpointListener) context
.getService(reference);
if (listener == null)
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
index 1768bce6c..6498092c7 100644
--- 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
@@ -12,6 +12,7 @@ package org.eclipse.ecf.osgi.services.remoteserviceadmin;
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
import org.eclipse.ecf.remoteservice.IRemoteServiceID;
import org.eclipse.ecf.remoteservice.IRemoteServiceListener;
@@ -47,6 +48,10 @@ public class ImportEndpoint {
this.importRegistrations = new HashSet<ImportRegistration>();
}
+ synchronized ID getContainerID() {
+ return (rsReference == null) ? null : rsReference.getContainerID();
+ }
+
synchronized boolean add(ImportRegistration importRegistration) {
return this.importRegistrations.add(importRegistration);
}
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 fa07f3944..94dc4f0d3 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
@@ -23,6 +23,7 @@ public class ImportRegistration implements
public ImportRegistration(ImportEndpoint importEndpoint) {
Assert.isNotNull(importEndpoint);
+ this.containerID = importEndpoint.getContainerID();
this.importEndpoint = importEndpoint;
this.importEndpoint.add(this);
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/LocatorServiceListener.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/LocatorServiceListener.java
index 4445a893c..c0d9ba984 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/LocatorServiceListener.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/LocatorServiceListener.java
@@ -30,11 +30,14 @@ class LocatorServiceListener implements IServiceListener {
private List<org.osgi.service.remoteserviceadmin.EndpointDescription> discoveredEndpointDescriptions = new ArrayList();
- public LocatorServiceListener(EndpointDescriptionLocator endpointDescriptionLocator) {
+ public LocatorServiceListener(
+ EndpointDescriptionLocator endpointDescriptionLocator) {
this(endpointDescriptionLocator, null);
}
- public LocatorServiceListener(EndpointDescriptionLocator endpointDescriptionLocator, IDiscoveryLocator locator) {
+ public LocatorServiceListener(
+ EndpointDescriptionLocator endpointDescriptionLocator,
+ IDiscoveryLocator locator) {
this.endpointDescriptionLocator = endpointDescriptionLocator;
this.locator = locator;
if (locator != null) {
@@ -89,7 +92,8 @@ class LocatorServiceListener implements IServiceListener {
else
discoveredEndpointDescriptions.remove(endpointDescription);
- endpointDescriptionLocator.queueEndpointDescription(endpointDescription, discovered);
+ endpointDescriptionLocator.queueEndpointDescription(
+ endpointDescription, discovered);
}
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
index 291993194..2a5770da4 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
@@ -57,12 +57,13 @@ 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 class RemoteServiceAdmin implements
org.osgi.service.remoteserviceadmin.RemoteServiceAdmin {
+ public static final String SERVICE_PROP = "org.eclipse.ecf.rsa";
+
private BundleContext context;
private boolean hostAutoCreateContainer = new Boolean(
@@ -132,6 +133,198 @@ public class RemoteServiceAdmin implements
}
+ // RemoteServiceAdmin service interface impl methods
+ public Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> exportService(
+ ServiceReference serviceReference,
+ Map<String, Object> overridingProperties) {
+
+ trace("exportService", "serviceReference=" + serviceReference
+ + ",properties=" + overridingProperties);
+
+ 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 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
+ .getProperty(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_CONFIGS));
+ // Get all intents (service.intents, service.exported.intents,
+ // service.exported.intents.extra)
+ String[] serviceIntents = PropertiesUtil
+ .getServiceIntents(serviceReference);
+
+ // Get a host container selector
+ IHostContainerSelector hostContainerSelector = getHostContainerSelector();
+ if (hostContainerSelector == null) {
+ logError("handleServiceRegistering",
+ "No hostContainerSelector available");
+ return Collections.EMPTY_LIST;
+ }
+ // select ECF remote service containers that match given exported
+ // interfaces, configs, and intents
+ IRemoteServiceContainer[] rsContainers = hostContainerSelector
+ .selectHostContainers(serviceReference, exportedInterfaces,
+ exportedConfigs, serviceIntents);
+ // If none found, log a warning and we're done
+ if (rsContainers == null || rsContainers.length == 0) {
+ logWarning(
+ "handleServiceRegistered", "No remote service containers found for serviceReference=" //$NON-NLS-1$
+ + serviceReference
+ + ". Remote service NOT EXPORTED"); //$NON-NLS-1$
+ return Collections.EMPTY_LIST;
+ }
+ 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;
+ 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);
+ }
+ }
+ return results;
+ }
+
+ public Collection<org.osgi.service.remoteserviceadmin.ExportReference> getExportedServices() {
+ Collection<org.osgi.service.remoteserviceadmin.ExportReference> results = new ArrayList<org.osgi.service.remoteserviceadmin.ExportReference>();
+ synchronized (exportedRegistrations) {
+ for (ExportRegistration reg : exportedRegistrations)
+ results.add(reg.getExportReference());
+ }
+ return results;
+ }
+
+ public Collection<org.osgi.service.remoteserviceadmin.ImportReference> getImportedEndpoints() {
+ Collection<org.osgi.service.remoteserviceadmin.ImportReference> results = new ArrayList<org.osgi.service.remoteserviceadmin.ImportReference>();
+ synchronized (importedRegistrations) {
+ for (ImportRegistration reg : importedRegistrations)
+ results.add(reg.getImportReference());
+ }
+ return results;
+ }
+
+ // RemoteServiceAdmin service interface impl methods
+
+ 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;
+ // Now get IConsumerContainerSelector, to select the ECF container
+ // for the given endpointDescription
+ IConsumerContainerSelector consumerContainerSelector = getConsumerContainerSelector();
+ // If there is none, then we can go no further
+ if (consumerContainerSelector == null) {
+ logError("importService",
+ "No consumerContainerSelector available");
+ return null;
+ }
+ // Select the rsContainer to handle the endpoint description
+ IRemoteServiceContainer rsContainer = consumerContainerSelector
+ .selectConsumerContainer(ed);
+ // If none found, log a warning and we're done
+ if (rsContainer == null) {
+ logWarning(
+ "importService", "No remote service container selected for endpoint=" //$NON-NLS-1$
+ + endpointDescription
+ + ". Remote service NOT IMPORTED"); //$NON-NLS-1$
+ return null;
+ }
+ // If one selected then import the service to create an import
+ // registration
+ ImportRegistration importRegistration = null;
+ ID containerID = rsContainer.getContainer().getID();
+ synchronized (importedRegistrations) {
+ ImportEndpoint importEndpoint = findImportEndpoint(ed);
+ if (importEndpoint != null) {
+ importRegistration = new ImportRegistration(importEndpoint);
+ } else {
+ try {
+ importEndpoint = importService(ed, rsContainer);
+ importRegistration = new ImportRegistration(
+ importEndpoint);
+ importedRegistrations.add(importRegistration);
+ } catch (Exception e) {
+ logError("importService",
+ "Exception importing endpointDescription=" + ed
+ + " with containerID=" + containerID, e);
+ importRegistration = new ImportRegistration(
+ containerID, e);
+ } catch (NoClassDefFoundError e) {
+ logError("importService",
+ "NoClassDefFoundError importing endpointDescription="
+ + ed + " with containerID="
+ + containerID, e);
+ importRegistration = new ImportRegistration(
+ containerID, e);
+ }
+ }
+ }
+ // Finally, return the importRegistration. It may be null or not.
+ return importRegistration;
+ } else {
+ logWarning("importService", "endpointDescription="
+ + endpointDescription
+ + " is not ECF EndpointDescription...ignoring");
+ return null;
+ }
+ }
+
private Object eventAdminTrackerLock = new Object();
private ServiceTracker eventAdminTracker;
@@ -248,30 +441,6 @@ public class RemoteServiceAdmin implements
.getService();
}
- protected void logError(String methodName, String message, IStatus status) {
- LogUtility.logError(methodName, DebugOptions.REMOTE_SERVICE_ADMIN,
- this.getClass(), status);
- }
-
- protected void trace(String methodName, String message) {
- LogUtility.trace(methodName, DebugOptions.REMOTE_SERVICE_ADMIN,
- this.getClass(), message);
- }
-
- protected void logWarning(String methodName, String message) {
- LogUtility.logWarning(methodName, DebugOptions.REMOTE_SERVICE_ADMIN,
- this.getClass(), message);
- }
-
- protected void logError(String methodName, String message, Throwable t) {
- LogUtility.logError(methodName, DebugOptions.REMOTE_SERVICE_ADMIN,
- this.getClass(), message, t);
- }
-
- protected void logError(String methodName, String message) {
- logError(methodName, message, (Throwable) null);
- }
-
private Version getPackageVersion(Bundle registeringBundle,
String packageName) {
ExportedPackage[] exportedPackages = getPackageAdmin()
@@ -456,19 +625,19 @@ public class RemoteServiceAdmin implements
return containerManager.getContainerTypeDescription(container.getID());
}
- protected String[] getSupportedConfigs(IContainer container) {
+ private String[] getSupportedConfigs(IContainer container) {
ContainerTypeDescription ctd = getContainerTypeDescription(container);
return (ctd == null) ? null : ctd.getSupportedConfigs();
}
- protected String[] getImportedConfigs(IContainer container,
+ private String[] getImportedConfigs(IContainer container,
String[] exporterSupportedConfigs) {
ContainerTypeDescription ctd = getContainerTypeDescription(container);
return (ctd == null) ? null : ctd
.getImportedConfigs(exporterSupportedConfigs);
}
- protected String[] getSupportedIntents(IContainer container) {
+ private String[] getSupportedIntents(IContainer container) {
ContainerTypeDescription ctd = getContainerTypeDescription(container);
return (ctd == null) ? null : ctd.getSupportedIntents();
}
@@ -1011,177 +1180,6 @@ public class RemoteServiceAdmin implements
this.context = null;
}
- public Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> exportService(
- ServiceReference serviceReference,
- Map<String, Object> overridingProperties) {
-
- trace("exportService", "serviceReference=" + serviceReference
- + ",properties=" + overridingProperties);
-
- 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 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
- .getProperty(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_CONFIGS));
- // Get all intents (service.intents, service.exported.intents,
- // service.exported.intents.extra)
- String[] serviceIntents = PropertiesUtil
- .getServiceIntents(serviceReference);
-
- // Get a host container selector
- IHostContainerSelector hostContainerSelector = getHostContainerSelector();
- if (hostContainerSelector == null) {
- logError("handleServiceRegistering",
- "No hostContainerSelector available");
- return Collections.EMPTY_LIST;
- }
- // select ECF remote service containers that match given exported
- // interfaces, configs, and intents
- IRemoteServiceContainer[] rsContainers = hostContainerSelector
- .selectHostContainers(serviceReference, exportedInterfaces,
- exportedConfigs, serviceIntents);
- // If none found, log a warning and we're done
- if (rsContainers == null || rsContainers.length == 0) {
- logWarning(
- "handleServiceRegistered", "No remote service containers found for serviceReference=" //$NON-NLS-1$
- + serviceReference
- + ". Remote service NOT EXPORTED"); //$NON-NLS-1$
- return Collections.EMPTY_LIST;
- }
- 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;
- 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);
- }
- }
- 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;
- // Now get IConsumerContainerSelector, to select the ECF container
- // for the given endpointDescription
- IConsumerContainerSelector consumerContainerSelector = getConsumerContainerSelector();
- // If there is none, then we can go no further
- if (consumerContainerSelector == null) {
- logError("importService",
- "No consumerContainerSelector available");
- return null;
- }
- // Select the rsContainer to handle the endpoint description
- IRemoteServiceContainer rsContainer = consumerContainerSelector
- .selectConsumerContainer(ed);
- // If none found, log a warning and we're done
- if (rsContainer == null) {
- logWarning(
- "importService", "No remote service container selected for endpoint=" //$NON-NLS-1$
- + endpointDescription
- + ". Remote service NOT IMPORTED"); //$NON-NLS-1$
- return null;
- }
- // If one selected then import the service to create an import
- // registration
- ImportRegistration importRegistration = null;
- ID containerID = rsContainer.getContainer().getID();
- synchronized (importedRegistrations) {
- ImportEndpoint importEndpoint = findImportEndpoint(ed);
- if (importEndpoint != null) {
- importRegistration = new ImportRegistration(importEndpoint);
- } else {
- try {
- importEndpoint = importService(ed, rsContainer);
- importRegistration = new ImportRegistration(
- importEndpoint);
- importedRegistrations.add(importRegistration);
- } catch (Exception e) {
- logError("importService",
- "Exception importing endpointDescription=" + ed
- + " with containerID=" + containerID, e);
- importRegistration = new ImportRegistration(
- containerID, e);
- } catch (NoClassDefFoundError e) {
- logError("importService",
- "NoClassDefFoundError importing endpointDescription="
- + ed + " with containerID="
- + containerID, e);
- importRegistration = new ImportRegistration(
- containerID, e);
- }
- }
- }
- // Finally, return the importRegistration. It may be null or not.
- return importRegistration;
- } else {
- logWarning("importService", "endpointDescription="
- + endpointDescription
- + " is not ECF EndpointDescription...ignoring");
- return null;
- }
- }
-
private ImportEndpoint findImportEndpoint(EndpointDescription ed) {
for (ImportRegistration reg : importedRegistrations) {
ImportEndpoint endpoint = reg.getImportEndpoint(ed);
@@ -1229,119 +1227,28 @@ public class RemoteServiceAdmin implements
return new RemoteServiceListener();
}
- protected Collection<ImportRegistration> unimportService(
- EndpointDescription endpointDescription) {
- trace("unimportService", "endpointDescription=" + endpointDescription);
- List<ImportRegistration> removedRegistrations = new ArrayList<ImportRegistration>();
- synchronized (importedRegistrations) {
- for (Iterator<ImportRegistration> i = importedRegistrations
- .iterator(); i.hasNext();) {
- ImportRegistration reg = i.next();
- ImportReference importReference = null;
- try {
- importReference = reg.getImportReference();
- if (importReference != null) {
- org.osgi.service.remoteserviceadmin.EndpointDescription importedDescription = importReference
- .getImportedEndpoint();
- if (importedDescription != null
- && importedDescription
- .equals(endpointDescription)) {
- removedRegistrations.add(reg);
- i.remove();
- }
- }
- } catch (IllegalStateException e) {
- // no export ref because ExportRegistration not
- // initialized properly
- logWarning("unimportService",
- "IllegalStateException accessing export reference for importRegistration="
- + reg);
- }
- }
- }
- // Now close all of them
- for (ImportRegistration removedReg : removedRegistrations)
- removedReg.close();
- return removedRegistrations;
- }
-
- 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);
- }
- return results;
+ protected void logError(String methodName, String message, IStatus status) {
+ LogUtility.logError(methodName, DebugOptions.REMOTE_SERVICE_ADMIN,
+ this.getClass(), status);
}
- public Collection<org.osgi.service.remoteserviceadmin.ExportReference> getExportedServices() {
- Collection<org.osgi.service.remoteserviceadmin.ExportReference> results = new ArrayList<org.osgi.service.remoteserviceadmin.ExportReference>();
- synchronized (exportedRegistrations) {
- for (ExportRegistration reg : exportedRegistrations) {
- results.add(reg.getExportReference());
- }
- }
- return results;
+ protected void trace(String methodName, String message) {
+ LogUtility.trace(methodName, DebugOptions.REMOTE_SERVICE_ADMIN,
+ this.getClass(), message);
}
- 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);
- }
- return results;
+ protected void logWarning(String methodName, String message) {
+ LogUtility.logWarning(methodName, DebugOptions.REMOTE_SERVICE_ADMIN,
+ this.getClass(), message);
}
- public Collection<org.osgi.service.remoteserviceadmin.ImportReference> getImportedEndpoints() {
- Collection<org.osgi.service.remoteserviceadmin.ImportReference> results = new ArrayList<org.osgi.service.remoteserviceadmin.ImportReference>();
- synchronized (importedRegistrations) {
- for (ImportRegistration reg : importedRegistrations) {
- results.add(reg.getImportReference());
- }
- }
- return results;
+ protected void logError(String methodName, String message, Throwable t) {
+ LogUtility.logError(methodName, DebugOptions.REMOTE_SERVICE_ADMIN,
+ this.getClass(), message, t);
}
- private ExportRegistration[] findExportRegistrations(
- ServiceReference serviceReference) {
- List<ExportRegistration> results = new ArrayList<ExportRegistration>();
- for (ExportRegistration exportReg : exportedRegistrations)
- if (exportReg.match(serviceReference))
- results.add(exportReg);
- return results.toArray(new ExportRegistration[results.size()]);
+ protected void logError(String methodName, String message) {
+ logError(methodName, message, (Throwable) null);
}
- protected EndpointDescription[] unexportService(
- ServiceReference serviceReference) {
- List<EndpointDescription> endpointDescriptions = new ArrayList<EndpointDescription>();
- synchronized (exportedRegistrations) {
- ExportRegistration[] exportRegs = findExportRegistrations(serviceReference);
- if (exportRegs != null) {
- for (int i = 0; i < exportRegs.length; i++) {
- org.osgi.service.remoteserviceadmin.ExportReference exportRef = null;
- try {
- exportRef = exportRegs[i].getExportReference();
- if (exportRef != null) {
- org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription = exportRef
- .getExportedEndpoint();
- if (endpointDescription != null
- && endpointDescription instanceof EndpointDescription) {
- endpointDescriptions
- .add((EndpointDescription) endpointDescription);
- }
- exportRegs[i].close();
- exportedRegistrations.remove(exportRegs[i]);
- }
- } catch (IllegalStateException e) {
- // no export ref because ExportRegistration not
- // initialized properly
- logWarning("unexportService",
- "IllegalStateException accessing export reference for exportRegistration="
- + exportRegs[i]);
- }
- }
- }
- }
- return endpointDescriptions
- .toArray(new EndpointDescription[endpointDescriptions.size()]);
- }
}
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 3260cc313..4f8ede27b 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
@@ -9,8 +9,11 @@
******************************************************************************/
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
@@ -22,7 +25,6 @@ import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.EventHook;
import org.osgi.service.remoteserviceadmin.EndpointListener;
-import org.osgi.service.remoteserviceadmin.ImportRegistration;
public class TopologyManager extends AbstractTopologyManager implements
EventHook, EndpointListener {
@@ -31,12 +33,14 @@ public class TopologyManager extends AbstractTopologyManager implements
private ServiceRegistration eventHookRegistration;
+ protected Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> exportedRegistrations = new ArrayList<org.osgi.service.remoteserviceadmin.ExportRegistration>();
+ protected Collection<org.osgi.service.remoteserviceadmin.ImportRegistration> importedRegistrations = new ArrayList<org.osgi.service.remoteserviceadmin.ImportRegistration>();
+
public TopologyManager(BundleContext context) {
super(context);
}
public void start() throws Exception {
- super.start();
// Register as EndpointListener, so that it gets notified when Endpoints
// are discovered
Properties props = new Properties();
@@ -92,7 +96,7 @@ public class TopologyManager extends AbstractTopologyManager implements
trace("handleEndpointAdded", "endpointDescription="
+ endpointDescription);
// First, select importing remote service admin
- org.osgi.service.remoteserviceadmin.RemoteServiceAdmin rsa = selectImportRemoteServiceAdmin(endpointDescription);
+ org.osgi.service.remoteserviceadmin.RemoteServiceAdmin rsa = getRemoteServiceAdmin();
if (rsa == null) {
logError("handleEndpointAdded",
@@ -101,28 +105,31 @@ public class TopologyManager extends AbstractTopologyManager implements
return;
}
// now call rsa.import
- ImportRegistration importRegistration = rsa
- .importService(endpointDescription);
- if (importRegistration == null) {
- logError("handleEndpointAdded",
- "Import registration is null for endpointDescription="
- + endpointDescription + " and rsa=" + rsa);
+ synchronized (importedRegistrations) {
+ org.osgi.service.remoteserviceadmin.ImportRegistration importRegistration = rsa
+ .importService(endpointDescription);
+ if (importRegistration == null) {
+ logError("handleEndpointAdded",
+ "Import registration is null for endpointDescription="
+ + endpointDescription + " and rsa=" + rsa);
+ } else
+ importedRegistrations.add(importRegistration);
}
+
}
private void handleEndpointRemoved(EndpointDescription endpointDescription) {
trace("handleEndpointRemoved", "endpointDescription="
+ endpointDescription);
// First, select importing remote service admin
- RemoteServiceAdmin rsa = selectUnimportRemoteServiceAdmin(endpointDescription);
+ org.osgi.service.remoteserviceadmin.RemoteServiceAdmin rsa = getRemoteServiceAdmin();
if (rsa == null) {
logError("handleEndpointRemoved",
"RemoteServiceAdmin not found for importing endpointDescription="
+ endpointDescription);
return;
}
- Collection<org.eclipse.ecf.osgi.services.remoteserviceadmin.ImportRegistration> unimportRegistrations = rsa
- .unimportService(endpointDescription);
+ Collection<ImportRegistration> unimportRegistrations = unimportService(endpointDescription);
trace("handleEndpointRemoved", "importRegistration="
+ unimportRegistrations + " removed for endpointDescription="
+ endpointDescription);
@@ -157,8 +164,7 @@ public class TopologyManager extends AbstractTopologyManager implements
return;
// Select remote service admin
- org.osgi.service.remoteserviceadmin.RemoteServiceAdmin rsa = selectExportRemoteServiceAdmin(
- serviceReference, exportedInterfaces);
+ org.osgi.service.remoteserviceadmin.RemoteServiceAdmin rsa = getRemoteServiceAdmin();
// if no remote service admin available, then log error and return
if (rsa == null) {
@@ -175,19 +181,22 @@ public class TopologyManager extends AbstractTopologyManager implements
exportProperties
.put(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES,
exportedInterfaces);
+ Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> registrations = null;
+ synchronized (exportedRegistrations) {
+ // Export the remote service using the selected remote service admin
+ registrations = rsa.exportService(serviceReference,
+ exportProperties);
- // Export the remote service using the selected remote service admin
- Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> registrations = rsa
- .exportService(serviceReference, exportProperties);
-
- if (registrations.size() == 0) {
- logError("handleServiceRegistered",
- "No export registrations created by RemoteServiceAdmin="
- + rsa + ". ServiceReference=" + serviceReference
- + " NOT EXPORTED");
- return;
+ if (registrations.size() == 0) {
+ logError("handleServiceRegistered",
+ "No export registrations created by RemoteServiceAdmin="
+ + rsa + ". ServiceReference="
+ + serviceReference + " NOT EXPORTED");
+ return;
+ }
+ // add them all
+ exportedRegistrations.addAll(registrations);
}
-
// publish exported registrations
for (org.osgi.service.remoteserviceadmin.ExportRegistration reg : registrations) {
advertiseEndpointDescription((EndpointDescription) reg
@@ -202,7 +211,7 @@ public class TopologyManager extends AbstractTopologyManager implements
}
private void handleServiceUnregistering(ServiceReference serviceReference) {
- RemoteServiceAdmin rsa = selectUnexportRemoteServiceAdmin(serviceReference);
+ org.osgi.service.remoteserviceadmin.RemoteServiceAdmin rsa = getRemoteServiceAdmin();
if (rsa == null) {
logError("handleServiceUnregistering",
"No RemoteServiceAdmin found for serviceReference="
@@ -210,8 +219,7 @@ public class TopologyManager extends AbstractTopologyManager implements
+ ". Remote service NOT UNEXPORTED");
return;
}
- EndpointDescription[] endpointDescriptions = rsa
- .unexportService(serviceReference);
+ EndpointDescription[] endpointDescriptions = unexportService(serviceReference);
if (endpointDescriptions != null) {
for (int i = 0; i < endpointDescriptions.length; i++) {
unadvertiseEndpointDescription(endpointDescriptions[i]);
@@ -219,4 +227,86 @@ public class TopologyManager extends AbstractTopologyManager implements
}
}
+ protected ExportRegistration[] findExportRegistrations(
+ ServiceReference serviceReference) {
+ List<ExportRegistration> results = new ArrayList<ExportRegistration>();
+ for (org.osgi.service.remoteserviceadmin.ExportRegistration reg : exportedRegistrations) {
+ ExportRegistration exportReg = (ExportRegistration) reg;
+ if (exportReg.match(serviceReference))
+ results.add(exportReg);
+ }
+ return results.toArray(new ExportRegistration[results.size()]);
+ }
+
+ protected EndpointDescription[] unexportService(
+ ServiceReference serviceReference) {
+ List<EndpointDescription> endpointDescriptions = new ArrayList<EndpointDescription>();
+ synchronized (exportedRegistrations) {
+ ExportRegistration[] exportRegs = findExportRegistrations(serviceReference);
+ if (exportRegs != null) {
+ for (int i = 0; i < exportRegs.length; i++) {
+ org.osgi.service.remoteserviceadmin.ExportReference exportRef = null;
+ try {
+ exportRef = exportRegs[i].getExportReference();
+ if (exportRef != null) {
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription = exportRef
+ .getExportedEndpoint();
+ if (endpointDescription != null
+ && endpointDescription instanceof EndpointDescription) {
+ endpointDescriptions
+ .add((EndpointDescription) endpointDescription);
+ }
+ exportRegs[i].close();
+ exportedRegistrations.remove(exportRegs[i]);
+ }
+ } catch (IllegalStateException e) {
+ // no export ref because ExportRegistration not
+ // initialized properly
+ logWarning("unexportService",
+ "IllegalStateException accessing export reference for exportRegistration="
+ + exportRegs[i]);
+ }
+ }
+ }
+ }
+ return endpointDescriptions
+ .toArray(new EndpointDescription[endpointDescriptions.size()]);
+ }
+
+ protected Collection<ImportRegistration> unimportService(
+ EndpointDescription endpointDescription) {
+ trace("unimportService", "endpointDescription=" + endpointDescription);
+ List<ImportRegistration> removedRegistrations = new ArrayList<ImportRegistration>();
+ synchronized (importedRegistrations) {
+ for (Iterator<org.osgi.service.remoteserviceadmin.ImportRegistration> i = importedRegistrations
+ .iterator(); i.hasNext();) {
+ ImportRegistration reg = (ImportRegistration) i.next();
+ ImportReference importReference = null;
+ try {
+ importReference = reg.getImportReference();
+ if (importReference != null) {
+ org.osgi.service.remoteserviceadmin.EndpointDescription importedDescription = importReference
+ .getImportedEndpoint();
+ if (importedDescription != null
+ && importedDescription
+ .equals(endpointDescription)) {
+ removedRegistrations.add(reg);
+ i.remove();
+ }
+ }
+ } catch (IllegalStateException e) {
+ // no export ref because ExportRegistration not
+ // initialized properly
+ logWarning("unimportService",
+ "IllegalStateException accessing export reference for importRegistration="
+ + reg);
+ }
+ }
+ }
+ // Now close all of them
+ for (ImportRegistration removedReg : removedRegistrations)
+ removedReg.close();
+ return removedRegistrations;
+ }
+
}

Back to the top