Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=499946
Change-Id: I0000000000000000000000000000000000000000
diff --git a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/ChannelEndpointImpl.java b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/ChannelEndpointImpl.java
index 33d50af..e5e9104 100644
--- a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/ChannelEndpointImpl.java
+++ b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/ChannelEndpointImpl.java
@@ -1126,7 +1126,7 @@
final LeaseMessage lease = (LeaseMessage) msg;
processLease(lease);
- populateLease(lease, RemoteOSGiServiceImpl.getServices(),
+ populateLease(lease, RemoteOSGiServiceImpl.getServices(networkChannel.getProtocol()),
RemoteOSGiServiceImpl.getTopics());
return lease;
}
diff --git a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.java b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.java
index 0fc077d..7425764 100644
--- a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.java
+++ b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.java
@@ -44,6 +44,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -488,11 +489,12 @@
final ServiceDiscoveryHandler handler = (ServiceDiscoveryHandler) context
.getService(reference);
- final RemoteServiceRegistration[] regs = (RemoteServiceRegistration[]) serviceRegistrations
- .values()
- .toArray(
- new RemoteServiceRegistration[serviceRegistrations
- .size()]);
+ RemoteServiceRegistration[] regs = null;
+
+ synchronized (serviceRegistrations) {
+ regs = (RemoteServiceRegistration[]) serviceRegistrations.values()
+ .toArray(new RemoteServiceRegistration[serviceRegistrations.size()]);
+ }
for (int i = 0; i < regs.length; i++) {
handler
@@ -556,7 +558,9 @@
+ " AS PROXIED SERVICES"); //$NON-NLS-1$
}
- serviceRegistrations.put(service, reg);
+ synchronized (serviceRegistrations) {
+ serviceRegistrations.put(service, reg);
+ }
registerWithServiceDiscovery(reg);
@@ -722,7 +726,7 @@
final NetworkChannelFactory factory = getNetworkChannelFactory(protocol);
channel = new ChannelEndpointImpl(factory, endpoint);
- return channel.sendLease(getServices(), getTopics());
+ return channel.sendLease(getServices(endpoint.getScheme()), getTopics());
}
/**
@@ -996,11 +1000,17 @@
*
* @return return the services.
*/
- static RemoteServiceRegistration[] getServices() {
- return (RemoteServiceRegistration[]) serviceRegistrations.values()
- .toArray(
- new RemoteServiceRegistration[serviceRegistrations
- .size()]);
+ static RemoteServiceRegistration[] getServices(String transport) {
+ List results = new ArrayList();
+ synchronized (serviceRegistrations) {
+ for (Iterator i = serviceRegistrations.keySet().iterator(); i.hasNext();) {
+ ServiceReference ref = (ServiceReference) i.next();
+ Object propVal = ref.getProperty(RemoteOSGiService.R_OSGi_REGISTRATION);
+ if (transport == null || propVal == null || propVal.equals(transport))
+ results.add(serviceRegistrations.get(ref));
+ }
+ }
+ return (RemoteServiceRegistration[]) results.toArray(new RemoteServiceRegistration[results.size()]);
}
/**
@@ -1023,8 +1033,9 @@
}
return null;
}
- return (RemoteServiceRegistration) serviceRegistrations
- .get(refs[0]);
+ synchronized (serviceRegistrations) {
+ return (RemoteServiceRegistration) serviceRegistrations.get(refs[0]);
+ }
} catch (final InvalidSyntaxException e) {
e.printStackTrace();
return null;
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
index 4ff69d3..39e818f 100644
--- a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
@@ -71,6 +71,9 @@
// Connect context to use for connect calls
private IConnectContext connectContext;
+ // New system property to allow the per-transport exposure of remote services to be defeated.
+ private boolean exposeRemoteServicesOnAllTransports = Boolean.parseBoolean(System.getProperty("org.eclipse.ecf.internal.provider.r_osgi.exposeRemoteServicesOnAllTransports", "false")); //$NON-NLS-1$ //$NON-NLS-2$
+
public R_OSGiRemoteServiceContainer(RemoteOSGiService service, final ID containerID) throws IDCreateException {
Assert.isNotNull(service);
Assert.isNotNull(containerID);
@@ -444,6 +447,14 @@
final Dictionary props = properties == null ? new Hashtable() : clone(properties);
+ R_OSGiNamespace ns = (R_OSGiNamespace) containerID.getNamespace();
+ // add the hint property for R-OSGi that this service is intended to be
+ // accessed remotely.
+ Object rosgiRegistrationValue = Boolean.TRUE;
+ if (!exposeRemoteServicesOnAllTransports)
+ rosgiRegistrationValue = (ns instanceof R_OSGiWSSNamespace) ? "https" : (ns instanceof R_OSGiWSNamespace) ? "http" : "r-osgi"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+
+ props.put(RemoteOSGiService.R_OSGi_REGISTRATION, rosgiRegistrationValue);
// add the hint property for R-OSGi that this service is intended to be
// accessed remotely.
props.put(RemoteOSGiService.R_OSGi_REGISTRATION, Boolean.TRUE);