Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-04-11 01:41:42 +0000
committerslewis2009-04-11 01:41:42 +0000
commitae149b67880dda6dc74cd0cdf68fb27f754100bc (patch)
tree34dc5f19260d1f29becb6e484a631a9401bc90ed /compendium
parent7bf845c6f65e2fbc762011a9dc65bb15c08dfd30 (diff)
downloadorg.eclipse.ecf-ae149b67880dda6dc74cd0cdf68fb27f754100bc.tar.gz
org.eclipse.ecf-ae149b67880dda6dc74cd0cdf68fb27f754100bc.tar.xz
org.eclipse.ecf-ae149b67880dda6dc74cd0cdf68fb27f754100bc.zip
Rename ServicePublication, service constants, and service endpoint description
Diffstat (limited to 'compendium')
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF2
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java8
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java38
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ContainerAdapterHelper.java41
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java375
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/EventHookImpl.java30
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IRemoteServiceContainerFinder.java44
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IServiceConstants.java (renamed from compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ECFServiceConstants.java)2
8 files changed, 344 insertions, 196 deletions
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF
index 3f063d609..8eb31d0c8 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF
@@ -9,6 +9,8 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.4
Import-Package: org.eclipse.ecf.core,
org.eclipse.ecf.core.identity,
org.eclipse.ecf.core.util,
+ org.eclipse.ecf.discovery;version="3.0.0",
+ org.eclipse.ecf.discovery.identity,
org.eclipse.ecf.osgi.services.discovery;version="1.0.0",
org.eclipse.ecf.remoteservice,
org.eclipse.ecf.remoteservice.events,
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java
index 080dec387..c10b1773d 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java
@@ -13,7 +13,7 @@ import java.util.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.util.Trace;
-import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants;
+import org.eclipse.ecf.osgi.services.distribution.IServiceConstants;
import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
import org.osgi.framework.*;
import org.osgi.framework.hooks.service.EventHook;
@@ -68,7 +68,7 @@ public abstract class AbstractEventHookImpl implements EventHook {
// This checks to see if the serviceReference has any remote interfaces
// declared via osgi.remote.interfaces property
Object osgiRemotes = serviceReference
- .getProperty(ECFServiceConstants.OSGI_REMOTE_INTERFACES);
+ .getProperty(IServiceConstants.OSGI_REMOTE_INTERFACES);
// If osgi.remote.interfaces required property is non-null then we
// handle further, if null then ignore the service registration event
if (osgiRemotes != null) {
@@ -98,7 +98,7 @@ public abstract class AbstractEventHookImpl implements EventHook {
}
// Now get optional service property osgi.remote.configuration.type
Object osgiRemoteConfigurationType = serviceReference
- .getProperty(ECFServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE);
+ .getProperty(IServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE);
// The osgiRemoteConfigurationType is optional and can be null. If
// non-null, it should be of type String [] according to RFC119...if
// it's non-null and not String [] we ignore
@@ -208,7 +208,7 @@ public abstract class AbstractEventHookImpl implements EventHook {
.getProperty(Constants.OBJECTCLASS));
for (int i = 0; i < remoteInterfaces.length; i++) {
String intf = remoteInterfaces[i];
- if (ECFServiceConstants.OSGI_REMOTE_INTERFACES_WILDCARD
+ if (IServiceConstants.OSGI_REMOTE_INTERFACES_WILDCARD
.equals(intf))
return (String[]) interfaces.toArray(new String[] {});
if (intf != null && interfaces.contains(intf))
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
index 07b5d6da4..2bfe67241 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
@@ -9,13 +9,14 @@
******************************************************************************/
package org.eclipse.ecf.internal.osgi.services.distribution;
-import java.util.Dictionary;
-import java.util.Hashtable;
+import java.util.*;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.ecf.core.IContainerManager;
import org.eclipse.ecf.core.util.*;
-import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants;
+import org.eclipse.ecf.osgi.services.distribution.IRemoteServiceContainerFinder;
+import org.eclipse.ecf.osgi.services.distribution.IServiceConstants;
+import org.eclipse.equinox.concurrent.future.ThreadsExecutor;
import org.osgi.framework.*;
import org.osgi.framework.hooks.service.EventHook;
import org.osgi.service.discovery.DiscoveredServiceTracker;
@@ -37,12 +38,15 @@ public class Activator implements BundleActivator {
private ServiceRegistration eventHookRegistration;
private ServiceRegistration distributionProviderRegistration;
private ServiceRegistration discoveredServiceTrackerRegistration;
+ private ServiceRegistration rsContainerFinderRegistration;
private ServiceTracker logServiceTracker = null;
private LogService logService = null;
private ServiceTracker adapterManagerTracker;
+ private ServiceTracker rsContainerFinderTracker;
+
public static Activator getDefault() {
return plugin;
}
@@ -100,10 +104,13 @@ public class Activator implements BundleActivator {
}
private void addDiscoveredServiceTracker() {
+ DiscoveredServiceTrackerImpl dstImpl = new DiscoveredServiceTrackerImpl(
+ this.distributionProvider, new ThreadsExecutor());
this.discoveredServiceTrackerRegistration = this.context
.registerService(DiscoveredServiceTracker.class.getName(),
- new DiscoveredServiceTrackerImpl(
- this.distributionProvider), null);
+ dstImpl, null);
+ this.rsContainerFinderRegistration = this.context.registerService(
+ IRemoteServiceContainerFinder.class.getName(), dstImpl, null);
}
private void addServiceRegistryHooks() {
@@ -115,7 +122,7 @@ public class Activator implements BundleActivator {
// register all existing services which have the marker property
try {
final ServiceReference[] refs = this.context.getServiceReferences(
- null, "(" + ECFServiceConstants.OSGI_REMOTE_INTERFACES
+ null, "(" + IServiceConstants.OSGI_REMOTE_INTERFACES
+ "=*)");
if (refs != null) {
for (int i = 0; i < refs.length; i++) {
@@ -161,6 +168,10 @@ public class Activator implements BundleActivator {
this.discoveredServiceTrackerRegistration.unregister();
this.discoveredServiceTrackerRegistration = null;
}
+ if (this.rsContainerFinderRegistration != null) {
+ this.rsContainerFinderRegistration.unregister();
+ this.rsContainerFinderRegistration = null;
+ }
}
/*
@@ -190,6 +201,10 @@ public class Activator implements BundleActivator {
distributionProvider.dispose();
distributionProvider = null;
}
+ if (rsContainerFinderTracker != null) {
+ rsContainerFinderTracker.close();
+ rsContainerFinderTracker = null;
+ }
this.context = null;
plugin = null;
}
@@ -203,6 +218,17 @@ public class Activator implements BundleActivator {
return (IContainerManager) containerManagerTracker.getService();
}
+ public synchronized IRemoteServiceContainerFinder[] getRemoteServiceContainerFinders() {
+ if (rsContainerFinderTracker == null) {
+ rsContainerFinderTracker = new ServiceTracker(this.context,
+ IRemoteServiceContainerFinder.class.getName(), null);
+ rsContainerFinderTracker.open();
+ }
+ Object[] svcs = (Object[]) rsContainerFinderTracker.getServices();
+ return (IRemoteServiceContainerFinder[]) Arrays.asList(svcs).toArray(
+ new IRemoteServiceContainerFinder[] {});
+ }
+
public IAdapterManager getAdapterManager() {
// First, try to get the adapter manager via
if (adapterManagerTracker == null) {
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ContainerAdapterHelper.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ContainerAdapterHelper.java
deleted file mode 100644
index e938706e3..000000000
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ContainerAdapterHelper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
-/**
- *
- */
-package org.eclipse.ecf.internal.osgi.services.distribution;
-
-import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
-
-class ContainerAdapterHelper {
- private IContainer container;
- private IRemoteServiceContainerAdapter containerAdapter;
-
- public ContainerAdapterHelper(IContainer c, IRemoteServiceContainerAdapter rsca) {
- this.container = c;
- this.containerAdapter = rsca;
- }
-
- public IContainer getContainer() {
- return container;
- }
-
- public IRemoteServiceContainerAdapter getRSCA() {
- return containerAdapter;
- }
-
- public String toString() {
- StringBuffer buf = new StringBuffer("ContainerAdapterHelper[");
- buf.append("containerID=").append(getContainer().getID());
- buf.append(";rsca=").append(getRSCA()).append("]");
- return buf.toString();
- }
-} \ No newline at end of file
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java
index a9aff1d54..4492056cc 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java
@@ -9,30 +9,63 @@
******************************************************************************/
package org.eclipse.ecf.internal.osgi.services.distribution;
+import java.net.URI;
import java.util.*;
import org.eclipse.core.runtime.*;
-import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.core.IContainerManager;
+import org.eclipse.ecf.core.*;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.util.Trace;
-import org.eclipse.ecf.osgi.services.discovery.ECFServiceEndpointDescription;
-import org.eclipse.ecf.osgi.services.discovery.ECFServicePublication;
-import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants;
+import org.eclipse.ecf.discovery.identity.IServiceID;
+import org.eclipse.ecf.osgi.services.discovery.*;
+import org.eclipse.ecf.osgi.services.distribution.IRemoteServiceContainerFinder;
+import org.eclipse.ecf.osgi.services.distribution.IServiceConstants;
import org.eclipse.ecf.remoteservice.*;
import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent;
import org.eclipse.ecf.remoteservice.events.IRemoteServiceUnregisteredEvent;
-import org.eclipse.equinox.concurrent.future.IFuture;
-import org.eclipse.equinox.concurrent.future.TimeoutException;
+import org.eclipse.equinox.concurrent.future.IExecutor;
+import org.eclipse.equinox.concurrent.future.IProgressRunnable;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.discovery.*;
-public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
+public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker,
+ IRemoteServiceContainerFinder {
DistributionProviderImpl distributionProvider;
+ IExecutor executor;
+ IProgressMonitor executorProgressMonitor;
- public DiscoveredServiceTrackerImpl(DistributionProviderImpl dp) {
+ List serviceLocations = new ArrayList();
+
+ private boolean addServiceURI(URI serviceLocation) {
+ if (serviceLocation == null)
+ return false;
+ synchronized (serviceLocation) {
+ return serviceLocations.add(serviceLocation);
+ }
+ }
+
+ private boolean removeServiceURI(URI serviceLocation) {
+ if (serviceLocation == null)
+ return false;
+ synchronized (serviceLocations) {
+ return serviceLocations.remove(serviceLocation);
+ }
+ }
+
+ private boolean containsServiceURI(URI serviceLocation) {
+ if (serviceLocation == null)
+ return false;
+ synchronized (serviceLocations) {
+ return serviceLocations.contains(serviceLocation);
+ }
+ }
+
+ public DiscoveredServiceTrackerImpl(DistributionProviderImpl dp,
+ IExecutor executor) {
this.distributionProvider = dp;
+ this.executor = executor;
}
// <Map<containerID><RemoteServiceRegistration>
@@ -42,12 +75,20 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
List ecfRemoteServiceProperties = Arrays.asList(new String[] {
Constants.SERVICE_ID, Constants.OBJECTCLASS,
- ECFServicePublication.PROP_KEY_ENDPOINT_ID,
- ECFServicePublication.PROP_KEY_ENDPOINT_INTERFACE_NAME,
- ECFServicePublication.PROP_KEY_ENDPOINT_LOCATION,
- ECFServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME,
- ECFServicePublication.PROP_KEY_SERVICE_INTERFACE_VERSION,
- ECFServicePublication.PROP_KEY_SERVICE_PROPERTIES });
+ IServicePublication.PROP_KEY_ENDPOINT_ID,
+ IServicePublication.PROP_KEY_ENDPOINT_INTERFACE_NAME,
+ IServicePublication.PROP_KEY_ENDPOINT_LOCATION,
+ IServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME,
+ IServicePublication.PROP_KEY_SERVICE_INTERFACE_VERSION,
+ IServicePublication.PROP_KEY_SERVICE_PROPERTIES });
+
+ // Impl of IRemoteServiceContainerFinder
+ public IRemoteServiceContainer[] findRemoteServiceContainers(
+ IServiceEndpointDescription endpointDescription,
+ IProgressMonitor monitor) {
+ return findRSCAs(endpointDescription.getECFEndpointID(),
+ endpointDescription);
+ }
/*
* (non-Javadoc)
@@ -56,7 +97,7 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
* org.osgi.service.discovery.DiscoveredServiceTracker#serviceChanged(org
* .osgi.service.discovery.DiscoveredServiceNotification)
*/
- public void serviceChanged(DiscoveredServiceNotification notification) {
+ public void serviceChanged(final DiscoveredServiceNotification notification) {
if (notification == null) {
logWarning("serviceChanged",
"DiscoveredServiceNotification is null. Ignoring");
@@ -65,12 +106,69 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
int notificationType = notification.getType();
switch (notificationType) {
case DiscoveredServiceNotification.AVAILABLE:
- handleDiscoveredServiceAvailable(notification
- .getServiceEndpointDescription());
+ ECFServiceEndpointDescription adesc = null;
+ try {
+ // If the service endpoint description is not ECF's then we
+ // don't process it
+ adesc = getECFserviceEndpointDescription(notification
+ .getServiceEndpointDescription());
+ } catch (Exception e) {
+ logError("serviceChanged.AVAILABLE",
+ "Error creating ECF endpoint description", e);
+ return;
+ }
+ // If it's not for us then return
+ if (adesc == null)
+ return;
+
+ IServiceID serviceID = adesc.getServiceID();
+ if (!isValidService(serviceID)) {
+ logWarning("serviceChanged.AVAILABLE",
+ "Invalid/possibly duplicate serviceID=" + serviceID);
+ return;
+ }
+ final ECFServiceEndpointDescription ecfASED = adesc;
+ // Otherwise execute with executor
+ this.executor.execute(new IProgressRunnable() {
+ public Object run(IProgressMonitor monitor) throws Exception {
+ try {
+ handleDiscoveredServiceAvailable(ecfASED, monitor);
+ } catch (Exception e) {
+ logError("handleDiscoveredServiceAvailble",
+ "Unexpected exception with ecfSED=" + ecfASED,
+ e);
+ throw e;
+ }
+ return null;
+ }
+ }, new NullProgressMonitor());
break;
case DiscoveredServiceNotification.UNAVAILABLE:
- handleDiscoveredServiceUnavailable(notification
- .getServiceEndpointDescription());
+ try {
+ ECFServiceEndpointDescription udesc = getECFserviceEndpointDescription(notification
+ .getServiceEndpointDescription());
+ // If it's not for us then return
+ if (udesc == null)
+ return;
+
+ // Remove existing proxy service registrations that correspond
+ // to the
+ // given serviceID
+ ServiceRegistration[] proxyServiceRegistrations = removeProxyServiceRegistrations(udesc);
+ // Then unregister them
+ if (proxyServiceRegistrations != null) {
+ for (int i = 0; i < proxyServiceRegistrations.length; i++) {
+ trace("handleDiscoveredServiceUnavailable",
+ "proxyServiceRegistrations="
+ + proxyServiceRegistrations[i]
+ + ",serviceEndpointDesc=" + udesc);
+ unregisterProxyServiceRegistration(proxyServiceRegistrations[i]);
+ }
+ removeServiceURI(udesc.getServiceID().getLocation());
+ }
+ } catch (Exception e) {
+ logError("serviceChanged", "UNAVAILABLE", e);
+ }
break;
case DiscoveredServiceNotification.MODIFIED:
// Do nothing for now
@@ -85,70 +183,132 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
}
}
- private void handleDiscoveredServiceUnavailable(
- ServiceEndpointDescription sed) {
- // If the service endpoint description is not ECF's then we
- // don't process it
- ECFServiceEndpointDescription ecfSED = getECFserviceEndpointDescription(sed);
- if (ecfSED == null) {
- return;
- }
- // Remove existing proxy service registrations that correspond to the
- // given serviceID
- ServiceRegistration[] proxyServiceRegistrations = removeProxyServiceRegistrations(ecfSED);
- // Then unregister them
- if (proxyServiceRegistrations != null) {
- for (int i = 0; i < proxyServiceRegistrations.length; i++) {
- trace("handleDiscoveredServiceUnavailable",
- "proxyServiceRegistrations="
- + proxyServiceRegistrations[i]
- + ",serviceEndpointDesc=" + ecfSED);
- unregisterProxyServiceRegistration(proxyServiceRegistrations[i]);
+ private boolean isValidService(IServiceID serviceID) {
+ if (serviceID == null)
+ return false;
+ URI location = serviceID.getLocation();
+ if (location == null)
+ return false;
+ synchronized (serviceLocations) {
+ if (containsServiceURI(location)) {
+ return false;
+ } else {
+ addServiceURI(location);
+ return true;
}
}
}
- private void handleDiscoveredServiceAvailable(ServiceEndpointDescription sed) {
- // If the service endpoint description is not ECF's then we
- // don't process it
- ECFServiceEndpointDescription ecfSED = getECFserviceEndpointDescription(sed);
- if (ecfSED == null) {
- return;
+ private IRemoteServiceContainer[] findRemoteServiceContainersViaService(
+ IServiceEndpointDescription description, IProgressMonitor monitor) {
+ Activator activator = Activator.getDefault();
+ if (activator == null)
+ return new IRemoteServiceContainer[0];
+ IRemoteServiceContainerFinder[] finders = activator
+ .getRemoteServiceContainerFinders();
+ if (finders == null || finders.length == 0) {
+ logError("findRemoteServiceContainersViaService",
+ "No container finders available");
+ return new IRemoteServiceContainer[0];
+ }
+ List result = new ArrayList();
+ for (int i = 0; i < finders.length; i++) {
+ IRemoteServiceContainer[] foundRSContainers = finders[i]
+ .findRemoteServiceContainers(description, monitor);
+ if (foundRSContainers != null && foundRSContainers.length > 0) {
+ trace("findRemoteServiceContainersViaService",
+ "findRemoteServiceContainers finder=" + finders[i]
+ + " ecfSED=" + description
+ + " foundRSContainers="
+ + Arrays.asList(foundRSContainers));
+ for (int j = 0; j < foundRSContainers.length; j++)
+ result.add(foundRSContainers[j]);
+ }
}
+ return (IRemoteServiceContainer[]) result
+ .toArray(new IRemoteServiceContainer[] {});
+ }
- ID endpointID = ecfSED.getECFEndpointID();
- // Find RSCAs for the given description
- ContainerAdapterHelper[] cahs = findRSCAs(endpointID, ecfSED);
- if (cahs == null || cahs.length == 0) {
+ private void handleDiscoveredServiceAvailable(
+ ECFServiceEndpointDescription ecfSED, IProgressMonitor monitor) {
+ // Find IRemoteServiceContainers for the given
+ // ECFServiceEndpointDescription via registered services
+ trace("handleDiscoveredServiceAvailable",
+ "calling findRemoteServiceContainersViaService with ecfSED="
+ + ecfSED);
+ IRemoteServiceContainer[] rsContainers = findRemoteServiceContainersViaService(
+ ecfSED, monitor);
+ if (rsContainers == null || rsContainers.length == 0) {
logError("handleDiscoveredServiceAvailable",
"No RemoteServiceContainerAdapters found for description="
+ ecfSED, null);
return;
}
// Give warning if more than one ContainerAdapterHelper found
- if (cahs.length > 1) {
+ if (rsContainers.length > 1) {
logWarning("handleDiscoveredServiceAvailable",
- "Multiple remote service containers=" + Arrays.asList(cahs)
+ "Multiple remote service containers="
+ + Arrays.asList(rsContainers)
+ " found for service endpoint description="
+ ecfSED);
}
+
+ // Get endpoint ID
+ ID ecfEndpointID = ecfSED.getECFEndpointID();
+ // Get remote service filter from the service endpoint description
+ // if it exists.
+ String remoteServiceFilter = ecfSED.getECFRemoteServicesFilter();
// For all remote service container adapters
// Get futureRemoteReferences...then create a thread
// to process the future
Collection providedInterfaces = ecfSED.getProvidedInterfaces();
- for (int i = 0; i < cahs.length; i++) {
+ for (int i = 0; i < rsContainers.length; i++) {
for (Iterator j = providedInterfaces.iterator(); j.hasNext();) {
String providedInterface = (String) j.next();
// Use async call to prevent blocking here
- trace("handleDiscoveredServiceAvailable", "rsca=" + cahs[i]
- + ",intf=" + providedInterface);
- IFuture futureRemoteReferences = cahs[i].getRSCA()
- .asyncGetRemoteServiceReferences(
- new ID[] { endpointID }, providedInterface,
- null);
- // And process the future returned in separate thread
- processFutureForRemoteServiceReferences(ecfSED,
- futureRemoteReferences, cahs[i]);
+ trace("handleDiscoveredServiceAvailable", "rsca="
+ + rsContainers[i] + ",endpointId=" + ecfEndpointID
+ + ",intf=" + providedInterface + ",rsFilter="
+ + remoteServiceFilter
+ + ". Calling getRemoteServiceReferences");
+ IRemoteServiceReference[] remoteReferences = null;
+ try {
+ remoteReferences = rsContainers[i].getContainerAdapter()
+ .getRemoteServiceReferences(ecfEndpointID,
+ providedInterface, remoteServiceFilter);
+ } catch (ContainerConnectException e) {
+ logError("handleDiscoveredServiceAvailable", "rsca="
+ + rsContainers[i] + ",endpointId=" + ecfEndpointID
+ + ",intf=" + providedInterface
+ + ". Connect error in getRemoteServiceReferences",
+ e);
+ continue;
+ } catch (InvalidSyntaxException e) {
+ logError(
+ "handleDiscoveredServiceAvailable",
+ "rsca="
+ + rsContainers[i]
+ + ",endpointId="
+ + ecfEndpointID
+ + ",intf="
+ + providedInterface
+ + " Filter syntax error in getRemoteServiceReferences",
+ e);
+ continue;
+ }
+ if (remoteReferences == null || remoteReferences.length == 0) {
+ logError("handleDiscoveredServiceAvailable",
+ "getRemoteServiceReferences result is empty. "
+ + "containerHelper="
+ + rsContainers[i]
+ + "remoteReferences="
+ + ((remoteReferences == null) ? "null"
+ : Arrays.asList(remoteReferences)
+ .toString()), null);
+ continue;
+ } else
+ registerRemoteServiceReferences(ecfSED, rsContainers[i],
+ remoteReferences);
}
}
}
@@ -168,76 +328,15 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
return ecfSED;
}
- private void processFutureForRemoteServiceReferences(
- final ECFServiceEndpointDescription sed,
- final IFuture futureRemoteReferences,
- final ContainerAdapterHelper ch) {
- Thread t = new Thread(new Runnable() {
- public void run() {
- try {
- // Call get to get the remoteReferences from the IFuture
- // instance
- // This will block, but since we're in our own thread we're
- // OK
- IRemoteServiceReference[] remoteReferences = (IRemoteServiceReference[]) futureRemoteReferences
- .get(sed.getLookupTimeout());
- // Get the status
- IStatus futureStatus = futureRemoteReferences.getStatus();
- if (futureStatus.isOK()) {
- trace("processFutureForRemoteServiceReferences.run",
- "containerHelper="
- + ch
- + "remoteReferences="
- + ((remoteReferences == null) ? "null"
- : Arrays.asList(
- remoteReferences)
- .toString()));
- if (remoteReferences != null
- && remoteReferences.length > 0) {
- registerRemoteServiceReferences(sed, ch,
- remoteReferences);
- } else {
- logError(
- "processFutureForRemoteServiceReferences",
- "getRemoteServiceReferences result is empty. "
- + "containerHelper="
- + ch
- + "remoteReferences="
- + ((remoteReferences == null) ? "null"
- : Arrays.asList(
- remoteReferences)
- .toString()), null);
- }
- } else {
- logError("processFutureForRemoteServiceReferences",
- "Future status NOT ok message="
- + futureStatus.getMessage(),
- futureStatus.getException());
- }
- } catch (InterruptedException e) {
- logError("processFutureForRemoteServiceReferences",
- "Retrieval interrupted", e);
- } catch (OperationCanceledException e) {
- logError("processFutureForRemoteServiceReferences",
- "Retrieval cancelled", e);
- } catch (TimeoutException e) {
- logError("processFutureForRemoteServiceReferences",
- "Retrieval timedout after " + e.getDuration(), e);
- }
- }
- });
- t.start();
- }
-
private void addProxyServiceRegistration(ServiceEndpointDescription sed,
- ContainerAdapterHelper ch, IRemoteServiceReference ref,
+ IRemoteServiceContainer ch, IRemoteServiceReference ref,
ServiceRegistration registration) {
ID containerID = ch.getContainer().getID();
RemoteServiceRegistrations reg = (RemoteServiceRegistrations) discoveredRemoteServiceRegistrations
.get(containerID);
if (reg == null) {
reg = new RemoteServiceRegistrations(sed, ch.getContainer(), ch
- .getRSCA(),
+ .getContainerAdapter(),
new RemoteServiceReferenceUnregisteredListener());
discoveredRemoteServiceRegistrations.put(containerID, reg);
}
@@ -345,7 +444,7 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
}
private void registerRemoteServiceReferences(
- ECFServiceEndpointDescription sed, ContainerAdapterHelper ch,
+ ECFServiceEndpointDescription sed, IRemoteServiceContainer ch,
IRemoteServiceReference[] remoteReferences) {
synchronized (discoveredRemoteServiceRegistrations) {
@@ -359,8 +458,8 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
for (int i = 0; i < remoteReferences.length; i++) {
// Get IRemoteService, used to create the proxy below
- IRemoteService remoteService = ch.getRSCA().getRemoteService(
- remoteReferences[i]);
+ IRemoteService remoteService = ch.getContainerAdapter()
+ .getRemoteService(remoteReferences[i]);
// If no remote service then give up
if (remoteService == null) {
logError("registerRemoteServiceReferences",
@@ -381,7 +480,8 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
// Get service properties for the proxy
Dictionary properties = getPropertiesForRemoteService(sed, ch
- .getRSCA(), remoteReferences[i], remoteService);
+ .getContainerAdapter(), remoteReferences[i],
+ remoteService);
// Create proxy right here
Object proxy = null;
@@ -427,11 +527,11 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
.getProperty(propKeys[i]));
}
}
- results.put(ECFServiceConstants.OSGI_REMOTE, remoteService);
+ results.put(IServiceConstants.OSGI_REMOTE, remoteService);
return results;
}
- private ContainerAdapterHelper[] findRSCAs(ID endpointID,
+ private IRemoteServiceContainer[] findRSCAs(ID endpointID,
ServiceEndpointDescription sedh) {
IContainerManager containerManager = Activator.getDefault()
.getContainerManager();
@@ -441,7 +541,7 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
if (containers == null) {
// log this?
logWarning("findRSCAs", "No containers found for container manager");
- return new ContainerAdapterHelper[0];
+ return new IRemoteServiceContainer[0];
}
List results = new ArrayList();
for (int i = 0; i < containers.length; i++) {
@@ -450,11 +550,11 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
if (adapter != null
&& includeRCSAForDescription(containers[i], adapter,
endpointID, sedh)) {
- results.add(new ContainerAdapterHelper(containers[i], adapter));
+ results.add(new RemoteServiceContainer(containers[i], adapter));
}
}
- return (ContainerAdapterHelper[]) results
- .toArray(new ContainerAdapterHelper[] {});
+ return (IRemoteServiceContainer[]) results
+ .toArray(new IRemoteServiceContainer[] {});
}
private boolean includeRCSAForDescription(IContainer container,
@@ -464,7 +564,7 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
// same as the
// container/adapter under test then we've found a compatible one
String connectNamespaceName = (String) description
- .getProperty(ECFServicePublication.PROP_KEY_ENDPOINT_CONTAINERID_NAMESPACE);
+ .getProperty(IServicePublication.PROP_KEY_ENDPOINT_CONTAINERID_NAMESPACE);
if (connectNamespaceName != null) {
Namespace namespace = container.getConnectNamespace();
if (namespace != null
@@ -487,7 +587,10 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker {
}
protected void logError(String methodName, String message, Throwable t) {
- traceException(methodName, message, t);
+ if (t != null)
+ traceException(methodName, message, t);
+ else
+ trace(methodName, message);
Activator.getDefault()
.log(
new Status(IStatus.ERROR, Activator.PLUGIN_ID,
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/EventHookImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/EventHookImpl.java
index bbc4fa3e0..ed0881a6e 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/EventHookImpl.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/EventHookImpl.java
@@ -14,8 +14,8 @@ import org.eclipse.core.runtime.*;
import org.eclipse.ecf.core.*;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.Namespace;
-import org.eclipse.ecf.osgi.services.discovery.ECFServicePublication;
-import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants;
+import org.eclipse.ecf.osgi.services.discovery.IServicePublication;
+import org.eclipse.ecf.osgi.services.distribution.IServiceConstants;
import org.eclipse.ecf.remoteservice.*;
import org.eclipse.ecf.remoteservice.Constants;
import org.osgi.framework.*;
@@ -83,7 +83,7 @@ public class EventHookImpl extends AbstractEventHookImpl {
// selected container adapters support all required intents (i.e. via
// findRSCAHoldersSatisfyingRequiredIntents
String[] remoteRequiresIntents = (String[]) serviceReference
- .getProperty(ECFServiceConstants.OSGI_REMOTE_REQUIRES_INTENTS);
+ .getProperty(IServiceConstants.OSGI_REMOTE_REQUIRES_INTENTS);
if (remoteRequiresIntents != null) {
rscas = findRSCAHoldersSatisfyingRequiredIntents(rscas,
remoteRequiresIntents);
@@ -162,12 +162,26 @@ public class EventHookImpl extends AbstractEventHookImpl {
getServicePropertiesForRemotePublication(ref));
IContainer container = holder.getContainer();
+
// Due to slp bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=216944
// We are not going to use the RFC 119
// ServicePublication.PROP_KEY_ENDPOINT_ID...since
// it won't handle some Strings with (e.g. slp) provider
- properties.put(ECFServicePublication.PROP_KEY_ENDPOINT_CONTAINERID,
+ ID endpointID = container.getID();
+ properties.put(IServicePublication.PROP_KEY_ENDPOINT_CONTAINERID,
container.getID());
+
+ // Also put the target ID in the service properties...*only*
+ // if the target ID is non-null and it's *not* the same as the
+ // endpointID, then include it in the set of properties delivered
+ // for publication
+ ID targetID = container.getConnectedID();
+ if (targetID != null && !targetID.equals(endpointID)) {
+ // put the target ID into the properties
+ properties.put(IServicePublication.PROP_KEY_TARGET_CONTAINERID,
+ targetID);
+ }
+
// Set remote service namespace (String)
Namespace rsnamespace = holder.getContainerAdapter()
.getRemoteServiceNamespace();
@@ -241,10 +255,10 @@ public class EventHookImpl extends AbstractEventHookImpl {
private static final List excludedProperties = Arrays.asList(new String[] {
org.osgi.framework.Constants.SERVICE_ID,
org.osgi.framework.Constants.OBJECTCLASS,
- ECFServiceConstants.OSGI_REMOTE_INTERFACES,
- ECFServiceConstants.OSGI_REMOTE_REQUIRES_INTENTS,
- ECFServiceConstants.OSGI_REMOTE,
- ECFServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE,
+ IServiceConstants.OSGI_REMOTE_INTERFACES,
+ IServiceConstants.OSGI_REMOTE_REQUIRES_INTENTS,
+ IServiceConstants.OSGI_REMOTE,
+ IServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE,
// ECF constants
org.eclipse.ecf.remoteservice.Constants.SERVICE_CONTAINER_ID, });
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IRemoteServiceContainerFinder.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IRemoteServiceContainerFinder.java
new file mode 100644
index 000000000..ec006c74c
--- /dev/null
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IRemoteServiceContainerFinder.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2009 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.osgi.services.distribution;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.ecf.osgi.services.discovery.IServiceEndpointDescription;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainer;
+
+public interface IRemoteServiceContainerFinder {
+
+ /**
+ *
+ * Find remote service containers.
+ *
+ * @param endpointDescription
+ * the endpoint description created from the discovered remote
+ * service meta data. This endpointDescription may be used to
+ * decide what IRemoteServiceContainer[] to return, as well as
+ * whether or not to connect the IContainer to the targetID
+ * (provided by
+ * {@link IServiceEndpointDescription#getECFTargetID()}. Will not
+ * be <code>null</code>.
+ *
+ * @param monitor
+ * a progress monitor to report progress or cancel operation from
+ * within the find. Will not be <code>null</code>.
+ * @return IRemoteServiceContainer[] the remote service containers that
+ * should be used to get remote service references for the remote
+ * service described by the endpointDescription. If no containers
+ * are relevant, then an empty array should be returned rather than
+ * <code>null</code>.
+ */
+ public IRemoteServiceContainer[] findRemoteServiceContainers(
+ IServiceEndpointDescription endpointDescription,
+ IProgressMonitor monitor);
+
+}
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ECFServiceConstants.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IServiceConstants.java
index d85fad936..10c34c12d 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ECFServiceConstants.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IServiceConstants.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.ecf.osgi.services.distribution;
-public interface ECFServiceConstants {
+public interface IServiceConstants {
/*
* service.intents – an optional list of intents provided by the service.

Back to the top