From b323497c62d1c7597e3fc5ba8457e07443b48300 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 11 Nov 2009 01:33:53 +0000 Subject: Add Import/Export Reference git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834738 13f79535-47bb-0310-9956-ffa450edef68 --- .../remoteserviceadmin/EndpointDescription.java | 337 +++++++++++++-------- .../remoteserviceadmin/EndpointPermission.java | 6 + .../osgi/remoteserviceadmin/ExportReference.java | 43 +++ .../remoteserviceadmin/ExportRegistration.java | 15 +- .../osgi/remoteserviceadmin/ImportReference.java | 42 +++ .../remoteserviceadmin/ImportRegistration.java | 16 +- .../osgi/remoteserviceadmin/RemoteConstants.java | 8 +- .../remoteserviceadmin/RemoteServiceAdmin.java | 14 +- .../RemoteServiceAdminEvent.java | 34 ++- .../impl/ExportReferenceImpl.java | 52 ++++ .../impl/ExportRegistrationImpl.java | 7 + .../impl/ImportReferenceImpl.java | 52 ++++ .../impl/ImportRegistrationImpl.java | 29 +- .../impl/OSGiServiceImporter.java | 2 +- .../impl/RemoteServiceAdminImpl.java | 14 +- 15 files changed, 465 insertions(+), 206 deletions(-) create mode 100644 java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ExportReference.java create mode 100644 java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ImportReference.java create mode 100644 java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ExportReferenceImpl.java create mode 100644 java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ImportReferenceImpl.java (limited to 'java') diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/EndpointDescription.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/EndpointDescription.java index 23a91b89ef..9fda882738 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/EndpointDescription.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/EndpointDescription.java @@ -15,14 +15,21 @@ */ package org.apache.tuscany.sca.osgi.remoteserviceadmin; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.HashMap; +import java.util.Dictionary; +import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.TreeMap; import org.osgi.framework.Constants; +import org.osgi.framework.Filter; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; import org.osgi.framework.Version; @@ -36,28 +43,20 @@ import org.osgi.framework.Version; * * An Endpoint Description reflects the perspective of an importer. That is, the * property keys have been chosen to match filters that are created by client - * bundles that need a service. - * - * TODO Automatically calculate versions of interface packages? - * - * TODO Constructor that takes a class? - * - * TODO Skipping of service.exported.* properties? - * - * TODO qualified intents? - * + * bundles that need a service. Therefore the map must not contain any + * service.exported.* property and must contain the service.imported.* ones. * + * The service.intents property contains the intents provided by the service + * itself combined with the intents added by the exporting distribution + * provider. Qualified intents appear expanded on this property. * * @Immutable * @version $Revision$ */ public class EndpointDescription { - private final Map /* */properties = new HashMap/* - * - */(); - private final List /* String */interfaces; + private final Map properties; + private final List interfaces; private final long remoteServiceId; private final String remoteFrameworkUUID; private final String remoteUri; @@ -65,103 +64,91 @@ public class EndpointDescription { /** * Create an Endpoint Description based on a Map. * - * @param properties + * @param properties The map to create the Endpoint Description from. * @throws IllegalArgumentException When the properties are not proper for * an Endpoint Description */ - public EndpointDescription(Map/* */properties) throws IllegalArgumentException { - this.properties.putAll(properties); - - interfaces = verifyInterfacesProperty(); - remoteServiceId = verifyLongProperty(RemoteConstants.SERVICE_REMOTE_ID); - remoteFrameworkUUID = verifyStringProperty(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID); - remoteUri = verifyStringProperty(RemoteConstants.SERVICE_REMOTE_URI); + public EndpointDescription(Map properties) { + this(properties, null); } /** * Create an Endpoint Description based on a reference and optionally a map - * of additional properties. + * of additional properties. The properties on the original service take + * precedence over the ones in the map. * - * @param ref A service reference that can be exported + * @param reference A service reference that can be exported * @param properties Additional properties to add. Can be null. - * @throws IllegalArgumentException + * @throws IllegalArgumentException When the properties are not proper for + * an Endpoint Description */ - public EndpointDescription(ServiceReference ref, Map /* */properties) - throws IllegalArgumentException { - if (properties != null) { - this.properties.putAll(properties); + public EndpointDescription(ServiceReference reference, Map properties) { + this(properties, reference); + if (reference == null) { + throw new NullPointerException("reference must not be null"); + } + } + + private EndpointDescription(Map map, ServiceReference reference) { + Map props = new TreeMap(String.CASE_INSENSITIVE_ORDER); + + if (map != null) { + try { + props.putAll(map); + } catch (ClassCastException e) { + IllegalArgumentException iae = new IllegalArgumentException("non-String key in properties"); + iae.initCause(e); + throw iae; + } + if (props.size() < map.size()) { + throw new IllegalArgumentException("duplicate keys with different cases in properties"); + } } - String[] keys = ref.getPropertyKeys(); - for (int i = 0; i > keys.length; i++) - properties.put(keys[i], ref.getProperty(keys[i])); + if (reference != null) { + for (String key : reference.getPropertyKeys()) { + if (!props.containsKey(key)) { + props.put(key, reference.getProperty(key)); + } + } + } + properties = Collections.unmodifiableMap(props); + /* properties must be initialized before calling the following methods */ interfaces = verifyInterfacesProperty(); remoteServiceId = verifyLongProperty(RemoteConstants.SERVICE_REMOTE_ID); remoteFrameworkUUID = verifyStringProperty(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID); remoteUri = verifyStringProperty(RemoteConstants.SERVICE_REMOTE_URI); } - /** - * Create an Endpoint Description based on the URI, the remote service ID - * and the interface names, and optionally service properties. - * - * @param uri The URI of the remote service. - * @param interfaceNames The names of the interfaces of the service to - * consider. - * @param remoteServiceId the remote service ID. - * @param properties Optionally service properties. - */ - public EndpointDescription(String uri, String[] interfaceNames, int remoteServiceId, Map properties) { - if (uri == null) { - throw new IllegalArgumentException("URI must not be null"); - } - if (interfaceNames == null) { - throw new IllegalArgumentException("Interfaces must not be null"); - } - this.remoteUri = uri; - this.interfaces = Arrays.asList(interfaceNames); - this.remoteServiceId = remoteServiceId; - this.remoteFrameworkUUID = (String)properties.get(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID); - if (properties != null) { - this.properties.putAll(properties); - } - if (interfaceNames != null) { - this.properties.put(Constants.OBJECTCLASS, interfaceNames); - } - this.properties.put(RemoteConstants.SERVICE_REMOTE_URI, uri); - if (remoteServiceId <= 0) { - this.properties.put(RemoteConstants.SERVICE_REMOTE_ID, new Integer(remoteServiceId)); - } - } - /** * Verify and obtain the interface list from the properties. * * @return A list with the interface names. - * @throws IllegalArgumentException when + * @throws IllegalArgumentException When the properties do not contain the + * right values for and interface list. + * */ - private List /* */verifyInterfacesProperty() { - List l = null; - - Object objectClass = properties.get(Constants.OBJECTCLASS); - if (objectClass == null) - l = Collections.EMPTY_LIST; - else if (!(objectClass instanceof String[])) + private List verifyInterfacesProperty() { + Object o = properties.get(Constants.OBJECTCLASS); + if (o == null) { + return Collections.EMPTY_LIST; + } + if (!(o instanceof String[])) { throw new IllegalArgumentException("objectClass must be a String[]"); - else { - l = Collections.unmodifiableList(Arrays.asList((String[])objectClass)); - for (Iterator i = l.iterator(); i.hasNext();) { - String interf = (String)i.next(); - try { - getInterfaceVersion(interf); - } catch (Exception e) { - throw new IllegalArgumentException("Improper version for interface " + interf + " caused by " + e); - } + } + String[] objectClass = (String[])o; + for (String interf : objectClass) { + try { + getInterfaceVersion(interf); + } catch (IllegalArgumentException e) { + IllegalArgumentException iae = new IllegalArgumentException("Improper version for interface " + interf); + iae.initCause(e); + throw iae; } } - return l; + return Collections.unmodifiableList(Arrays.asList(objectClass)); } /** @@ -178,7 +165,7 @@ public class EndpointDescription { throw new IllegalArgumentException("Required property not set: " + propName); } if (!(r instanceof String)) { - throw new IllegalArgumentException("Required property is not a string: " + propName); + throw new IllegalArgumentException("Required property is not a String: " + propName); } return (String)r; } @@ -193,7 +180,6 @@ public class EndpointDescription { */ private long verifyLongProperty(String propName) { Object r = properties.get(propName); - long result; if (r == null) { throw new IllegalArgumentException("Required property not set: " + propName); } @@ -201,11 +187,13 @@ public class EndpointDescription { throw new IllegalArgumentException("Required property is not a string: " + propName); } try { - result = Long.parseLong((String)r); + return Long.parseLong((String)r); } catch (NumberFormatException e) { - throw new IllegalArgumentException("Required property cannot be parsed as a long: " + propName); + IllegalArgumentException iae = + new IllegalArgumentException("Required property cannot be parsed as a long: " + propName); + iae.initCause(e); + throw iae; } - return result; } /** @@ -225,7 +213,7 @@ public class EndpointDescription { } /** - * Answer the list of interfaces implemented by the exported service. + * Provide the list of interfaces implemented by the exported service. * * If this Endpoint Description does not map to a service, then this List * must be empty. @@ -236,43 +224,42 @@ public class EndpointDescription { * @return The read only list of Java interface names accessible by this * endpoint. */ - public List/* */getInterfaces() { + public List getInterfaces() { return interfaces; } /** - * Answer the version of the given interface. + * Provide the version of the given interface. * * The version is encoded by prefixing the given interface name with * endpoint.version., and then using this as a property key. - * The value must then be the Version object. For example: + * For example: * *
      * endpoint.version.com.acme.Foo
      * 
* + * The value of this property is in String format and will be converted to a + * Version object by this method. + * * @param name The name of the interface for which a version is requested * @return The version of the given interface or null if the * interface has no version in this Endpoint Description */ public Version getInterfaceVersion(String name) { - String v = (String)properties.get("endpoint.version." + name); - if (v == null) { - return Version.emptyVersion; - } else { - return new Version(v); - } + String version = (String)properties.get("endpoint.version." + name); + return Version.parseVersion(version); } /** - * Returns the service id for the service exported through this - * endpoint. + * Returns the service id for the service exported through this endpoint. * - * This is the service id under which the framework has registered the service. This - * field together with the Framework UUID is a globally unique id for a service. + * This is the service id under which the framework has registered the + * service. This field together with the Framework UUID is a globally unique + * id for a service. * - * @return Service id of a service or 0 if this Endpoint - * Description does not relate to an OSGi service + * @return Service id of a service or 0 if this Endpoint Description does + * not relate to an OSGi service * */ public long getRemoteServiceID() { @@ -293,12 +280,11 @@ public class EndpointDescription { * This value represents the * {@link RemoteConstants#SERVICE_IMPORTED_CONFIGS} * - * @return The configuration type used for the associated endpoint and - * optionally synonyms. + * @return An unmodifiable list of the configuration types used for the + * associated endpoint and optionally synonyms. */ - public List/* */getConfigurationTypes() { - // TODO - return null; + public List getConfigurationTypes() { + return getStringPlusProperty(RemoteConstants.SERVICE_IMPORTED_CONFIGS); } /** @@ -311,21 +297,66 @@ public class EndpointDescription { * The property the intents come from is * {@link RemoteConstants#SERVICE_INTENTS} * - * @return A list of expanded intents that are provided by this endpoint. + * @return An unmodifiable list of expanded intents that are provided by + * this endpoint. + */ + public List getIntents() { + return getStringPlusProperty(RemoteConstants.SERVICE_INTENTS); + } + + /** + * Reads a 'String+' property from the properties map, which may be of type + * String, String[] or Collection and returns it as an unmodifiable + * List. + * + * @param key The property + * @return An unmodifiable list + * @throws Illegal */ - public List/* */getIntents() { - // TODO - return null; + private List getStringPlusProperty(String key) { + Object value = properties.get(key); + if (value == null) { + return Collections.EMPTY_LIST; + } + + if (value instanceof String) { + return Collections.singletonList((String)value); + } + if (value instanceof String[]) { + String[] values = (String[])value; + List result = new ArrayList(values.length); + for (String v : values) { + if (v != null) { + result.add(v); + } + } + return result; + } + + if (value instanceof Collection) { + Collection values = (Collection)value; + List result = new ArrayList(values.size()); + for (Iterator iter = values.iterator(); iter.hasNext();) { + Object v = iter.next(); + if ((v != null) && (v instanceof String)) { + result.add((String)v); + } + } + return result; + } + + return Collections.EMPTY_LIST; } /** - * Return the framework UUID, if present. + * Return the framework UUID for the remote service, if present. * - * The property the intents come from is + * The property the framework UUID comes from is * {@link RemoteConstants#SERVICE_REMOTE_FRAMEWORK_UUID} * - * @return Remote Framework UUID, or null if this endpoint is not associated with an OSGi service + * @return Remote Framework UUID, or null if this endpoint is not associated + * with an OSGi service */ public String getRemoteFrameworkUUID() { return remoteFrameworkUUID; @@ -337,9 +368,8 @@ public class EndpointDescription { * @return An unmodifiable map referring to the properties of this Endpoint * Description. */ - public Map/* */getProperties() { - // TODO - return Collections.unmodifiableMap(properties); + public Map getProperties() { + return properties; } /** @@ -366,20 +396,77 @@ public class EndpointDescription { /** * Two endpoints are equal if their URIs are equal, the hash code is * therefore derived from the URI. + * + * @return The hashcode of this endpoint. */ public int hashCode() { - // TODO return getRemoteURI().hashCode(); } /** * Two endpoints are equal if their URIs are equal. + * + * @return */ public boolean equals(Object other) { - if (other instanceof EndpointDescription) { - return getRemoteURI().equals(((EndpointDescription)other).getRemoteURI()); + if (this == other) { + return true; } - return false; + if (!(other instanceof EndpointDescription)) { + return false; + } + return getRemoteURI().equals(((EndpointDescription)other).getRemoteURI()); + } + + /** + * TODO + * + * @param filter + * @return + * @throws InvalidSyntaxException + */ + public boolean match(String filter) throws InvalidSyntaxException { + Filter f = FrameworkUtil.createFilter(filter); + Dictionary d = new UnmodifiableDictionary(properties); + return f.matchCase(d); } + /** + * Unmodifiable wrapper for Dictionary. + */ + private static class UnmodifiableDictionary extends Dictionary { + private final Map wrapped; + + UnmodifiableDictionary(Map wrapped) { + this.wrapped = wrapped; + } + + public Enumeration elements() { + return (Enumeration)Collections.enumeration(wrapped.values()); + } + + public V get(Object key) { + return wrapped.get(key); + } + + public boolean isEmpty() { + return wrapped.isEmpty(); + } + + public Enumeration keys() { + return (Enumeration)Collections.enumeration(wrapped.keySet()); + } + + public V put(K key, V value) { + throw new UnsupportedOperationException(); + } + + public V remove(Object key) { + throw new UnsupportedOperationException(); + } + + public int size() { + return wrapped.size(); + } + } } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/EndpointPermission.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/EndpointPermission.java index 74f913583e..1e12547ab5 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/EndpointPermission.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/EndpointPermission.java @@ -58,6 +58,12 @@ import org.osgi.framework.FrameworkUtil; import org.osgi.framework.InvalidSyntaxException; /** + *
+ * -------------------------------------------------------------
+ * THIS CLASS IS A PLACEHOLDER (COPIED FROM SERVICE PERMISSION)!
+ * -------------------------------------------------------------
+ * 
+ * * A bundle's authority to register or get a service. *
    *
  • The register action allows a bundle to register a service diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ExportReference.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ExportReference.java new file mode 100644 index 0000000000..dd6b71a021 --- /dev/null +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ExportReference.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) OSGi Alliance (2008, 2009). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.sca.osgi.remoteserviceadmin; + +import org.osgi.framework.ServiceReference; + +/** + * An Export Reference associates a service with a local endpoint. + * + * The Export Reference can be used to reference an exported service. When the + * service is no longer exported, all methods must return null; + * + * @ThreadSafe + */ +public interface ExportReference { + /** + * Return the service being exported. + * + * @return The service being exported, must be null when this + * registration is unregistered. + */ + ServiceReference getExportedService(); + + /** + * Return the Endpoint Description that is created for this registration. + * + * @return the local Endpoint Description + */ + EndpointDescription getEndpointDescription(); +} diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ExportRegistration.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ExportRegistration.java index 0e747293cb..231d742220 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ExportRegistration.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ExportRegistration.java @@ -31,21 +31,12 @@ import org.osgi.framework.ServiceReference; */ public interface ExportRegistration { /** - * Return the service being exported. + * Return the Export Reference for the exported service. * - * @return The service being exported, must be null when this - * registration is unregistered. + * @return An Export Reference for this registration * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} */ - ServiceReference getExportedService() throws IllegalStateException; - - /** - * Return the Endpoint Description that is created for this registration. - * - * @return the local Endpoint Description - * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} - */ - EndpointDescription getEndpointDescription(); + ExportReference getExportReference() throws IllegalStateException; /** * Delete the local endpoint and disconnect any remote distribution diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ImportReference.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ImportReference.java new file mode 100644 index 0000000000..ead03edd58 --- /dev/null +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ImportReference.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) OSGi Alliance (2008, 2009). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.sca.osgi.remoteserviceadmin; + +import org.osgi.framework.ServiceReference; + +/** + * An Import Reference associates an active proxy service to a remote endpoint. + * + * The Import Reference can be used to reference an imported service. When the + * service is no longer imported, all methods must return null; + * + * @ThreadSafe + */ +public interface ImportReference { + /** + * Answer the associated Service Reference for the proxy to the endpoint. + * + * @return A Service Reference to the proxy for the endpoint. + */ + ServiceReference getImportedService(); + + /** + * Answer the associated remote Endpoint Description. + * + * @return A Endpoint Description for the remote endpoint. + */ + EndpointDescription getImportedEndpointDescription(); +} diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ImportRegistration.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ImportRegistration.java index 0346902383..28dcc213c9 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ImportRegistration.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/ImportRegistration.java @@ -15,8 +15,6 @@ */ package org.apache.tuscany.sca.osgi.remoteserviceadmin; -import org.osgi.framework.ServiceReference; - /** * An Import Registration associates an active proxy service to a remote * endpoint. @@ -29,20 +27,12 @@ import org.osgi.framework.ServiceReference; */ public interface ImportRegistration { /** - * Answer the associated Service Reference for the proxy to the endpoint. - * - * @return A Service Reference to the proxy for the endpoint. - * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} - */ - ServiceReference getImportedService(); - - /** - * Answer the associated remote Endpoint Description. + * Answer the associated Export Reference. * - * @return A Endpoint Description for the remote endpoint. + * @return An Import Reference for this registration * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} */ - EndpointDescription getImportedEndpointDescription(); + ImportReference getImportedReference(); /** * Unregister this Import Registration. This must close the connection diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteConstants.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteConstants.java index afc3355c38..63ce2ed042 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteConstants.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteConstants.java @@ -131,7 +131,7 @@ public class RemoteConstants { * * The value of this property is of type String+. */ - public final String SERVICE_IMPORTED_CONFIGS = "service.imported.configs"; + public final static String SERVICE_IMPORTED_CONFIGS = "service.imported.configs"; /** * A list of intents that this service implements. This property has dual @@ -152,19 +152,19 @@ public class RemoteConstants { * endpoint following the URI syntax. As far as this specification is * concerned, this unique id is opaque. */ - final public static String SERVICE_REMOTE_URI = "service.remote.uri"; + public final static String SERVICE_REMOTE_URI = "service.remote.uri"; /** * The property key for the endpoint service id. This is a unique id for a * service based on the framework id '.' service id or another model. As far as this specification is * concerned, this unique id is opaque. */ - final public static String SERVICE_REMOTE_ID = "service.remote.id"; + public final static String SERVICE_REMOTE_ID = "service.remote.id"; /** * The property key for the endpoint service id. This is a unique id for a * service based on the framework id '.' service id or another model. As far as this specification is * concerned, this unique id is opaque. */ - final public static String SERVICE_REMOTE_FRAMEWORK_UUID = "service.remote.framework.id"; + public final static String SERVICE_REMOTE_FRAMEWORK_UUID = "service.remote.framework.id"; } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteServiceAdmin.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteServiceAdmin.java index dade67c096..b79cfbe330 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteServiceAdmin.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteServiceAdmin.java @@ -97,29 +97,23 @@ public interface RemoteServiceAdmin { ImportRegistration importService(EndpointDescription endpoint); /** - * Answer the currently active Export Registrations. + * Answer the currently active Export References. * * @return A collection of Export Registrations that are currently active. * @throws SecurityException When the caller no * {@link EndpointPermission#READ} could be obtained - * - * TODO I guess we must ensure these registrations cannot be closed? Only the owners should be able to close them, - * TODO should we make sure that the list contains the registration objects that the caller created? */ - Collection/* */getExportedServices(); + Collection/* */getExportedServices(); /** - * Answer the currently active Import Registrations. + * Answer the currently active Import References. * * @throws SecurityException When the caller no EndpointPermission LIST * could be obtained * @return A collection of Import Registrations that are currently active. * @throws SecurityException When the caller no * {@link EndpointPermission#READ} could be obtained - * - * TODO I guess we must ensure these registrations cannot be closed? Only the owners should be able to close them, - * TODO should we make sure that the list contains the registration objects that the caller created? */ - Collection/* */getImportedEndpoints(); + Collection/* */getImportedEndpoints(); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteServiceAdminEvent.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteServiceAdminEvent.java index d0eda01f6e..71f914b085 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteServiceAdminEvent.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/RemoteServiceAdminEvent.java @@ -76,8 +76,8 @@ public class RemoteServiceAdminEvent { */ public static final int IMPORT_WARNING = 8; - private final ImportRegistration importRegistration; - private final ExportRegistration exportRegistration; + private final ImportReference importReference; + private final ExportReference exportReference; private final Throwable exception; private final int type; private final Bundle source; @@ -87,19 +87,19 @@ public class RemoteServiceAdminEvent { * * @param type The event type * @param source The source bundle, must not be null. - * @param importRegistration The importRegistration, can be null. - * @param exportRegistration The exportRegistration, can be null. + * @param importReference The importReference, can be null. + * @param exportReference The exportReference, can be null. * @param exception Any exceptions encountered, can be null */ RemoteServiceAdminEvent(int type, Bundle source, - ImportRegistration importRegistration, - ExportRegistration exportRegistration, + ImportReference importReference, + ExportReference exportReference, Throwable exception) { this.type = type; this.source = source; - this.importRegistration = importRegistration; - this.exportRegistration = exportRegistration; + this.importReference = importReference; + this.exportReference = exportReference; this.exception = exception; } @@ -108,10 +108,11 @@ public class RemoteServiceAdminEvent { * * @param type The event type * @param source The source bundle, must not be null. - * @param exportRegistration The exportRegistration, can not be null. + * @param exportRegistration The exportRegistration, can not be + * null. * @param exception Any exceptions encountered, can be null */ - public RemoteServiceAdminEvent(int type, Bundle source, ExportRegistration exportRegistration, Throwable exception) { + public RemoteServiceAdminEvent(int type, Bundle source, ExportReference exportRegistration, Throwable exception) { this(type, source, null, exportRegistration, exception); } @@ -120,25 +121,26 @@ public class RemoteServiceAdminEvent { * * @param type The event type * @param source The source bundle, must not be null. - * @param importRegistration The importRegistration, can not be null. + * @param importRegistration The importRegistration, can not be + * null. * @param exception Any exceptions encountered, can be null */ - public RemoteServiceAdminEvent(int type, Bundle source, ImportRegistration importRegistration, Throwable exception) { + public RemoteServiceAdminEvent(int type, Bundle source, ImportReference importRegistration, Throwable exception) { this(type, source, importRegistration, null, exception); } /** * @return the importRegistration or null */ - public ImportRegistration getImportRegistration() { - return importRegistration; + public ImportReference getImportReference() { + return importReference; } /** * @return the exportRegistration or null */ - public ExportRegistration getExportRegistration() { - return exportRegistration; + public ExportReference getExportReference() { + return exportReference; } /** diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ExportReferenceImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ExportReferenceImpl.java new file mode 100644 index 0000000000..a36f388bf6 --- /dev/null +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ExportReferenceImpl.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl; + +import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription; +import org.apache.tuscany.sca.osgi.remoteserviceadmin.ExportReference; +import org.osgi.framework.ServiceReference; + +/** + * + */ +public class ExportReferenceImpl implements ExportReference { + private final ServiceReference exportedService; + private final EndpointDescription endpointDescription; + + /** + * @param exportedService + * @param endpointDescription + */ + public ExportReferenceImpl(ServiceReference exportedService, EndpointDescription endpointDescription) { + super(); + this.exportedService = exportedService; + this.endpointDescription = endpointDescription; + } + + public ServiceReference getExportedService() { + return exportedService; + } + + public EndpointDescription getEndpointDescription() { + return endpointDescription; + } + + +} diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ExportRegistrationImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ExportRegistrationImpl.java index 58d72f389f..c31b1b1c70 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ExportRegistrationImpl.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ExportRegistrationImpl.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription; +import org.apache.tuscany.sca.osgi.remoteserviceadmin.ExportReference; import org.apache.tuscany.sca.osgi.remoteserviceadmin.ExportRegistration; import org.osgi.framework.ServiceReference; @@ -32,6 +33,7 @@ public class ExportRegistrationImpl implements ExportRegistration { private ServiceReference exportedService; private EndpointDescription endpointDescription; private Throwable exception; + private ExportReference exportReference; /** * @param exportedService @@ -86,4 +88,9 @@ public class ExportRegistrationImpl implements ExportRegistration { return node; } + public ExportReference getExportReference() throws IllegalStateException { + // TODO Auto-generated method stub + return null; + } + } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ImportReferenceImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ImportReferenceImpl.java new file mode 100644 index 0000000000..453d9a8020 --- /dev/null +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ImportReferenceImpl.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl; + +import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription; +import org.apache.tuscany.sca.osgi.remoteserviceadmin.ImportReference; +import org.osgi.framework.ServiceReference; + +/** + * + */ +public class ImportReferenceImpl implements ImportReference { + + private final ServiceReference importedService; + private final EndpointDescription endpointDescription; + + /** + * @param exportedService + * @param endpointDescription + */ + public ImportReferenceImpl(ServiceReference importedService, EndpointDescription endpointDescription) { + super(); + this.importedService = importedService; + this.endpointDescription = endpointDescription; + } + + public ServiceReference getImportedService() { + return importedService; + } + + public EndpointDescription getImportedEndpointDescription() { + return endpointDescription; + } + +} diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ImportRegistrationImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ImportRegistrationImpl.java index d085bd282d..e89a05233b 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ImportRegistrationImpl.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/ImportRegistrationImpl.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription; +import org.apache.tuscany.sca.osgi.remoteserviceadmin.ImportReference; import org.apache.tuscany.sca.osgi.remoteserviceadmin.ImportRegistration; import org.osgi.framework.ServiceReference; @@ -29,8 +30,7 @@ import org.osgi.framework.ServiceReference; */ public class ImportRegistrationImpl implements ImportRegistration { private Node node; - private ServiceReference exportedService; - private EndpointDescription endpointDescription; + private ImportReference importReference; private Throwable exception; /** @@ -39,13 +39,12 @@ public class ImportRegistrationImpl implements ImportRegistration { * @param exception */ public ImportRegistrationImpl(Node node, - ServiceReference exportedService, + ServiceReference importedService, EndpointDescription endpointDescription, Throwable exception) { super(); this.node = node; - this.exportedService = exportedService; - this.endpointDescription = endpointDescription; + this.importReference = new ImportReferenceImpl(importedService, endpointDescription); this.exception = exception; } @@ -53,11 +52,10 @@ public class ImportRegistrationImpl implements ImportRegistration { * @param exportedService * @param endpointDescription */ - public ImportRegistrationImpl(Node node, ServiceReference exportedService, EndpointDescription endpointDescription) { + public ImportRegistrationImpl(Node node, ServiceReference importedService, EndpointDescription endpointDescription) { super(); this.node = node; - this.exportedService = exportedService; - this.endpointDescription = endpointDescription; + this.importReference = new ImportReferenceImpl(importedService, endpointDescription); } /** @@ -69,16 +67,7 @@ public class ImportRegistrationImpl implements ImportRegistration { node = null; } exception = null; - endpointDescription = null; - exportedService = null; - } - - public ServiceReference getImportedService() { - return exportedService; - } - - public EndpointDescription getImportedEndpointDescription() { - return endpointDescription; + importReference = null; } public Throwable getException() { @@ -89,4 +78,8 @@ public class ImportRegistrationImpl implements ImportRegistration { return node; } + public ImportReference getImportedReference() { + return importReference; + } + } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java index c869ab8c14..93b03d8075 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java @@ -88,7 +88,7 @@ public class OSGiServiceImporter extends AbstractOSGiServiceHandler { } public void unimportService(ImportRegistration importRegistration) { - Node node = (Node)importRegistration.getImportedService().getProperty("sca.node"); + Node node = (Node)importRegistration.getImportedReference().getImportedService().getProperty("sca.node"); node.stop(); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java index 9da7b5f014..28b2d864aa 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java @@ -131,7 +131,7 @@ public class RemoteServiceAdminImpl implements RemoteServiceAdmin, ManagedServic private void fireExportEvents(Bundle source, List exportRegistrations) { for (ExportRegistration registration : exportRegistrations) { RemoteServiceAdminEvent rsaEvent = - new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION, source, registration, + new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION, source, registration.getExportReference(), registration.getException()); EventAdmin eventAdmin = getEventAdmin(); if (eventAdmin != null) { @@ -211,13 +211,13 @@ public class RemoteServiceAdminImpl implements RemoteServiceAdmin, ManagedServic props.put("bundle-symbolicname", rsaBundle.getSymbolicName()); props.put("bundle-version", rsaBundle.getHeaders().get(Constants.BUNDLE_VERSION)); props.put("cause", rsaEvent.getException()); - props.put("import.registration", rsaEvent.getImportRegistration()); - props.put("export.registration", rsaEvent.getExportRegistration()); + props.put("import.reference", rsaEvent.getImportReference()); + props.put("export.reference", rsaEvent.getExportReference()); EndpointDescription ep = null; - if (rsaEvent.getImportRegistration() != null) { - ep = rsaEvent.getImportRegistration().getImportedEndpointDescription(); + if (rsaEvent.getImportReference() != null) { + ep = rsaEvent.getImportReference().getImportedEndpointDescription(); } else { - ep = rsaEvent.getExportRegistration().getEndpointDescription(); + ep = rsaEvent.getExportReference().getEndpointDescription(); } props.put("service.remote.id", ep.getRemoteServiceID()); props.put("service.remote.uuid", ep.getRemoteFrameworkUUID()); @@ -231,7 +231,7 @@ public class RemoteServiceAdminImpl implements RemoteServiceAdmin, ManagedServic private void fireImportEvents(Bundle source, ImportRegistration registration) { RemoteServiceAdminEvent rsaEvent = - new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_REGISTRATION, source, registration, registration + new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_REGISTRATION, source, registration.getImportedReference(), registration .getException()); EventAdmin eventAdmin = getEventAdmin(); if (eventAdmin != null) { -- cgit v1.2.3