Refactor the OSGi remote services implementation and improve the notifications
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@826369 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0bcd3fabdf
commit
26fced7b9d
25 changed files with 378 additions and 225 deletions
|
@ -32,7 +32,7 @@ Import-Package: javax.xml.namespace,
|
|||
org.apache.tuscany.sca.node;version="2.0.0",
|
||||
org.apache.tuscany.sca.node.configuration;version="2.0.0",
|
||||
org.apache.tuscany.sca.node.impl;version="2.0.0",
|
||||
org.apache.tuscany.sca.osgi.service.remoteadmin;version="2.0.0",
|
||||
org.apache.tuscany.sca.osgi.remoteserviceadmin;version="2.0.0",
|
||||
org.apache.tuscany.sca.policy;version="2.0.0",
|
||||
org.apache.tuscany.sca.provider;version="2.0.0",
|
||||
org.apache.tuscany.sca.runtime;version="2.0.0",
|
||||
|
@ -41,10 +41,11 @@ Import-Package: javax.xml.namespace,
|
|||
org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional,
|
||||
org.osgi.framework;version="1.4.0",
|
||||
org.osgi.framework.hooks.service;version="1.0.0";resolution:=optional,
|
||||
org.osgi.service.event;version="1.2.0",
|
||||
org.osgi.service.packageadmin;version="1.2.0";resolution:=optional,
|
||||
org.osgi.util.tracker;version="1.3.0";resolution:=optional
|
||||
Bundle-SymbolicName: org.apache.tuscany.sca.node.osgi.impl
|
||||
Bundle-DocURL: http://www.apache.org/
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.apache.tuscany.sca.osgi.service.remoteadmin;version="2.0.0"
|
||||
Export-Package: org.apache.tuscany.sca.osgi.remoteserviceadmin;version="2.0.0"
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>services</artifactId>
|
||||
<version>3.2.0-v20090520-1800</version>
|
||||
<scope>test</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Equinox Declarative Services -->
|
||||
|
|
|
@ -21,9 +21,9 @@ package org.apache.tuscany.sca.node.osgi.impl;
|
|||
|
||||
import static org.apache.tuscany.sca.node.osgi.impl.NodeManager.isSCABundle;
|
||||
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.TopologyManagerImpl;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.RemoteServiceAdminImpl;
|
||||
import org.apache.tuscany.sca.osgi.service.discovery.impl.DiscoveryActivator;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.impl.RemoteServiceAdminImpl;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.impl.RemoteControllerImpl;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
@ -40,7 +40,7 @@ public class NodeActivator implements BundleActivator, SynchronousBundleListener
|
|||
|
||||
private DiscoveryActivator discoveryActivator = new DiscoveryActivator();
|
||||
private RemoteServiceAdminImpl remoteAdmin;
|
||||
private RemoteControllerImpl controller;
|
||||
private TopologyManagerImpl controller;
|
||||
|
||||
private void init() {
|
||||
synchronized (this) {
|
||||
|
@ -63,7 +63,7 @@ public class NodeActivator implements BundleActivator, SynchronousBundleListener
|
|||
remoteAdmin = new RemoteServiceAdminImpl(context);
|
||||
remoteAdmin.start();
|
||||
|
||||
controller = new RemoteControllerImpl(context);
|
||||
controller = new TopologyManagerImpl(context);
|
||||
controller.start();
|
||||
|
||||
// exporter = new OSGiServiceExporter(context);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
/**
|
||||
* A white board service that represents a listener for endpoints.
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
// TODO Hacked from ServiePermission
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
/**
|
||||
* Provide the definition of the constants used in the Remote Services API.
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.tuscany.sca.osgi.service.remoteadmin;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin;
|
||||
|
||||
/**
|
||||
* A Remote Service Admin Listener is notified asynchronously of any export or
|
|
@ -17,9 +17,8 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin.impl;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -29,8 +28,8 @@ import java.util.UUID;
|
|||
import org.apache.tuscany.sca.assembly.Endpoint;
|
||||
import org.apache.tuscany.sca.interfacedef.Interface;
|
||||
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.Constants;
|
||||
|
||||
|
@ -38,8 +37,7 @@ import org.osgi.framework.Constants;
|
|||
* Implementation of {@link EndpointDescription}
|
||||
*/
|
||||
public class EndpointHelper {
|
||||
private static final String FRAMEWORK_UUID = UUID.randomUUID().toString();
|
||||
|
||||
private final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
|
||||
private EndpointHelper() {
|
||||
}
|
||||
|
||||
|
@ -68,14 +66,12 @@ public class EndpointHelper {
|
|||
return props;
|
||||
}
|
||||
|
||||
public static String getFrameworkUUID(BundleContext bundleContext) {
|
||||
String uuid = null;
|
||||
if (bundleContext != null) {
|
||||
URL url = bundleContext.getBundle(0).getEntry("/"); // bundleentry://0.fwk24942249/
|
||||
uuid = url.getHost();
|
||||
} else {
|
||||
uuid = FRAMEWORK_UUID;
|
||||
public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
|
||||
String uuid = System.getProperty(FRAMEWORK_UUID);
|
||||
if (uuid == null) {
|
||||
uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
System.setProperty(FRAMEWORK_UUID, uuid);
|
||||
return uuid;
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin.impl;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
|
||||
|
||||
import static org.apache.tuscany.sca.assembly.Base.SCA11_TUSCANY_NS;
|
||||
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SCA_BINDINGS;
|
||||
|
@ -33,11 +33,14 @@ import java.net.MalformedURLException;
|
|||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
@ -78,11 +81,12 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
|
|||
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
|
||||
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
|
||||
import org.apache.tuscany.sca.monitor.MonitorFactory;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.policy.Intent;
|
||||
import org.apache.tuscany.sca.policy.PolicyFactory;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.Constants;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
/**
|
||||
|
@ -168,17 +172,50 @@ public class EndpointIntrospector {
|
|||
return intentList;
|
||||
}
|
||||
|
||||
private Map<String, Object> getProperties(ServiceReference reference) {
|
||||
/**
|
||||
* Any property in the map overrides the service reference properties, regardless of
|
||||
* case. That is, if the map contains a key then it will override any case variant
|
||||
* of this key in the Service Reference.<p>
|
||||
* If the map contains the objectClass or service. id property key in any case
|
||||
* variant, then these properties must not override the Service Reference’s value. This
|
||||
* implies that the map can provide the service.exported. interfaces, property allowing
|
||||
* the Topology Manager to export any registered service, also services not specifically
|
||||
* marked to be exported.
|
||||
* @param reference
|
||||
* @param props
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> getProperties(ServiceReference reference, Map<String, Object> props) {
|
||||
String[] names = reference.getPropertyKeys();
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
if (names != null) {
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
for (String name : names) {
|
||||
properties.put(name, reference.getProperty(name));
|
||||
}
|
||||
return properties;
|
||||
} else {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
if (props != null) {
|
||||
// Create a map of names (key = lowcase name, value = name)
|
||||
Map<String, String> nameMap = new HashMap<String, String>();
|
||||
if (names != null) {
|
||||
for (String name : names) {
|
||||
nameMap.put(name.toLowerCase(), name);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Object> p : props.entrySet()) {
|
||||
if (Constants.OBJECTCLASS.equalsIgnoreCase(p.getKey())) {
|
||||
throw new IllegalArgumentException(Constants.OBJECTCLASS + " property cannot be overridden.");
|
||||
} else if (Constants.SERVICE_ID.equalsIgnoreCase(p.getKey())) {
|
||||
throw new IllegalArgumentException(Constants.SERVICE_ID + " property cannot be overridden.");
|
||||
}
|
||||
String key = nameMap.get(p.getKey().toLowerCase());
|
||||
if (key != null) {
|
||||
properties.put(key, p.getValue());
|
||||
} else {
|
||||
properties.put(p.getKey(), p.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -204,11 +241,12 @@ public class EndpointIntrospector {
|
|||
* Introspect a local OSGi Service represented by the ServiceReference to create
|
||||
* an SCA service with the required intents and bindings
|
||||
* @param reference The service reference for a local OSGi service
|
||||
* @param props Addiontal properties
|
||||
* @return An SCA contribution with a deployable composite for the SCA service
|
||||
* @throws Exception
|
||||
*/
|
||||
public Contribution introspect(ServiceReference reference) throws Exception {
|
||||
Map<String, Object> properties = getProperties(reference);
|
||||
public Contribution introspect(ServiceReference reference, Map<String, Object> props) throws Exception {
|
||||
Map<String, Object> properties = getProperties(reference, props);
|
||||
|
||||
OSGiProperty serviceID = implementationFactory.createOSGiProperty();
|
||||
serviceID.setName(SERVICE_ID);
|
||||
|
@ -237,6 +275,12 @@ public class EndpointIntrospector {
|
|||
remoteInterfaces = getStrings(reference.getProperty(OBJECTCLASS));
|
||||
} else {
|
||||
remoteInterfaces = parse(remoteInterfaces);
|
||||
String[] objectClasses = getStrings(reference.getProperty(OBJECTCLASS));
|
||||
Set<String> objectClassSet = new HashSet<String>(Arrays.asList(objectClasses));
|
||||
if (!objectClassSet.containsAll(Arrays.asList(remoteInterfaces))) {
|
||||
throw new IllegalArgumentException("The exported interfaces are not a subset of the types"
|
||||
+ " listed in the objectClass service property from the Service Reference");
|
||||
}
|
||||
}
|
||||
for (String intf : remoteInterfaces) {
|
||||
Service service = assemblyFactory.createService();
|
|
@ -17,11 +17,11 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin.impl;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
|
||||
|
||||
import org.apache.tuscany.sca.node.Node;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.ExportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.ExportRegistration;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
/**
|
||||
|
@ -58,7 +58,7 @@ public class ExportRegistrationImpl implements ExportRegistration {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.ExportRegistration#close()
|
||||
* @see org.apache.tuscany.sca.osgi.remoteserviceadmin.ExportRegistration#close()
|
||||
*/
|
||||
public void close() {
|
||||
if (node != null) {
|
|
@ -17,11 +17,11 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin.impl;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
|
||||
|
||||
import org.apache.tuscany.sca.node.Node;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.ImportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.ImportRegistration;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@ public class ImportRegistrationImpl implements ImportRegistration {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.ImportRegistration#close()
|
||||
* @see org.apache.tuscany.sca.osgi.remoteserviceadmin.ImportRegistration#close()
|
||||
*/
|
||||
public void close() {
|
||||
if (node != null) {
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin.impl;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
|
@ -17,13 +17,14 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin.impl;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
|
||||
|
||||
import static org.apache.tuscany.sca.osgi.service.remoteadmin.impl.EndpointHelper.createEndpointDescription;
|
||||
import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.EndpointHelper.createEndpointDescription;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.Component;
|
||||
import org.apache.tuscany.sca.assembly.ComponentService;
|
||||
|
@ -35,8 +36,8 @@ import org.apache.tuscany.sca.node.NodeFactory;
|
|||
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
|
||||
import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
|
||||
import org.apache.tuscany.sca.node.impl.NodeImpl;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.ExportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.ExportRegistration;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
@ -77,12 +78,13 @@ public class OSGiServiceExporter implements ServiceTrackerCustomizer, LifeCycleL
|
|||
}
|
||||
|
||||
public Object addingService(ServiceReference reference) {
|
||||
return exportService(reference);
|
||||
return exportService(reference, null);
|
||||
}
|
||||
|
||||
public List<ExportRegistration> exportService(ServiceReference reference) {
|
||||
public List<ExportRegistration> exportService(ServiceReference reference, Map<String, Object> properties) {
|
||||
// FIXME: [rfeng] We need to check if a corresponding endpoint has been exported
|
||||
try {
|
||||
Contribution contribution = introspector.introspect(reference);
|
||||
Contribution contribution = introspector.introspect(reference, properties);
|
||||
if (contribution != null) {
|
||||
|
||||
NodeConfiguration configuration = nodeFactory.createNodeConfiguration();
|
||||
|
@ -112,7 +114,7 @@ public class OSGiServiceExporter implements ServiceTrackerCustomizer, LifeCycleL
|
|||
|
||||
public void modifiedService(ServiceReference reference, Object service) {
|
||||
removedService(reference, service);
|
||||
exportService(reference);
|
||||
exportService(reference, null);
|
||||
}
|
||||
|
||||
public void removedService(ServiceReference reference, Object service) {
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin.impl;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
@ -31,8 +31,8 @@ import org.apache.tuscany.sca.node.NodeFactory;
|
|||
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
|
||||
import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
|
||||
import org.apache.tuscany.sca.node.impl.NodeImpl;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.ImportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.ImportRegistration;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.ExportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.ImportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdmin;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdminEvent;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdminListener;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.Constants;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.service.event.Event;
|
||||
import org.osgi.service.event.EventAdmin;
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
||||
/**
|
||||
* SCA Implementation of {@link RemoteServiceAdmin}
|
||||
*/
|
||||
public class RemoteServiceAdminImpl implements RemoteServiceAdmin {
|
||||
private BundleContext context;
|
||||
private ServiceRegistration registration;
|
||||
private ServiceTracker listeners;
|
||||
|
||||
private OSGiServiceExporter exporter;
|
||||
private OSGiServiceImporter importer;
|
||||
|
||||
private Collection<ImportRegistration> importedEndpoints = new ArrayList<ImportRegistration>();
|
||||
private Collection<ExportRegistration> exportedServices = new ArrayList<ExportRegistration>();
|
||||
|
||||
public RemoteServiceAdminImpl(BundleContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.exporter = new OSGiServiceExporter(context);
|
||||
this.importer = new OSGiServiceImporter(context);
|
||||
exporter.start();
|
||||
importer.start();
|
||||
registration = context.registerService(RemoteServiceAdmin.class.getName(), this, null);
|
||||
listeners = new ServiceTracker(this.context, RemoteServiceAdminListener.class.getName(), null);
|
||||
listeners.open();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (registration != null) {
|
||||
registration.unregister();
|
||||
registration = null;
|
||||
}
|
||||
if (listeners != null) {
|
||||
listeners.close();
|
||||
listeners = null;
|
||||
}
|
||||
for (ExportRegistration exportRegistration : exportedServices) {
|
||||
exportRegistration.close();
|
||||
}
|
||||
exportedServices.clear();
|
||||
for (ImportRegistration importRegistration : importedEndpoints) {
|
||||
importRegistration.close();
|
||||
}
|
||||
importedEndpoints.clear();
|
||||
if (importer != null) {
|
||||
importer.stop();
|
||||
importer = null;
|
||||
}
|
||||
if (exporter != null) {
|
||||
exporter.stop();
|
||||
exporter = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdmin#exportService(org.osgi.framework.ServiceReference,
|
||||
* java.util.Map)
|
||||
*/
|
||||
public List<ExportRegistration> exportService(ServiceReference ref, Map properties) {
|
||||
List<ExportRegistration> exportRegistrations = exporter.exportService(ref, properties);
|
||||
if (exportRegistrations != null) {
|
||||
exportedServices.addAll(exportRegistrations);
|
||||
fireExportEvents(ref.getBundle(), exportRegistrations);
|
||||
}
|
||||
return exportRegistrations;
|
||||
}
|
||||
|
||||
private void fireExportEvents(Bundle source, List<ExportRegistration> exportRegistrations) {
|
||||
for (ExportRegistration registration : exportRegistrations) {
|
||||
RemoteServiceAdminEvent rsaEvent =
|
||||
new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION, source, registration,
|
||||
registration.getException());
|
||||
EventAdmin eventAdmin = getEventAdmin();
|
||||
if (eventAdmin != null) {
|
||||
eventAdmin.postEvent(wrap(rsaEvent));
|
||||
}
|
||||
for (Object listener : listeners.getServices()) {
|
||||
RemoteServiceAdminListener rsaListener = (RemoteServiceAdminListener)listener;
|
||||
rsaListener.remoteAdminEvent(rsaEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private EventAdmin getEventAdmin() {
|
||||
ServiceReference reference = context.getServiceReference(EventAdmin.class.getName());
|
||||
if (reference == null) {
|
||||
return null;
|
||||
} else {
|
||||
return (EventAdmin)context.getService(reference);
|
||||
}
|
||||
}
|
||||
|
||||
private Event wrap(RemoteServiceAdminEvent rsaEvent) {
|
||||
int type = rsaEvent.getType();
|
||||
String eventType = null;
|
||||
switch (type) {
|
||||
case RemoteServiceAdminEvent.EXPORT_ERROR:
|
||||
eventType = "EXPORT_ERROR";
|
||||
break;
|
||||
case RemoteServiceAdminEvent.EXPORT_REGISTRATION:
|
||||
eventType = "EXPORT_REGISTRATION";
|
||||
break;
|
||||
case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION:
|
||||
eventType = "EXPORT_UNREGISTRATION";
|
||||
break;
|
||||
case RemoteServiceAdminEvent.EXPORT_WARNING:
|
||||
eventType = "EXPORT_WARNING";
|
||||
break;
|
||||
case RemoteServiceAdminEvent.IMPORT_ERROR:
|
||||
eventType = "IMPORT_ERROR";
|
||||
break;
|
||||
case RemoteServiceAdminEvent.IMPORT_REGISTRATION:
|
||||
eventType = "IMPORT_REGISTRATION";
|
||||
break;
|
||||
case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION:
|
||||
eventType = "EXPORT_ERROR";
|
||||
break;
|
||||
case RemoteServiceAdminEvent.IMPORT_WARNING:
|
||||
eventType = "IMPORT_UNREGISTRATION";
|
||||
break;
|
||||
}
|
||||
String topic = "org/osgi/service/remoteserviceadmin/" + eventType;
|
||||
Map<String, Object> props = new HashMap<String, Object>();
|
||||
/*
|
||||
* <ul>
|
||||
<li>bundle – (Bundle) The Remote Service Admin bundle
|
||||
<li>bundle-id – (Long) The id of the Blueprint bundle.
|
||||
<li>bundle-symbolicname – (String) The Bundle Symbolic Name of the
|
||||
Remote Service Admin bundle.
|
||||
<li>bundle-version - (Version) The version of the Blueprint bundle.
|
||||
<li>cause – The exception, if present.
|
||||
<li>import.registration – An imported endpoint, if present
|
||||
<li>export.registration – An exported endpoint, if present
|
||||
<li>service.remote.id – Remote service UUID, if present
|
||||
<li>service.remote.uuid – Remote service UUID, if present
|
||||
<li>service.remote.uri – (String) The URI of the endpoint, if present
|
||||
<li>objectClass – (String[]) The interface names, if present
|
||||
<li>service.imported.configs – (String+) The configuration types of the
|
||||
imported services, if present
|
||||
<li>timestamp – (Long) The time when the event occurred
|
||||
<li>event – (RemoteServiceAdminEvent) The RemoteServiceAdminEvent
|
||||
object that caused this event.
|
||||
</ul>
|
||||
*/
|
||||
Bundle rsaBundle = context.getBundle();
|
||||
props.put("bundle", rsaBundle);
|
||||
props.put("bundle-id", rsaBundle.getBundleId());
|
||||
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());
|
||||
EndpointDescription ep = null;
|
||||
if (rsaEvent.getImportRegistration() != null) {
|
||||
ep = rsaEvent.getImportRegistration().getImportedEndpointDescription();
|
||||
} else {
|
||||
ep = rsaEvent.getExportRegistration().getEndpointDescription();
|
||||
}
|
||||
props.put("service.remote.id", ep.getRemoteServiceID());
|
||||
props.put("service.remote.uuid", ep.getRemoteFrameworkUUID());
|
||||
props.put("service.remote.uri", ep.getRemoteURI());
|
||||
props.put("objectClass", ep.getInterfaces());
|
||||
props.put("service.imported.configs", ep.getConfigurationTypes());
|
||||
props.put("timestamp", new Long(System.currentTimeMillis()));
|
||||
props.put("event", rsaEvent);
|
||||
return new Event(topic, props);
|
||||
}
|
||||
|
||||
private void fireImportEvents(Bundle source, ImportRegistration registration) {
|
||||
RemoteServiceAdminEvent rsaEvent =
|
||||
new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_REGISTRATION, source, registration, registration
|
||||
.getException());
|
||||
EventAdmin eventAdmin = getEventAdmin();
|
||||
if (eventAdmin != null) {
|
||||
eventAdmin.postEvent(wrap(rsaEvent));
|
||||
}
|
||||
for (Object listener : listeners.getServices()) {
|
||||
RemoteServiceAdminListener rsaListener = (RemoteServiceAdminListener)listener;
|
||||
rsaListener.remoteAdminEvent(rsaEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdmin#getExportedServices()
|
||||
*/
|
||||
public Collection<ExportRegistration> getExportedServices() {
|
||||
return exportedServices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdmin#getImportedEndpoints()
|
||||
*/
|
||||
public Collection<ImportRegistration> getImportedEndpoints() {
|
||||
return importedEndpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdmin#importService(org.apache.tuscany.sca.dosgi.discovery.EndpointDescription)
|
||||
*/
|
||||
public ImportRegistration importService(EndpointDescription endpoint) {
|
||||
Bundle bundle = (Bundle)endpoint.getProperties().get(Bundle.class.getName());
|
||||
ImportRegistration importReg = importer.importService(bundle, endpoint);
|
||||
if (importReg != null) {
|
||||
fireImportEvents(bundle, importReg);
|
||||
importedEndpoints.add(importReg);
|
||||
}
|
||||
return importReg;
|
||||
}
|
||||
}
|
|
@ -17,11 +17,11 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.osgi.service.remoteadmin.impl;
|
||||
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
|
||||
|
||||
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTERFACES;
|
||||
import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants.SERVICE_EXPORTED_CONFIGS;
|
||||
import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants.SERVICE_IMPORTED;
|
||||
import static org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_CONFIGS;
|
||||
import static org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Dictionary;
|
||||
|
@ -37,13 +37,13 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.apache.tuscany.sca.common.java.collection.CollectionMap;
|
||||
import org.apache.tuscany.sca.core.LifeCycleListener;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointListener;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.ExportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.ImportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdminEvent;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdminListener;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointListener;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.ExportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.ImportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdmin;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdminEvent;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteServiceAdminListener;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.Constants;
|
||||
|
@ -58,9 +58,9 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
|
|||
/**
|
||||
* Implementation of Remote Controller
|
||||
*/
|
||||
public class RemoteControllerImpl implements ListenerHook, RemoteServiceAdminListener, EndpointListener,
|
||||
public class TopologyManagerImpl implements ListenerHook, RemoteServiceAdminListener, EndpointListener,
|
||||
ServiceTrackerCustomizer, LifeCycleListener /*, EventHook */{
|
||||
private final static Logger logger = Logger.getLogger(RemoteControllerImpl.class.getName());
|
||||
private final static Logger logger = Logger.getLogger(TopologyManagerImpl.class.getName());
|
||||
public final static String ENDPOINT_LOCAL = "service.local";
|
||||
|
||||
private BundleContext context;
|
||||
|
@ -81,7 +81,7 @@ public class RemoteControllerImpl implements ListenerHook, RemoteServiceAdminLis
|
|||
|
||||
private Filter remotableServiceFilter;
|
||||
|
||||
public RemoteControllerImpl(BundleContext context) {
|
||||
public TopologyManagerImpl(BundleContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
@ -312,7 +312,7 @@ public class RemoteControllerImpl implements ListenerHook, RemoteServiceAdminLis
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointListener#addEndpoint(org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription,
|
||||
* @see org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointListener#addEndpoint(org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription,
|
||||
* java.lang.String)
|
||||
*/
|
||||
public void endpointAdded(EndpointDescription endpoint, String matchedFilter) {
|
||||
|
@ -320,7 +320,7 @@ public class RemoteControllerImpl implements ListenerHook, RemoteServiceAdminLis
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointListener#removeEndpoint(org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription)
|
||||
* @see org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointListener#removeEndpoint(org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription)
|
||||
*/
|
||||
public void endpointRemoved(EndpointDescription endpoint, String matchedFilter) {
|
||||
unimportService(endpoint);
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.apache.tuscany.sca.osgi.service.discovery.impl;
|
||||
|
||||
import static org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointListener.ENDPOINT_LISTENER_SCOPE;
|
||||
import static org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointListener.ENDPOINT_LISTENER_SCOPE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -37,10 +37,10 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
|||
import org.apache.tuscany.sca.core.LifeCycleListener;
|
||||
import org.apache.tuscany.sca.node.NodeFactory;
|
||||
import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointListener;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.impl.OSGiHelper;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointListener;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.Constants;
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
package org.apache.tuscany.sca.osgi.service.discovery.impl;
|
||||
|
||||
import static org.apache.tuscany.sca.osgi.service.remoteadmin.impl.EndpointHelper.createEndpointDescription;
|
||||
import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.EndpointHelper.createEndpointDescription;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.Endpoint;
|
||||
import org.apache.tuscany.sca.assembly.Implementation;
|
||||
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
|
||||
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
|
||||
import org.apache.tuscany.sca.runtime.EndpointListener;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
|
|
@ -50,9 +50,9 @@ import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
|
|||
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
|
||||
import org.apache.tuscany.sca.monitor.Monitor;
|
||||
import org.apache.tuscany.sca.monitor.MonitorFactory;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.impl.EndpointHelper;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants;
|
||||
import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.EndpointHelper;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.BundleEvent;
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
* 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.service.remoteadmin.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.ExportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.ImportRegistration;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin;
|
||||
import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdminListener;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
||||
/**
|
||||
* SCA Implementation of {@link RemoteServiceAdmin}
|
||||
*/
|
||||
public class RemoteServiceAdminImpl implements RemoteServiceAdmin {
|
||||
private BundleContext context;
|
||||
private ServiceRegistration registration;
|
||||
private ServiceTracker listeners;
|
||||
|
||||
private OSGiServiceExporter exporter;
|
||||
private OSGiServiceImporter importer;
|
||||
|
||||
private Collection<ImportRegistration> importedEndpoints = new ArrayList<ImportRegistration>();
|
||||
private Collection<ExportRegistration> exportedServices = new ArrayList<ExportRegistration>();
|
||||
|
||||
public RemoteServiceAdminImpl(BundleContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.exporter = new OSGiServiceExporter(context);
|
||||
this.importer = new OSGiServiceImporter(context);
|
||||
exporter.start();
|
||||
importer.start();
|
||||
registration = context.registerService(RemoteServiceAdmin.class.getName(), this, null);
|
||||
listeners = new ServiceTracker(this.context, RemoteServiceAdminListener.class.getName(), null);
|
||||
listeners.open();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (registration != null) {
|
||||
registration.unregister();
|
||||
registration = null;
|
||||
}
|
||||
if (listeners != null) {
|
||||
listeners.close();
|
||||
listeners = null;
|
||||
}
|
||||
for (ExportRegistration exportRegistration : exportedServices) {
|
||||
exportRegistration.close();
|
||||
}
|
||||
exportedServices.clear();
|
||||
for (ImportRegistration importRegistration : importedEndpoints) {
|
||||
importRegistration.close();
|
||||
}
|
||||
importedEndpoints.clear();
|
||||
if (importer != null) {
|
||||
importer.stop();
|
||||
importer = null;
|
||||
}
|
||||
if (exporter != null) {
|
||||
exporter.stop();
|
||||
exporter = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin#exportService(org.osgi.framework.ServiceReference)
|
||||
*/
|
||||
public List<ExportRegistration> exportService(ServiceReference ref) {
|
||||
List<ExportRegistration> exportRegistrations = exporter.exportService(ref);
|
||||
if (exportRegistrations != null) {
|
||||
exportedServices.addAll(exportRegistrations);
|
||||
}
|
||||
return exportRegistrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin#exportService(org.osgi.framework.ServiceReference,
|
||||
* java.util.Map)
|
||||
*/
|
||||
public List<ExportRegistration> exportService(ServiceReference ref, Map properties) {
|
||||
List<ExportRegistration> exportRegistrations = exporter.exportService(ref);
|
||||
if (exportRegistrations != null) {
|
||||
exportedServices.addAll(exportRegistrations);
|
||||
}
|
||||
return exportRegistrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin#getExportedServices()
|
||||
*/
|
||||
public Collection<ExportRegistration> getExportedServices() {
|
||||
return exportedServices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin#getImportedEndpoints()
|
||||
*/
|
||||
public Collection<ImportRegistration> getImportedEndpoints() {
|
||||
return importedEndpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin#importService(org.apache.tuscany.sca.dosgi.discovery.EndpointDescription)
|
||||
*/
|
||||
public ImportRegistration importService(EndpointDescription endpoint) {
|
||||
Bundle bundle = (Bundle) endpoint.getProperties().get(Bundle.class.getName());
|
||||
ImportRegistration importReg = importer.importService(bundle, endpoint);
|
||||
if (importReg != null) {
|
||||
importedEndpoints.add(importReg);
|
||||
}
|
||||
return importReg;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue