Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2011-05-04 15:01:51 +0000
committerslewis2011-05-04 15:01:51 +0000
commit3d37515bad1736663e73652c89b6fc8c68feab75 (patch)
tree89eaa0999a64e15ca239e6db467819f4addcc9b4
parent515e8fff7810b3043d0e680e79df4c96144644e2 (diff)
downloadorg.eclipse.ecf-3d37515bad1736663e73652c89b6fc8c68feab75.tar.gz
org.eclipse.ecf-3d37515bad1736663e73652c89b6fc8c68feab75.tar.xz
org.eclipse.ecf-3d37515bad1736663e73652c89b6fc8c68feab75.zip
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=344713 and
https://bugs.eclipse.org/bugs/show_bug.cgi?id=344716
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java17
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java1
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java59
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java112
4 files changed, 102 insertions, 87 deletions
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
index fc883f9dd..99ce0c5c7 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
@@ -128,13 +128,11 @@ public class Activator implements BundleActivator {
.getName(), new ServiceFactory() {
public Object getService(Bundle bundle,
ServiceRegistration registration) {
- return new RemoteServiceAdmin(bundle);
+ return getRemoteServiceAdmin(bundle);
}
public void ungetService(Bundle bundle,
ServiceRegistration registration, Object service) {
- if (service != null)
- ((RemoteServiceAdmin) service).close();
}
}, (Dictionary) rsaProps);
@@ -154,6 +152,15 @@ public class Activator implements BundleActivator {
// start endpointDescriptionLocator
endpointDescriptionLocator.start();
}
+
+ private RemoteServiceAdmin remoteServiceAdmin;
+
+ private RemoteServiceAdmin getRemoteServiceAdmin(Bundle bundle) {
+ if (remoteServiceAdmin == null) {
+ remoteServiceAdmin = new RemoteServiceAdmin(bundle);
+ }
+ return remoteServiceAdmin;
+ }
/*
* (non-Javadoc)
@@ -170,6 +177,10 @@ public class Activator implements BundleActivator {
remoteServiceAdminRegistration.unregister();
remoteServiceAdminRegistration = null;
}
+ if (remoteServiceAdmin != null) {
+ remoteServiceAdmin.close();
+ remoteServiceAdmin = null;
+ }
if (endpointDescriptionAdvertiserRegistration != null) {
endpointDescriptionAdvertiserRegistration.unregister();
endpointDescriptionAdvertiserRegistration = null;
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java
index e1e5236f0..6208de4c6 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java
@@ -61,7 +61,6 @@ public class PropertiesUtil {
RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE,
RemoteConstants.ENDPOINT_IDFILTER_IDS,
RemoteConstants.ENDPOINT_REMOTESERVICE_FILTER,
- RemoteConstants.ENDPOINT_SERVICE_IMPORTED_CONFIGS_VALUE,
RemoteConstants.SERVICE_EXPORTED_CONTAINER_CONNECT_CONTEXT,
RemoteConstants.SERVICE_EXPORTED_CONTAINER_FACTORY_ARGS,
RemoteConstants.SERVICE_EXPORTED_CONTAINER_ID,
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java
index 5262d1398..1698795f2 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ConsumerContainerSelector.java
@@ -9,7 +9,10 @@
******************************************************************************/
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.PropertiesUtil;
import org.eclipse.ecf.remoteservice.IRemoteServiceContainer;
/**
@@ -29,33 +32,47 @@ public class ConsumerContainerSelector extends
EndpointDescription endpointDescription) {
trace("selectConsumerContainers", "endpointDescription=" + endpointDescription); //$NON-NLS-1$ //$NON-NLS-2$
- // Get the endpointID
- ID endpointContainerID = endpointDescription.getContainerID();
+ // Get service.imported.configs
+ List<String> serviceImportedConfigs = PropertiesUtil
+ .getStringPlusProperty(
+ endpointDescription.getProperties(),
+ org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED_CONFIGS);
+ // For ECF providers this endpoint description property should always contain the constant
+ // org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants.ENDPOINT_SERVICE_IMPORTED_CONFIGS_VALUE
+ if (serviceImportedConfigs
+ .contains(RemoteConstants.ENDPOINT_SERVICE_IMPORTED_CONFIGS_VALUE)) {
+ // Get the endpointID
+ ID endpointContainerID = endpointDescription.getContainerID();
- String[] remoteSupportedConfigs = (String[]) endpointDescription
- .getProperties()
- .get(org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED);
+ String[] remoteSupportedConfigs = (String[]) endpointDescription
+ .getProperties()
+ .get(org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED);
- // Get connect targetID
- ID connectTargetID = endpointDescription.getConnectTargetID();
+ // Get connect targetID
+ ID connectTargetID = endpointDescription.getConnectTargetID();
- IRemoteServiceContainer rsContainer = selectExistingConsumerContainer(
- endpointContainerID, remoteSupportedConfigs, connectTargetID);
+ IRemoteServiceContainer rsContainer = selectExistingConsumerContainer(
+ endpointContainerID, remoteSupportedConfigs,
+ connectTargetID);
- // If we haven't found any existing containers then we create one
- // from the remoteSupportedConfigs...*iff* autoCreateContainer is
- // set to true
- if (rsContainer == null && autoCreateContainer)
- rsContainer = createAndConfigureConsumerContainer(
- remoteSupportedConfigs, endpointDescription.getProperties());
+ // If we haven't found any existing containers then we create one
+ // from the remoteSupportedConfigs...*iff* autoCreateContainer is
+ // set to true
+ if (rsContainer == null && autoCreateContainer)
+ rsContainer = createAndConfigureConsumerContainer(
+ remoteSupportedConfigs,
+ endpointDescription.getProperties());
- // Get the connect target ID from the endpointDescription
- // and connect the given containers to the connect targetID
- // This is only needed when when the endpointID is different from
- // the connect targetID, and the containers are not already connected
- connectContainerToTarget(rsContainer, connectTargetID);
+ // Get the connect target ID from the endpointDescription
+ // and connect the given containers to the connect targetID
+ // This is only needed when when the endpointID is different from
+ // the connect targetID, and the containers are not already
+ // connected
+ connectContainerToTarget(rsContainer, connectTargetID);
- return rsContainer;
+ return rsContainer;
+ }
+ return null;
}
public void close() {
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
index e8e598aaf..cce1a9351 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
@@ -172,7 +172,8 @@ public class RemoteServiceAdmin implements
: overridingProperties);
// First get exported interfaces
- String[] exportedInterfaces = PropertiesUtil.getExportedInterfaces(serviceReference,overridingProperties);
+ String[] exportedInterfaces = PropertiesUtil.getExportedInterfaces(
+ serviceReference, overridingProperties);
if (exportedInterfaces == null)
throw new IllegalArgumentException(
org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES
@@ -435,7 +436,6 @@ public class RemoteServiceAdmin implements
private EndpointDescription endpointDescription;
private IRemoteServiceRegistration rsRegistration;
- private ExportReference exportReference;
private Set<ExportRegistration> exportRegistrations = new HashSet<ExportRegistration>();
private Throwable exception;
@@ -447,11 +447,8 @@ public class RemoteServiceAdmin implements
this.serviceReference = serviceReference;
Assert.isNotNull(endpointDescription);
this.endpointDescription = endpointDescription;
-
Assert.isNotNull(reg);
this.rsRegistration = reg;
- this.exportReference = new ExportReference(serviceReference,
- endpointDescription);
}
ExportEndpoint(ServiceReference serviceReference,
@@ -479,10 +476,6 @@ public class RemoteServiceAdmin implements
return endpointDescription;
}
- synchronized ExportReference getExportReference() {
- return exportReference;
- }
-
synchronized IRemoteServiceRegistration getRemoteServiceRegistration() {
return rsRegistration;
}
@@ -499,17 +492,14 @@ public class RemoteServiceAdmin implements
rsRegistration.unregister();
rsRegistration = null;
}
- if (exportReference != null) {
- exportReference.close();
- exportReference = null;
- }
+ serviceReference = null;
+ endpointDescription = null;
}
return removed;
}
public synchronized String toString() {
- return "ExportEndpoint[rsRegistration=" + rsRegistration //$NON-NLS-1$
- + ", exportReference=" + exportReference + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ return "ExportEndpoint[rsRegistration=" + rsRegistration + "]"; //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -518,12 +508,17 @@ public class RemoteServiceAdmin implements
org.osgi.service.remoteserviceadmin.ExportRegistration {
private ExportEndpoint exportEndpoint;
+ private ExportReference exportReference;
ExportRegistration(ExportEndpoint exportEndpoint) {
Assert.isNotNull(exportEndpoint);
this.exportEndpoint = exportEndpoint;
// Add ourselves to this exported endpoint
this.exportEndpoint.add(this);
+ ServiceReference sr = this.exportEndpoint.getServiceReference();
+ EndpointDescription ed = this.exportEndpoint
+ .getEndpointDescription();
+ this.exportReference = new ExportReference(sr, ed);
}
synchronized ID getContainerID() {
@@ -542,8 +537,7 @@ public class RemoteServiceAdmin implements
throw new IllegalStateException(
"Cannot get export reference as export registration is invalid", //$NON-NLS-1$
t);
- return (exportEndpoint == null) ? null : exportEndpoint
- .getExportReference();
+ return exportReference;
}
synchronized boolean match(ServiceReference serviceReference) {
@@ -584,28 +578,29 @@ public class RemoteServiceAdmin implements
}
public void close() {
- boolean closed = false;
+ boolean publish = false;
Throwable t = null;
- org.osgi.service.remoteserviceadmin.ExportReference exportReference = null;
EndpointDescription endpointDescription = null;
synchronized (this) {
if (exportEndpoint != null) {
t = getException();
- exportReference = (t == null) ? getExportReference() : null;
endpointDescription = getEndpointDescription();
- closed = exportEndpoint.close(this);
+ exportEndpoint.close(this);
exportEndpoint = null;
+ publish = true;
}
}
- if (closed) {
- removeExportRegistration(this);
+ exportReference.close();
+ removeExportRegistration(this);
+ Bundle clientBundle = getClientBundle();
+ // Only publish events
+ if (publish && clientBundle != null)
publishEvent(
new RemoteServiceAdminEvent(
endpointDescription.getContainerID(),
RemoteServiceAdminEvent.EXPORT_UNREGISTRATION,
- getClientBundle(), exportReference, t),
+ clientBundle, exportReference, t),
endpointDescription);
- }
}
public synchronized Throwable getException() {
@@ -658,7 +653,6 @@ public class RemoteServiceAdmin implements
private IRemoteServiceListener rsListener;
private IRemoteServiceReference rsReference;
private ServiceRegistration proxyRegistration;
- private ImportReference importReference;
private Set<ImportRegistration> importRegistrations = new HashSet<ImportRegistration>();
private Throwable exception;
@@ -673,8 +667,6 @@ public class RemoteServiceAdmin implements
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
@@ -696,6 +688,10 @@ public class RemoteServiceAdmin implements
return endpointDescription;
}
+ synchronized ServiceRegistration getProxyRegistration() {
+ return proxyRegistration;
+ }
+
synchronized Throwable getException() {
return exception;
}
@@ -729,18 +725,11 @@ public class RemoteServiceAdmin implements
}
rsContainerAdapter = null;
}
- if (importReference != null) {
- importReference.close();
- importReference = null;
- }
+ endpointDescription = null;
}
return removed;
}
- synchronized ImportReference getImportReference() {
- return importReference;
- }
-
synchronized boolean match(IRemoteServiceID remoteServiceID) {
if (remoteServiceID == null || rsReference == null)
return false;
@@ -749,18 +738,13 @@ public class RemoteServiceAdmin implements
public synchronized String toString() {
return "ImportEndpoint[rsReference=" + rsReference //$NON-NLS-1$
- + ", proxyRegistration=" + proxyRegistration //$NON-NLS-1$
- + ", importReference=" + importReference + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ + ", proxyRegistration=" + proxyRegistration + "]"; //$NON-NLS-1$ //$NON-NLS-2$
}
synchronized boolean match(EndpointDescription ed) {
- if (importReference == null)
+ if (importRegistrations.size() == 0)
return false;
- EndpointDescription importedEndpoint = (EndpointDescription) importReference
- .getImportedEndpoint();
- if (importedEndpoint == null)
- return false;
- return importedEndpoint.isSameService(ed);
+ return this.endpointDescription.isSameService(ed);
}
}
@@ -769,11 +753,15 @@ public class RemoteServiceAdmin implements
org.osgi.service.remoteserviceadmin.ImportRegistration {
private ImportEndpoint importEndpoint;
+ private ImportReference importReference;
ImportRegistration(ImportEndpoint importEndpoint) {
- Assert.isNotNull(importEndpoint);
this.importEndpoint = importEndpoint;
this.importEndpoint.add(this);
+ ServiceRegistration sr = this.importEndpoint.getProxyRegistration();
+ EndpointDescription ed = this.importEndpoint
+ .getEndpointDescription();
+ this.importReference = new ImportReference(sr.getReference(), ed);
}
synchronized ID getContainerID() {
@@ -806,33 +794,33 @@ public class RemoteServiceAdmin implements
throw new IllegalStateException(
"Cannot get import reference as registration not properly initialized", //$NON-NLS-1$
t);
- return importEndpoint == null ? null : importEndpoint
- .getImportReference();
+ return importReference;
}
public void close() {
- boolean closed = false;
- org.osgi.service.remoteserviceadmin.ImportReference importReference = null;
- EndpointDescription endpointDescription = null;
Throwable t = null;
+ EndpointDescription endpointDescription = null;
+ boolean publish = false;
synchronized (this) {
if (importEndpoint != null) {
t = getException();
- importReference = (t == null) ? getImportReference() : null;
endpointDescription = getEndpointDescription();
- closed = importEndpoint.close(this);
+ importEndpoint.close(this);
importEndpoint = null;
+ publish = true;
}
}
- if (closed) {
- removeImportRegistration(this);
+ importReference.close();
+ removeImportRegistration(this);
+ Bundle clientBundle = getClientBundle();
+ if (publish && clientBundle != null)
publishEvent(
new RemoteServiceAdminEvent(
endpointDescription.getContainerID(),
RemoteServiceAdminEvent.IMPORT_UNREGISTRATION,
- getClientBundle(), importReference, t),
+ clientBundle, importReference, t),
endpointDescription);
- }
+
}
public synchronized Throwable getException() {
@@ -899,8 +887,9 @@ public class RemoteServiceAdmin implements
EndpointDescription endpointDescription) {
EventAdmin eventAdmin = getEventAdmin();
if (eventAdmin == null) {
- logWarning("postEvent", "No event admin available to post event=" //$NON-NLS-1$ //$NON-NLS-2$
- + event);
+ logError(
+ "RemoteServiceAdmin.postEvent", "No event admin service available to post event=" //$NON-NLS-1$ //$NON-NLS-2$
+ + event);
return;
}
int eventType = event.getType();
@@ -1253,12 +1242,13 @@ public class RemoteServiceAdmin implements
endpointDescriptionProperties
.put(org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED,
remoteConfigsSupported);
- // SERVICE_IMPORTED_CONFIGS...set to same value as remote configs
+ // SERVICE_IMPORTED_CONFIGS...set to constant value for all ECF
+ // providers
// supported (which is computed
// for the exporting ECF container
endpointDescriptionProperties
.put(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED_CONFIGS,
- remoteConfigsSupported);
+ RemoteConstants.ENDPOINT_SERVICE_IMPORTED_CONFIGS_VALUE);
// SERVICE_INTENTS
Object intents = PropertiesUtil
@@ -1528,8 +1518,6 @@ public class RemoteServiceAdmin implements
public void ungetService(Bundle bundle,
ServiceRegistration registration, Object service) {
ungetProxyClassLoader(bundle);
- this.remoteService = null;
- this.interfaceVersions = null;
}
}

Back to the top