diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-20 06:20:53 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-20 06:20:53 +0000 |
commit | 60f5bce98ed1ce21b111c0d006d2dfd02106371b (patch) | |
tree | 1964272ea9422fd03f2e694ebbdca94b0132bd7d /sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java | |
parent | 734dac1eaf4ff319d8355d08335aeb019abf727e (diff) |
Update to the latest version of OSGi Remote Service Admin
Fix the issues to pass OSGi SCA configuration type TCK
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@901079 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java index d33fd5a5e6..f24e9af7c1 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java @@ -20,11 +20,14 @@ package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl; import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; import org.apache.tuscany.sca.node.impl.NodeImpl; import org.osgi.framework.Bundle; @@ -37,6 +40,9 @@ import org.osgi.service.remoteserviceadmin.ImportRegistration; * Watching and exporting OSGi services */ public class OSGiServiceImporter extends AbstractOSGiServiceHandler { + private final static Logger logger = Logger.getLogger(OSGiServiceImporter.class.getName()); + private Map<EndpointDescription, ImportReferenceImpl> importReferences = + new ConcurrentHashMap<EndpointDescription, ImportReferenceImpl>(); /** * @param context @@ -51,6 +57,11 @@ public class OSGiServiceImporter extends AbstractOSGiServiceHandler { // Defer init() to importService() } + public void stop() { + importReferences.clear(); + super.stop(); + } + public ImportRegistration importService(Bundle bundle, EndpointDescription endpointDescription) { init(); try { @@ -77,19 +88,27 @@ public class OSGiServiceImporter extends AbstractOSGiServiceHandler { + "#reference(" + componentReference.getName() + ")"); - return new ImportRegistrationImpl(node, serviceReference, endpointDescription); + synchronized (this) { + ImportReferenceImpl importReference = importReferences.get(endpointDescription); + if (importReference == null) { + importReference = new ImportReferenceImpl(node, serviceReference, endpointDescription); + importReferences.put(endpointDescription, importReference); + } + return importReference.register(); + } } else { return null; } } catch (Exception e) { - e.printStackTrace(); - return null; + logger.log(Level.SEVERE, e.getMessage(), e); + return new ImportRegistrationImpl(null, e); } } public void unimportService(ImportRegistration importRegistration) { - Node node = (Node)importRegistration.getImportReference().getImportedService().getProperty("sca.node"); - node.stop(); + if (importRegistration != null) { + importRegistration.close(); + } } } |