diff options
author | slewis | 2009-02-25 03:37:11 +0000 |
---|---|---|
committer | slewis | 2009-02-25 03:37:11 +0000 |
commit | e11d639e8578d12c80e850142cfcca8cfe4cf674 (patch) | |
tree | cd2b62aa9f168c7836628dbe3a882406616e3419 /compendium/bundles/org.eclipse.ecf.osgi.services.distribution | |
parent | 959df475b7af71d1642415eb059f4ad53b271f9c (diff) | |
download | org.eclipse.ecf-e11d639e8578d12c80e850142cfcca8cfe4cf674.tar.gz org.eclipse.ecf-e11d639e8578d12c80e850142cfcca8cfe4cf674.tar.xz org.eclipse.ecf-e11d639e8578d12c80e850142cfcca8cfe4cf674.zip |
Restructured ServicePublicationHandler and ServiceConstants, and remote service Constants
Diffstat (limited to 'compendium/bundles/org.eclipse.ecf.osgi.services.distribution')
5 files changed, 171 insertions, 76 deletions
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 c4eb186e3..9f832f7ca 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 @@ -11,7 +11,7 @@ package org.eclipse.ecf.internal.osgi.services.distribution; import java.util.*; import org.eclipse.ecf.core.util.Trace; -import org.eclipse.ecf.osgi.services.distribution.ServiceConstants; +import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants; import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration; import org.osgi.framework.*; import org.osgi.framework.hooks.service.EventHook; @@ -67,7 +67,7 @@ public abstract class AbstractEventHookImpl implements EventHook { // declared via // osgi.remote.interfaces Object osgiRemotes = serviceReference - .getProperty(ServiceConstants.OSGI_REMOTE_INTERFACES); + .getProperty(ECFServiceConstants.OSGI_REMOTE_INTERFACES); // If osgi.remote.interfaces required property is non-null then we // handle further, if null then ignore if (osgiRemotes != null) { @@ -97,7 +97,7 @@ public abstract class AbstractEventHookImpl implements EventHook { } // Now get optional service property osgi.remote.configuration.type Object osgiRemoteConfigurationType = serviceReference - .getProperty(ServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE); + .getProperty(ECFServiceConstants.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 @@ -195,7 +195,7 @@ public abstract class AbstractEventHookImpl implements EventHook { .getProperty(Constants.OBJECTCLASS)); for (int i = 0; i < remoteInterfaces.length; i++) { String intf = remoteInterfaces[i]; - if (ServiceConstants.OSGI_REMOTE_INTERFACES_WILDCARD.equals(intf)) + if (ECFServiceConstants.OSGI_REMOTE_INTERFACES_WILDCARD.equals(intf)) return (String[]) interfaces.toArray(new String[] {}); if (intf != null && interfaces.contains(intf)) results.add(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 a754ab9a4..763cb5e56 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 @@ -12,7 +12,7 @@ package org.eclipse.ecf.internal.osgi.services.distribution; import java.util.Dictionary; import java.util.Hashtable; import org.eclipse.ecf.core.IContainerManager; -import org.eclipse.ecf.osgi.services.distribution.ServiceConstants; +import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants; import org.osgi.framework.*; import org.osgi.framework.hooks.service.EventHook; import org.osgi.service.distribution.DistributionProvider; @@ -66,7 +66,7 @@ public class Activator implements BundleActivator { try { final ServiceReference[] refs = this.context .getServiceReferences(null, "(" - + ServiceConstants.OSGI_REMOTE_INTERFACES + "=*)"); + + ECFServiceConstants.OSGI_REMOTE_INTERFACES + "=*)"); if (refs != null) { for (int i = 0; i < refs.length; i++) { hook.handleRegisteredServiceEvent(refs[i], null); 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 23ea9bc25..de2b3f137 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,6 +14,7 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.ecf.core.*; import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.util.Trace; +import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants; import org.eclipse.ecf.remoteservice.*; import org.eclipse.ecf.remoteservice.Constants; import org.osgi.framework.*; @@ -66,13 +67,32 @@ public class EventHookImpl extends AbstractEventHookImpl { RSCAHolder[] rscas = findRSCAHolders(serviceReference, ecfConfiguration); // If there are relevant ones then actually register a remote service // with them. - if (rscas == null) { + if (rscas == null || rscas.length == 0) { trace("registerRemoteService", "No remote service container adapters found for serviceReference=" + serviceReference + " and configuration=" + ecfConfiguration); return; } + // Get osgi.remote.requires.intents, and if it is set, verify that the + // selected container adapters support all required intents (i.e. via + // findRSCAHoldersSatisfyingRequiredIntents + String[] remoteRequiresIntents = (String[]) serviceReference + .getProperty(ECFServiceConstants.OSGI_REMOTE_REQUIRES_INTENTS); + if (remoteRequiresIntents != null) { + rscas = findRSCAHoldersSatisfyingRequiredIntents(rscas, + remoteRequiresIntents); + } + // We may not have any remaining, so we need to check again + if (rscas == null || rscas.length == 0) { + trace( + "registerRemoteService", + "No remote service container adapters found satisfying required intents for serviceReference=" + + serviceReference + + " and configuration=" + + ecfConfiguration); + return; + } // Now actually register remote service with remote service container // adapters found above. This involves three steps: // 1) registering the remote service with each ECF @@ -83,10 +103,8 @@ public class EventHookImpl extends AbstractEventHookImpl { // Step 1 IRemoteServiceRegistration remoteRegistration = rscas[i] .getContainerAdapter().registerRemoteService( - remoteInterfaces, - getService(serviceReference), - createPropertiesForRemoteService(rscas[i], - remoteInterfaces, serviceReference)); + remoteInterfaces, getService(serviceReference), + getPropertiesForRemoteService(serviceReference)); trace("registerRemoteService", "REGISTERED REMOTE SERVICE serviceReference=" + serviceReference + " remoteRegistration=" @@ -99,12 +117,37 @@ public class EventHookImpl extends AbstractEventHookImpl { } } - private void publishRemoteService(RSCAHolder holder, ServiceReference ref, - String[] remoteInterfaces, + private RSCAHolder[] findRSCAHoldersSatisfyingRequiredIntents( + RSCAHolder[] rscas, String[] remoteRequiresIntents) { + List results = new ArrayList(); + for (int i = 0; i < rscas.length; i++) { + boolean include = true; + List supportedIntents = Arrays.asList(rscas[i] + .getContainerTypeDescription().getSupportedIntents()); + for (int j = 0; j < remoteRequiresIntents.length; j++) { + if (!supportedIntents.contains(remoteRequiresIntents[j])) { + include = false; + } + } + if (include) { + trace("findRSCAHoldersSatisfyingRequiredIntents", + "INCLUDING container=" + rscas[i].getContainer() + + " satisfying intents. supported intents=" + + supportedIntents); + results.add(rscas[i]); + } else { + trace("findRSCAHoldersSatisfyingRequiredIntents", + "EXCLUDING container=" + rscas[i].getContainer() + + " supported intents=" + supportedIntents); + } + } + return (RSCAHolder[]) results.toArray(new RSCAHolder[] {}); + } + + Dictionary getServicePublicationProperties(RSCAHolder holder, + ServiceReference ref, String[] remoteInterfaces, IRemoteServiceRegistration remoteRegistration) { - // First create properties for new ServicePublication - final Dictionary properties = new Hashtable(); - final BundleContext context = Activator.getDefault().getContext(); + final Dictionary properties = new Properties(); // Set mandatory ServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME properties.put(ServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME, getAsCollection(remoteInterfaces)); @@ -116,21 +159,33 @@ public class EventHookImpl extends AbstractEventHookImpl { // Set optional ServicePublication.PROP_KEY_SERVICE_PROPERTIES properties.put(ServicePublication.PROP_KEY_SERVICE_PROPERTIES, - getServiceProperties(ref)); + getServicePropertiesForRemotePublication(ref)); // Set optional ServicePublication.PROP_KEY_ENDPOINT_ID to // container.getID().toExternalForm() IContainer container = holder.getContainer(); properties.put(ServicePublication.PROP_KEY_ENDPOINT_ID, container .getID().toExternalForm()); - // ECF remote service property + // 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 properties.put(Constants.SERVICE_ID, ((Long) remoteRegistration - .getProperty(Constants.SERVICE_ID)).toString()); + .getProperty(Constants.SERVICE_ID))); + return properties; + } + + private void publishRemoteService(RSCAHolder holder, ServiceReference ref, + String[] remoteInterfaces, + IRemoteServiceRegistration remoteRegistration) { + // First create properties for new ServicePublication + final Dictionary properties = getServicePublicationProperties(holder, + ref, remoteInterfaces, remoteRegistration); + final BundleContext context = Activator.getDefault().getContext(); // Now, at long last, register the ServicePublication. // The RFC 119 discovery should/will pick this up and send it out ServiceRegistration reg = context.registerService( @@ -152,49 +207,46 @@ public class EventHookImpl extends AbstractEventHookImpl { return result; } - private Map getServiceProperties(final ServiceReference ref) { - Map map = (Map) ref - .getProperty(ServicePublication.PROP_KEY_SERVICE_PROPERTIES); - if (map == null) - map = new HashMap(); - return map; - } - private Map parseECFConfigurationType(String[] remoteConfigurationType) { Map results = new HashMap(); // TODO parse ecf configuration from remoteConfigurationType return results; } - protected Collection /* <? extends String> */registerRemoteService( - RSCAHolder[] rscas, String[] remoteInterfaces, ServiceReference sr) { - final ArrayList result = new ArrayList(); - for (int i = 0; i < rscas.length; i++) { - IRemoteServiceRegistration remoteRegistration = rscas[i] - .getContainerAdapter().registerRemoteService( - remoteInterfaces, - getService(sr), - createPropertiesForRemoteService(rscas[i], - remoteInterfaces, sr)); - trace("registerRemoteService", - "REGISTERED REMOTE SERVICE serviceReference=" + sr - + " remoteRegistration=" + remoteRegistration); - result.add(remoteRegistration.getContainerID().toString()); - fireRemoteServiceRegistered(sr, remoteRegistration); + protected Dictionary getPropertiesForRemoteService(ServiceReference sr) { + String[] propKeys = sr.getPropertyKeys(); + Properties newProps = new Properties(); + for (int i = 0; i < propKeys.length; i++) { + if (!excludeRemoteServiceProperty(propKeys[i])) + newProps.put(propKeys[i], sr.getProperty(propKeys[i])); } - return result; + return newProps; } - protected Dictionary createPropertiesForRemoteService(RSCAHolder holder, - String[] remotes, ServiceReference sr) { + protected Map getServicePropertiesForRemotePublication(ServiceReference sr) { String[] propKeys = sr.getPropertyKeys(); Properties newProps = new Properties(); for (int i = 0; i < propKeys.length; i++) { - newProps.put(propKeys[i], sr.getProperty(propKeys[i])); + if (!excludeRemoteServiceProperty(propKeys[i])) + newProps.put(propKeys[i], sr.getProperty(propKeys[i])); } return newProps; } + 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 }); + + private boolean excludeRemoteServiceProperty(String string) { + if (excludedProperties.contains(string)) + return true; + return false; + } + protected RSCAHolder[] findRSCAHolders(ServiceReference serviceReference, Map ecfConfiguration) { IContainerManager containerManager = Activator.getDefault() 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/ECFServiceConstants.java new file mode 100644 index 000000000..ca5542015 --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ECFServiceConstants.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * 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; + +public interface ECFServiceConstants { + + /* + * osgi.intents an optional list of intents provided by the service. The + * property advertises capabilities of the service and can be used by the + * service consumer in the lookup filter to only select a service that + * provides certain qualities of service. The value of this property is of + * type String[] and has to be provided by the service as part of the + * registration, regardless whether its a local service or a proxy. The + * value on the proxy is a union of the value specified by the service + * provider, plus any remote-specific intents (see + * orgi.remote.require.intents, below), plus any intents which the + * Distribution Software adds that describe characteristics of the + * Distribution being mechanism. Therefore the value of this property can + * vary between the client side proxy and the server side. + */ + public static final String OSGI_INTENTS = "osgi.intents"; + + /* + * osgi.remote.interfaces [ * | interface_name [, interface_name]* ]: A + * distribution software implementation may expose a service for remote + * access, if and only if the service has indicated its intention as well as + * support for remote invocations by setting this service property in its + * service registration. The value of this property is of type String[]. If + * the list contains only one value, which is set to *, all of the + * interfaces specified in the BundleContext.registerService() call are + * being exposed remotely. The value can also be set to a comma-separated + * list of interface names, which should be a subset of the interfaces + * specified in the registerService call. In this case only the specified + * interfaces are exposed remotely. + */ + public static final String OSGI_REMOTE_INTERFACES = "osgi.remote.interfaces"; + + /* + * osgi.remote.requires.intents an optional list of intents that should be + * provided when remotely exposing the service. If a DSW implementation + * cannot satisfy these intents when exposing the service remotely, it + * should not expose the service. The value of this property is of type + * String[]. + */ + public static final String OSGI_REMOTE_REQUIRES_INTENTS = "osgi.remote.requires.intents"; + + /* + * osgi.remote this property is set on client side service proxies + * registered in the OSGi Service Registry. + */ + public static final String OSGI_REMOTE = "osgi.remote"; + + /* + * osgi.remote.configuration.type service providing side property that + * identifies the metadata type of additional metadata, if any, that was + * provided with the service, e.g. sca. Multiple types and thus sets of + * additional metadata may be provided. The value of this property is of + * type String[]. + */ + public static final String OSGI_REMOTE_CONFIGURATION_TYPE = "osgi.remote.configuration.type"; + + public static final String OSGI_REMOTE_INTERFACES_WILDCARD = "*"; + + public static final String ECF_REMOTE_CONFIGURATION_TYPE = "ecf"; + +} diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ServiceConstants.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ServiceConstants.java deleted file mode 100644 index f656fa595..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ServiceConstants.java +++ /dev/null @@ -1,30 +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.osgi.services.distribution; - -public interface ServiceConstants { - - public static final String OSGI_INTENTS = "osgi.intents"; - - public static final String OSGI_REMOTE_INTERFACES = "osgi.remote.interfaces"; - - public static final String OSGI_REMOTE_REQUIRES_INTENTS = "osgi.remote.requires.intents"; - - public static final String OSGI_REMOTE_CONFIGURATION_TYPE = "osgi.remote.configuration.type"; - - public static final String OSGI_REMOTE = "osgi.remote"; - - public static final String OSGI_REMOTE_INTERFACES_WILDCARD = "*"; - - // ecf,org.eclipse.ecf.containerID=<id> - - public static final String ECF_REMOTE_CONFIGURATION_TYPE = "ecf"; - -} |