diff options
author | slewis | 2009-02-25 09:00:12 +0000 |
---|---|---|
committer | slewis | 2009-02-25 09:00:12 +0000 |
commit | 643584194cf6f8f111608c7f5240f48db25a263c (patch) | |
tree | 85547b797d713ed74a5bf32b09502351eb80bb45 /compendium/bundles/org.eclipse.ecf.osgi.services.distribution | |
parent | 075fc4a54b371bcef9b5549cebc3c5ce7e327cb0 (diff) | |
download | org.eclipse.ecf-643584194cf6f8f111608c7f5240f48db25a263c.tar.gz org.eclipse.ecf-643584194cf6f8f111608c7f5240f48db25a263c.tar.xz org.eclipse.ecf-643584194cf6f8f111608c7f5240f48db25a263c.zip |
Further additions for RFC 119 impl
Diffstat (limited to 'compendium/bundles/org.eclipse.ecf.osgi.services.distribution')
5 files changed, 125 insertions, 58 deletions
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/.options b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/.options index 4f120a0d2..3c8f01bae 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/.options +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/.options @@ -19,3 +19,5 @@ org.eclipse.ecf.osgi.services.distribution/debug/findhook=true org.eclipse.ecf.osgi.services.distribution/debug/eventhook=true +org.eclipse.ecf.osgi.services.distribution/debug/discoveredservicetracker=true + 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 763cb5e56..89c47247f 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 @@ -15,6 +15,7 @@ import org.eclipse.ecf.core.IContainerManager; import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants; import org.osgi.framework.*; import org.osgi.framework.hooks.service.EventHook; +import org.osgi.service.discovery.DiscoveredServiceTracker; import org.osgi.service.distribution.DistributionProvider; import org.osgi.util.tracker.ServiceTracker; @@ -25,13 +26,13 @@ public class Activator implements BundleActivator { private static Activator plugin; private BundleContext context; - private ServiceRegistration eventHookRegistration; - private ServiceRegistration distributionProviderRegistration; - private ServiceRegistration listenerHookRegistration; + private ServiceTracker containerManagerTracker; private DistributionProviderImpl distributionProvider; - private ServiceTracker containerManagerTracker; + private ServiceRegistration eventHookRegistration; + private ServiceRegistration distributionProviderRegistration; + private ServiceRegistration discoveredServiceTrackerRegistration; public static Activator getDefault() { return plugin; @@ -52,10 +53,18 @@ public class Activator implements BundleActivator { plugin = this; this.context = ctxt; this.distributionProvider = new DistributionProviderImpl(); + addDiscoveredServiceTracker(); addServiceRegistryHooks(); addDistributionProvider(); } + private void addDiscoveredServiceTracker() { + this.discoveredServiceTrackerRegistration = this.context + .registerService(DiscoveredServiceTracker.class.getName(), + new DiscoveredServiceTrackerImpl( + this.distributionProvider), null); + } + private void addServiceRegistryHooks() { // register the event hook to get informed when new services appear final EventHookImpl hook = new EventHookImpl(distributionProvider); @@ -64,9 +73,9 @@ 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 + "=*)"); + final ServiceReference[] refs = this.context.getServiceReferences( + null, "(" + ECFServiceConstants.OSGI_REMOTE_INTERFACES + + "=*)"); if (refs != null) { for (int i = 0; i < refs.length; i++) { hook.handleRegisteredServiceEvent(refs[i], null); @@ -97,10 +106,6 @@ public class Activator implements BundleActivator { this.eventHookRegistration.unregister(); this.eventHookRegistration = null; } - if (this.listenerHookRegistration != null) { - this.listenerHookRegistration.unregister(); - this.listenerHookRegistration = null; - } } private void removeDistributionProvider() { @@ -110,6 +115,13 @@ public class Activator implements BundleActivator { } } + private void removeDiscoveredServiceTracker() { + if (this.discoveredServiceTrackerRegistration != null) { + this.discoveredServiceTrackerRegistration.unregister(); + this.discoveredServiceTrackerRegistration = null; + } + } + /* * (non-Javadoc) * @@ -117,6 +129,7 @@ public class Activator implements BundleActivator { * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext ctxt) throws Exception { + removeDiscoveredServiceTracker(); removeDistributionProvider(); removeServiceRegistryHooks(); if (containerManagerTracker != null) { diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DebugOptions.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DebugOptions.java index 25ad8f676..302314f50 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DebugOptions.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DebugOptions.java @@ -27,4 +27,7 @@ public interface DebugOptions { public static final String FINDHOOKDEBUG = DEBUG + "/findhook"; + public static final String DISCOVEREDSERVICETRACKER = DEBUG + + "/discoveredservicetracker"; + } 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 d82ab7275..c6ae64ac7 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 @@ -14,10 +14,10 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.ecf.core.IContainer; import org.eclipse.ecf.core.IContainerManager; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.identity.Namespace; +import org.eclipse.ecf.core.identity.*; import org.eclipse.ecf.core.util.ECFException; import org.eclipse.ecf.core.util.Trace; +import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants; import org.eclipse.ecf.remoteservice.*; import org.eclipse.equinox.concurrent.future.IFuture; import org.eclipse.equinox.concurrent.future.TimeoutException; @@ -41,8 +41,7 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { logError("DiscoveredServiceNotification is null", null); return; } - Trace.entering(Activator.PLUGIN_ID, DebugOptions.DEBUG, - this.getClass(), "serviceChanged", notification); + trace("serviceChanged", "notification="); int notificationType = notification.getType(); switch (notificationType) { case DiscoveredServiceNotification.AVAILABLE: @@ -100,20 +99,29 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { } // Find RSCAs for the given description IRemoteServiceContainerAdapter[] rscas = findRSCAs(description); - if (rscas == null) { + if (rscas == null || rscas.length == 0) { logError("No RemoteServiceContainerAdapters found for description " + description, null); return; } + ID endpointID = null; + try { + endpointID = createEndpointID(description); + } catch (IDCreateException e) { + logError("No endpoint ID created for description " + description, e); + return; + } for (int i = 0; i < rscas.length; i++) { for (Iterator j = providedInterfaces.iterator(); j.hasNext();) { String providedInterface = (String) j.next(); // Use async call to prevent blocking here + trace("handleDiscoveredServiceAvailable", "rscas=" + rscas[i] + + ", calling asyncGetRemoteServiceReferences endpoint=" + + endpointID + ",intf=" + providedInterface); IFuture futureRemoteReferences = rscas[i] .asyncGetRemoteServiceReferences( - createContainerIDsForQuery(description), - providedInterface, - getRemoteFilterForQuery(description)); + new ID[] { endpointID }, providedInterface, + null); // And process the future returned in separate thread processFutureForRemoteServiceReferences(futureRemoteReferences, rscas[i], description, getTimeout(description)); @@ -121,11 +129,6 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { } } - private String getRemoteFilterForQuery( - ServiceEndpointDescription description) { - return null; - } - long getTimeout(ServiceEndpointDescription description) { // for now return constant of 30s return 30000; @@ -139,9 +142,15 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { public void run() { try { // First get remote service references + trace("processFutureForRemoteServiceReferences", "future=" + + futureRemoteReferences + " calling future.get"); IRemoteServiceReference[] remoteReferences = (IRemoteServiceReference[]) futureRemoteReferences .get(timeout); IStatus futureStatus = futureRemoteReferences.getStatus(); + trace("processFutureForRemoteServiceReferences", "future=" + + futureRemoteReferences + " status=" + + futureStatus + " remoteReferences=" + + Arrays.asList(remoteReferences)); if (futureStatus.isOK() && remoteReferences != null && remoteReferences.length > 0) { registerRemoteServiceReferences(rsca, remoteReferences, @@ -185,6 +194,8 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { ServiceEndpointDescription description) { // First, get IRemoteService instances for remote references for (int i = 0; i < remoteReferences.length; i++) { + trace("registerRemoteServiceReference", "rsca=" + rsca + + ", remoteReference=" + remoteReferences[i]); // Otherwise we register it. IRemoteService remoteService = rsca .getRemoteService(remoteReferences[i]); @@ -193,15 +204,15 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { + remoteReferences[i], null); continue; } - String[] clazzes = getClazzesForRemoteServiceReference( - remoteReferences[i], description); + String[] clazzes = (String[]) remoteReferences[i] + .getProperty(Constants.OBJECTCLASS); if (clazzes == null) { logError("no classes specified for remote service reference " + remoteReferences[i], null); continue; } Dictionary properties = getPropertiesForRemoteServiceReference( - remoteReferences[i], description); + remoteService, description); Object proxy = null; try { proxy = remoteService.getProxy(); @@ -223,41 +234,55 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { + " already registered locally", null); continue; } + ServiceRegistration registration = null; try { // Finally register - ServiceRegistration registration = bundleContext - .registerService(clazzes, proxy, properties); + trace("registerRemoteServiceReferences", + "registering classes=" + Arrays.asList(clazzes) + + ",properties=" + properties); + registration = bundleContext.registerService(clazzes, + proxy, properties); addRemoteServiceRegistration(remoteReferences[i], registration); } catch (Exception e) { logError("Error registering for remote reference " + remoteReferences[i], e); + removeRemoteServiceRegistration(remoteReferences[i]); continue; } } } } - private Dictionary getPropertiesForRemoteServiceReference( - IRemoteServiceReference remoteServiceReference, - ServiceEndpointDescription description) { + private void removeRemoteServiceRegistration( + IRemoteServiceReference iRemoteServiceReference) { // TODO Auto-generated method stub - return null; + } - private String[] getClazzesForRemoteServiceReference( - IRemoteServiceReference iRemoteServiceReference, - ServiceEndpointDescription description) { + private Dictionary getPropertiesForRemoteServiceReference( + IRemoteService remoteService, ServiceEndpointDescription description) { // TODO Auto-generated method stub - return null; + Properties results = new Properties(); + // XXX Fill in properties from ECF + results.put(ECFServiceConstants.OSGI_REMOTE, remoteService); + return results; } - private ID[] createContainerIDsForQuery( - ServiceEndpointDescription description) { - // XXX if there is a container id in the ServiceEndpointDescription - // service properties, then we should retrieve it - // and return in array here - return null; + private ID createEndpointID(ServiceEndpointDescription description) + throws IDCreateException { + String endpointID = description.getEndpointID(); + if (endpointID == null) + return null; + // Get idfilter namespace name + String idfilterNamespaceName = (String) description + .getProperty(Constants.SERVICE_IDFILTER_NAMESPACE); + if (idfilterNamespaceName == null) + throw new IDCreateException( + "IDfilter Namespace name is not set in description " + + description); + return IDFactory.getDefault().createID(idfilterNamespaceName, + endpointID); } private IRemoteServiceContainerAdapter[] findRSCAs( @@ -287,11 +312,12 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { private boolean includeRCSAForDescription(IContainer container, IRemoteServiceContainerAdapter adapter, ServiceEndpointDescription description) { - String namespaceName = (String) description - .getProperty(Constants.SERVICE_NAMESPACE); - if (namespaceName != null) { - Namespace namespace = adapter.getRemoteServiceNamespace(); - if (namespace.getName().equals(namespaceName)) + String connectNamespaceName = (String) description + .getProperty(Constants.SERVICE_CONNECT_ID_NAMESPACE); + if (connectNamespaceName != null) { + Namespace namespace = container.getConnectNamespace(); + if (namespace != null + && namespace.getName().equals(connectNamespaceName)) return true; } return true; @@ -304,4 +330,14 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { t.printStackTrace(System.err); } + protected void trace(String methodName, String message) { + Trace.trace(Activator.PLUGIN_ID, DebugOptions.DISCOVEREDSERVICETRACKER, + this.getClass(), methodName, message); + } + + protected void traceException(String string, Throwable e) { + Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, + this.getClass(), string, e); + } + } 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 de2b3f137..5ef3500a0 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 @@ -13,6 +13,7 @@ import java.util.*; import org.eclipse.core.runtime.Assert; 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.distribution.ECFServiceConstants; import org.eclipse.ecf.remoteservice.*; @@ -105,10 +106,9 @@ public class EventHookImpl extends AbstractEventHookImpl { .getContainerAdapter().registerRemoteService( remoteInterfaces, getService(serviceReference), getPropertiesForRemoteService(serviceReference)); - trace("registerRemoteService", - "REGISTERED REMOTE SERVICE serviceReference=" - + serviceReference + " remoteRegistration=" - + remoteRegistration); + trace("registerRemoteService", "REGISTERED REMOTE SERVICE " + + rscas[i] + " serviceReference=" + serviceReference + + " remoteRegistration=" + remoteRegistration); // Step 2 fireRemoteServiceRegistered(serviceReference, remoteRegistration); // Step 3 @@ -168,11 +168,22 @@ public class EventHookImpl extends AbstractEventHookImpl { // ECF remote service properties // Specify container factory name - properties.put(Constants.SERVICE_CONTAINER_FACTORY_NAME, holder - .getContainerTypeDescription().getName()); - properties.put(Constants.SERVICE_CONTAINER_CLASSNAME, holder - .getContainer().getClass().getName()); - // Specify remote service id AS STRING + Namespace connectnamespace = holder.getContainer() + .getConnectNamespace(); + if (connectnamespace != null) + properties.put(Constants.SERVICE_CONNECT_ID_NAMESPACE, + connectnamespace.getName()); + + Namespace idnamespace = holder.getContainer().getID().getNamespace(); + if (idnamespace != null) + properties.put(Constants.SERVICE_IDFILTER_NAMESPACE, idnamespace + .getName()); + + Namespace rsnamespace = holder.getContainerAdapter() + .getRemoteServiceNamespace(); + if (rsnamespace != null) + properties.put(Constants.SERVICE_NAMESPACE, rsnamespace.getName()); + properties.put(Constants.SERVICE_ID, ((Long) remoteRegistration .getProperty(Constants.SERVICE_ID))); @@ -239,7 +250,9 @@ public class EventHookImpl extends AbstractEventHookImpl { ECFServiceConstants.OSGI_REMOTE_INTERFACES, ECFServiceConstants.OSGI_REMOTE_REQUIRES_INTENTS, ECFServiceConstants.OSGI_REMOTE, - ECFServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE }); + ECFServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE, + // ECF constants + org.eclipse.ecf.remoteservice.Constants.SERVICE_CONTAINER_ID, }); private boolean excludeRemoteServiceProperty(String string) { if (excludedProperties.contains(string)) |