diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-16 22:04:54 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-16 22:04:54 +0000 |
commit | 9084bd19216f4865f63d7d68f3d4c3ac6f9d37f4 (patch) | |
tree | 92c8a4294ca795b146a0ab58d9527d1cab6f7383 | |
parent | cefd69376ea57f21a5f5e7cc23883ef05bb5be96 (diff) |
Start to hook up the osgi-based node
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755018 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java | 44 | ||||
-rw-r--r-- | java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java | 3 | ||||
-rw-r--r-- | java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF | 1 | ||||
-rw-r--r-- | java/sca/modules/node-impl-osgi/pom.xml | 7 | ||||
-rw-r--r-- | java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java | 84 | ||||
-rw-r--r-- | java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java) | 20 |
6 files changed, 105 insertions, 54 deletions
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java index 4567f8a708..f3d59cc513 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java @@ -19,65 +19,25 @@ package org.apache.tuscany.sca.implementation.osgi.runtime; -import static org.apache.tuscany.sca.implementation.osgi.runtime.OSGiImplementationManager.isSCABundle; - -import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.framework.SynchronousBundleListener; /** * Bundle activator to receive the BundleContext */ -public class OSGiImplementationRuntimeActivator implements BundleActivator, SynchronousBundleListener { +public class OSGiImplementationRuntimeActivator implements BundleActivator { private static BundleContext bundleContext; - private boolean inited; - - private void init() { - synchronized (this) { - if (inited) { - return; - } - inited = true; - } - } public void start(BundleContext context) throws Exception { bundleContext = context; - boolean found = false; - for (Bundle b : context.getBundles()) { - if (isSCABundle(b)) { - found = true; - break; - } - } - - if (found) { - init(); - } else { - context.addBundleListener(this); - } } public void stop(BundleContext context) throws Exception { - context.removeBundleListener(this); bundleContext = null; } - public static BundleContext getBundleContext() { + static BundleContext getBundleContext() { return bundleContext; } - public void bundleChanged(BundleEvent event) { - if (event.getType() == BundleEvent.STARTING) { - if (isSCABundle(event.getBundle())) { - // The bundle is an SCA implementation, init implementation.osgi - bundleContext.removeBundleListener(this); - init(); - } - } - - } - } diff --git a/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java b/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java index abd2985005..1dee0b1ae7 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java +++ b/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java @@ -85,6 +85,7 @@ public class CalculatorOSGiNodeTestCase { bundles.add(getCodeLocation(OSGiImplementation.class)); bundles.add(getCodeLocation(OSGiBundleContributionScanner.class)); + bundles.add(getCodeLocation(NodeImpl.class)); bundles.add(OSGiTestBundles.createBundle("target/test-classes/calculator-bundle.jar", "calculator/dosgi/META-INF/MANIFEST.MF", @@ -131,8 +132,6 @@ public class CalculatorOSGiNodeTestCase { for (Bundle b : context.getBundles()) { if (b.getSymbolicName().equals("calculator.dosgi")) { b.start(); - NodeImpl node = new NodeImpl(b); - node.start(); System.out.println(string(b, false)); } } diff --git a/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF b/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF index c02de5f8f8..886e434868 100644 --- a/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF +++ b/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF @@ -26,6 +26,7 @@ Bundle-Vendor: The Apache Software Foundation Bundle-Version: 2.0.0
Bnd-LastModified: 1225397240796
Bundle-ManifestVersion: 2
+Bundle-Activator: org.apache.tuscany.sca.node.osgi.impl.NodeActivator
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Apache Tuscany SCA Node Implementation
Import-Package: javax.xml.namespace,
diff --git a/java/sca/modules/node-impl-osgi/pom.xml b/java/sca/modules/node-impl-osgi/pom.xml index 3ba75702b9..f3e6d79c4e 100644 --- a/java/sca/modules/node-impl-osgi/pom.xml +++ b/java/sca/modules/node-impl-osgi/pom.xml @@ -155,6 +155,13 @@ <version>2.0-SNAPSHOT</version> <scope>test</scope> </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-launcher-equinox</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> </dependencies> diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java new file mode 100644 index 0000000000..42ae9d89f3 --- /dev/null +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java @@ -0,0 +1,84 @@ +/* + * 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.node.osgi.impl; + +import static org.apache.tuscany.sca.node.osgi.impl.NodeManager.isSCABundle; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.SynchronousBundleListener; + +/** + * Bundle activator to receive the BundleContext + */ +public class NodeActivator implements BundleActivator, SynchronousBundleListener { + private static BundleContext bundleContext; + private boolean inited; + + private void init() { + synchronized (this) { + if (inited) { + return; + } + NodeManager manager = new NodeManager(bundleContext); + manager.start(); + bundleContext.addBundleListener(manager); + inited = true; + } + } + + public void start(BundleContext context) throws Exception { + bundleContext = context; + boolean found = false; + for (Bundle b : context.getBundles()) { + if (isSCABundle(b)) { + found = true; + break; + } + } + + if (found) { + init(); + } else { + context.addBundleListener(this); + } + } + + public void stop(BundleContext context) throws Exception { + context.removeBundleListener(this); + bundleContext = null; + } + + public static BundleContext getBundleContext() { + return bundleContext; + } + + public void bundleChanged(BundleEvent event) { + if (event.getType() == BundleEvent.STARTING) { + if (isSCABundle(event.getBundle())) { + init(); + } + } + + } + +} diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java index fdc2e1ee2d..68575b6c74 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java @@ -17,15 +17,13 @@ * under the License. */ -package org.apache.tuscany.sca.implementation.osgi.runtime; +package org.apache.tuscany.sca.node.osgi.impl; -import java.net.URL; import java.util.Dictionary; import java.util.Enumeration; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; @@ -36,11 +34,11 @@ import org.osgi.framework.SynchronousBundleListener; /** * Managing the mapping between OSGi bundles and SCA implementation.osgi */ -public class OSGiImplementationManager implements SynchronousBundleListener, ServiceListener { +public class NodeManager implements SynchronousBundleListener, ServiceListener { private BundleContext bundleContext; - private Map<Bundle, OSGiImplementation> implementations = new ConcurrentHashMap<Bundle, OSGiImplementation>(); + private Map<Bundle, NodeImpl> nodes = new ConcurrentHashMap<Bundle, NodeImpl>(); - public OSGiImplementationManager(BundleContext bundleContext) { + public NodeManager(BundleContext bundleContext) { super(); this.bundleContext = bundleContext; } @@ -86,15 +84,17 @@ public class OSGiImplementationManager implements SynchronousBundleListener, Ser if (!isSCABundle(bundle)) { return; } - URL compositeFile = bundle.getEntry("OSGI-INF/sca/bundle.composite"); - URL componentTypeFile = bundle.getEntry("OSGI-INF/sca/bundle.componentType"); + NodeImpl node = new NodeImpl(bundle); + nodes.put(bundle, node); + node.start(); } private void bundleStopping(Bundle bundle) { - OSGiImplementation impl = implementations.remove(bundle); - if (impl == null) { + NodeImpl node = nodes.remove(bundle); + if (node == null) { return; } + node.stop(); } public void serviceChanged(ServiceEvent event) { |