From 3e83ea07820067f9d8f65f7fe28b27297167b5f7 Mon Sep 17 00:00:00 2001 From: slewis Date: Tue, 28 Apr 2009 05:16:48 +0000 Subject: Changed osgi cmpn version 20090427 --- .../distribution/AbstractEventHookImpl.java | 27 +++++-- .../osgi/services/distribution/Activator.java | 10 +-- .../distribution/DiscoveredServiceTrackerImpl.java | 16 ++-- .../osgi/services/distribution/EventHookImpl.java | 49 ++++-------- .../distribution/DefaultProxyContainerFinder.java | 2 +- .../distribution/IDistributionConstants.java | 90 ++++++++++++++++++++++ .../services/distribution/IServiceConstants.java | 73 ------------------ 7 files changed, 136 insertions(+), 131 deletions(-) create mode 100644 compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IDistributionConstants.java delete mode 100644 compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IServiceConstants.java 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 e8a820bba..2f1f38a8d 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.IServiceConstants; +import org.eclipse.ecf.osgi.services.distribution.IDistributionConstants; import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration; import org.osgi.framework.*; import org.osgi.framework.hooks.service.EventHook; @@ -63,19 +63,29 @@ public abstract class AbstractEventHookImpl implements EventHook { } } + String[] getStringArrayFromPropertyValue(Object value) { + if (value == null) + return null; + else if (value instanceof String) + return new String[] { (String) value }; + else if (value instanceof String[]) + return (String[]) value; + else if (value instanceof Collection) + return (String[]) ((Collection) value).toArray(new String[] {}); + else + return null; + } + void handleRegisteredServiceEvent(ServiceReference serviceReference, Collection contexts) { // This checks to see if the serviceReference has any remote interfaces // declared via osgi.remote.interfaces property Object osgiRemotes = serviceReference - .getProperty(IServiceConstants.OSGI_REMOTE_INTERFACES); + .getProperty(IDistributionConstants.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) { - // The osgiRemotes should be of type String [] according to - // RFC119...if it's not String [] we ignore - String[] remoteInterfacesArr = (String[]) ((osgiRemotes instanceof String[]) ? osgiRemotes - : null); + String[] remoteInterfacesArr = getStringArrayFromPropertyValue(osgiRemotes); if (remoteInterfacesArr == null) { logError("handleRegisteredServiceEvent", "remoteInterfaces not of String [] type as required by RFC 119"); @@ -97,7 +107,8 @@ public abstract class AbstractEventHookImpl implements EventHook { return; } // Now call registerRemoteService - findContainersAndRegisterRemoteService(serviceReference, remoteInterfaces); + findContainersAndRegisterRemoteService(serviceReference, + remoteInterfaces); } } @@ -191,7 +202,7 @@ public abstract class AbstractEventHookImpl implements EventHook { .getProperty(Constants.OBJECTCLASS)); for (int i = 0; i < remoteInterfaces.length; i++) { String intf = remoteInterfaces[i]; - if (IServiceConstants.OSGI_REMOTE_INTERFACES_WILDCARD.equals(intf)) + if (IDistributionConstants.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 4af427ae9..43e135c11 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 @@ -135,7 +135,7 @@ public class Activator implements BundleActivator { // register all existing services which have the marker property try { final ServiceReference[] refs = this.context.getServiceReferences( - null, "(" + IServiceConstants.OSGI_REMOTE_INTERFACES + null, "(" + IDistributionConstants.REMOTE_INTERFACES + "=*)"); if (refs != null) { for (int i = 0; i < refs.length; i++) { @@ -148,13 +148,13 @@ public class Activator implements BundleActivator { // Setup properties for the distribution provider final Dictionary properties = new Hashtable(); - properties.put(DistributionProvider.PROP_KEY_VENDOR_NAME, + properties.put(DistributionProvider.VENDOR_NAME, DistributionProviderImpl.VENDOR_NAME); - properties.put(DistributionProvider.PROP_KEY_PRODUCT_NAME, + properties.put(DistributionProvider.PRODUCT_NAME, DistributionProviderImpl.PRODUCT_NAME); - properties.put(DistributionProvider.PROP_KEY_PRODUCT_VERSION, + properties.put(DistributionProvider.PRODUCT_VERSION, DistributionProviderImpl.PRODUCT_VERSION); - properties.put(DistributionProvider.PROP_KEY_SUPPORTED_INTENTS, + properties.put(DistributionProvider.SUPPORTED_INTENTS, distributionProvider.getSupportedIntents()); // Register distribution provider this.distributionProviderRegistration = this.context.registerService( 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 bcc735ab2..6a56f7760 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 @@ -17,7 +17,7 @@ import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.discovery.identity.IServiceID; import org.eclipse.ecf.osgi.services.discovery.*; import org.eclipse.ecf.osgi.services.distribution.IProxyContainerFinder; -import org.eclipse.ecf.osgi.services.distribution.IServiceConstants; +import org.eclipse.ecf.osgi.services.distribution.IDistributionConstants; import org.eclipse.ecf.remoteservice.*; import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent; import org.eclipse.ecf.remoteservice.events.IRemoteServiceUnregisteredEvent; @@ -37,12 +37,12 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { .synchronizedMap(new HashMap()); private List ecfRemoteServiceProperties = Arrays.asList(new String[] { Constants.SERVICE_ID, Constants.OBJECTCLASS, - 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 }); + IServicePublication.ENDPOINT_ID, + IServicePublication.ENDPOINT_INTERFACE_NAME, + IServicePublication.ENDPOINT_LOCATION, + IServicePublication.SERVICE_INTERFACE_NAME, + IServicePublication.SERVICE_INTERFACE_VERSION, + IServicePublication.SERVICE_PROPERTIES }); public DiscoveredServiceTrackerImpl(DistributionProviderImpl dp, IExecutor executor) { @@ -467,7 +467,7 @@ public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { .getProperty(propKeys[i])); } } - results.put(IServiceConstants.OSGI_REMOTE, remoteService); + results.put(IDistributionConstants.REMOTE, remoteService); return results; } 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 a4e79d892..e21b40e6e 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.ecf.core.IContainer; import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.Namespace; import org.eclipse.ecf.osgi.services.discovery.IServicePublication; +import org.eclipse.ecf.osgi.services.distribution.IDistributionConstants; import org.eclipse.ecf.osgi.services.distribution.IHostContainerFinder; -import org.eclipse.ecf.osgi.services.distribution.IServiceConstants; import org.eclipse.ecf.remoteservice.*; import org.eclipse.ecf.remoteservice.Constants; import org.osgi.framework.*; @@ -31,32 +31,11 @@ public class EventHookImpl extends AbstractEventHookImpl { ServiceReference serviceReference, String[] remoteInterfaces) { // Get optional service property osgi.remote.configuration.type - Object osgiRemoteConfigurationType = serviceReference - .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 - String[] remoteConfigurationType = null; - if (osgiRemoteConfigurationType != null) { - if (!(osgiRemoteConfigurationType instanceof String[])) { - logError("handleRegisteredServiceEvent", - "osgi.remote.configuration.type is not String[] as required by RFC 119"); - return; - } - remoteConfigurationType = (String[]) osgiRemoteConfigurationType; - } + String[] remoteConfigurationType = getStringArrayFromPropertyValue(serviceReference + .getProperty(IDistributionConstants.REMOTE_CONFIGURATION_TYPE)); // Get optional service property service.intents - Object osgiRemoteRequiresIntents = serviceReference - .getProperty(IServiceConstants.OSGI_REMOTE_REQUIRES_INTENTS); - String[] remoteRequiresIntents = null; - if (osgiRemoteRequiresIntents != null) { - if (!(osgiRemoteRequiresIntents instanceof String[])) { - logError("handleRegisteredServiceEvent", - "service.intents is not String[] as required by RFC 119"); - return; - } - osgiRemoteRequiresIntents = (String[]) osgiRemoteRequiresIntents; - } + String[] remoteRequiresIntents = getStringArrayFromPropertyValue(serviceReference + .getProperty(IDistributionConstants.REMOTE_REQUIRES_INTENTS)); // Now call out to find host remote service containers IRemoteServiceContainer[] rsContainers = findRemoteServiceContainers( serviceReference, remoteInterfaces, remoteConfigurationType, @@ -115,11 +94,11 @@ public class EventHookImpl extends AbstractEventHookImpl { IRemoteServiceRegistration remoteRegistration) { final Dictionary properties = new Properties(); // Set mandatory ServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME - properties.put(ServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME, + properties.put(ServicePublication.SERVICE_INTERFACE_NAME, getAsCollection(remoteInterfaces)); // Set optional ServicePublication.PROP_KEY_SERVICE_PROPERTIES - properties.put(ServicePublication.PROP_KEY_SERVICE_PROPERTIES, + properties.put(ServicePublication.SERVICE_PROPERTIES, getServicePropertiesForRemotePublication(ref)); IContainer container = rsContainer.getContainer(); @@ -129,8 +108,7 @@ public class EventHookImpl extends AbstractEventHookImpl { // ServicePublication.PROP_KEY_ENDPOINT_ID...since // it won't handle some Strings with (e.g. slp) provider ID endpointID = container.getID(); - properties.put(IServicePublication.PROP_KEY_ENDPOINT_CONTAINERID, - container.getID()); + properties.put(IServicePublication.ENDPOINT_CONTAINERID, endpointID); // 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 @@ -139,8 +117,7 @@ public class EventHookImpl extends AbstractEventHookImpl { 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); + properties.put(IServicePublication.TARGET_CONTAINERID, targetID); } // Set remote service namespace (String) @@ -210,10 +187,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, - IServiceConstants.OSGI_REMOTE_INTERFACES, - IServiceConstants.OSGI_REMOTE_REQUIRES_INTENTS, - IServiceConstants.OSGI_REMOTE, - IServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE, + IDistributionConstants.REMOTE_INTERFACES, + IDistributionConstants.REMOTE_REQUIRES_INTENTS, + IDistributionConstants.REMOTE, + IDistributionConstants.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/DefaultProxyContainerFinder.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/DefaultProxyContainerFinder.java index b0b20cc48..d1c335c94 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/DefaultProxyContainerFinder.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/DefaultProxyContainerFinder.java @@ -49,7 +49,7 @@ public class DefaultProxyContainerFinder extends AbstractContainerFinder if (includeContainerWithConnectNamespace( allContainers[i], (String) endpointDescription - .getProperty(IServicePublication.PROP_KEY_ENDPOINT_CONTAINERID_NAMESPACE))) + .getProperty(IServicePublication.ENDPOINT_CONTAINERID_NAMESPACE))) results.add(allContainers[i]); } return (IContainer[]) results.toArray(new IContainer[] {}); diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IDistributionConstants.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IDistributionConstants.java new file mode 100644 index 000000000..065ad13a7 --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IDistributionConstants.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * 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.osgi.service.distribution.DistributionConstants; + +public interface IDistributionConstants { + + /** + * This service registration property indicates that the provided service is + * to be made available remotely, which implies that it is suitable for + * remote invocations. This property lists a subset of service interface + * names specified in the BundleContext.registerService call, + * denoting the interfaces that are suitable for remoting. 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 of this property is of type String, String[] or Collection of + * String. + */ + public static final String REMOTE_INTERFACES = DistributionConstants.REMOTE_INTERFACES; + + /** + * This optional service registration property contains a list of intents + * that should be satisfied when publishing this service remotely. If a + * Distribution Provider 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, String[] or Collection of + * String. + */ + public static final String REMOTE_REQUIRES_INTENTS = DistributionConstants.REMOTE_REQUIRES_INTENTS; + + /** + * This optional service registration property identifies the metadata type + * of additional metadata associated with the service provider or consumer, + * e.g. "sca" Multiple types and thus sets of additional metadata may be + * provided. + *

+ * The value of this property is of type String, String[] or Collection of + * String. + */ + public static final String REMOTE_CONFIGURATION_TYPE = DistributionConstants.REMOTE_CONFIGURATION_TYPE; + + /** + * This optional service registration property contains a list of intents + * provided by the service itself. The property advertises capabilities of + * the service implementation and can be used by the service consumer in the + * lookup filter to only select a service that provides certain qualities of + * service. + *

+ * These service intents may be interpreted by other framework components + * for example to take them into account when exposing that service + * remotely. + *

+ * In case of proxies to remote services the value of this property is a + * union of the value specified by the service provider, plus its + * remote-specific intents (see {@link #REMOTE_REQUIRES_INTENTS} ), plus any + * intents which the Distribution Software adds to describe characteristics + * of the distribution mechanism. Therefore the value of this property can + * vary between the client side proxy and the server side service. + *

+ * The value of this property is of type String, String[] or Collection of + * String. + */ + public static final String DEPLOYMENT_INTENTS = DistributionConstants.DEPLOYMENT_INTENTS; + + /** + * This service registration property is set on client side service proxies + * registered in the OSGi Service Registry. This allows service consumers to + * identify remote services if needed. + *

+ * The value of this property is undefined. The simple fact that the + * property is set denotes that the service is running remotely. + */ + public static final String REMOTE = DistributionConstants.REMOTE; + + public static final String 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/IServiceConstants.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IServiceConstants.java deleted file mode 100644 index 10c34c12d..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/IServiceConstants.java +++ /dev/null @@ -1,73 +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 IServiceConstants { - - /* - * service.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 it’s 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 SERVICE_INTENTS = "service.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.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"; - - /* - * 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"; - - public static final String OSGI_REMOTE_INTERFACES_WILDCARD = "*"; - - public static final String ECF_REMOTE_CONFIGURATION_TYPE = "ecf"; - -} -- cgit v1.2.3