summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-osgi-runtime
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-16 22:04:54 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-16 22:04:54 +0000
commit9084bd19216f4865f63d7d68f3d4c3ac6f9d37f4 (patch)
tree92c8a4294ca795b146a0ab58d9527d1cab6f7383 /java/sca/modules/implementation-osgi-runtime
parentcefd69376ea57f21a5f5e7cc23883ef05bb5be96 (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
Diffstat (limited to 'java/sca/modules/implementation-osgi-runtime')
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java112
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java44
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java3
3 files changed, 3 insertions, 156 deletions
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/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java
deleted file mode 100644
index fdc2e1ee2d..0000000000
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java
+++ /dev/null
@@ -1,112 +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.implementation.osgi.runtime;
-
-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;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.SynchronousBundleListener;
-
-/**
- * Managing the mapping between OSGi bundles and SCA implementation.osgi
- */
-public class OSGiImplementationManager implements SynchronousBundleListener, ServiceListener {
- private BundleContext bundleContext;
- private Map<Bundle, OSGiImplementation> implementations = new ConcurrentHashMap<Bundle, OSGiImplementation>();
-
- public OSGiImplementationManager(BundleContext bundleContext) {
- super();
- this.bundleContext = bundleContext;
- }
-
- public void start() {
- for (Bundle b : bundleContext.getBundles()) {
- if ((b.getState() & Bundle.ACTIVE) != 0) {
- // Process the active bundles
- bundleStarted(b);
- }
- }
- }
-
- public static boolean isSCABundle(Bundle bundle) {
- Dictionary<?, ?> headers = bundle.getHeaders();
- // OSGi RFC 119 SCA
- if (headers.get("SCA-Composite") != null) {
- return true;
- }
- Enumeration<?> entries = bundle.findEntries("OSGI-INF/sca", "*", false);
- if (entries != null && entries.hasMoreElements()) {
- return true;
- }
-
- // OSGi Declarative Services
- if (headers.get("Service-Component") != null) {
- return true;
- }
-
- // OSGI RFC 124: BluePrint Service
- if (headers.get("Bundle-Blueprint") != null) {
- return true;
- }
-
- entries = bundle.findEntries("OSGI-INF/blueprint", "*.xml", false);
- if (entries != null && entries.hasMoreElements()) {
- return true;
- }
- return false;
- }
-
- private void bundleStarted(Bundle bundle) {
- if (!isSCABundle(bundle)) {
- return;
- }
- URL compositeFile = bundle.getEntry("OSGI-INF/sca/bundle.composite");
- URL componentTypeFile = bundle.getEntry("OSGI-INF/sca/bundle.componentType");
- }
-
- private void bundleStopping(Bundle bundle) {
- OSGiImplementation impl = implementations.remove(bundle);
- if (impl == null) {
- return;
- }
- }
-
- public void serviceChanged(ServiceEvent event) {
- }
-
- public void bundleChanged(BundleEvent event) {
- int type = event.getType();
- if (type == BundleEvent.STOPPING) {
- bundleStopping(event.getBundle());
- } else if (type == BundleEvent.STARTED) {
- bundleStarted(event.getBundle());
- }
- }
-
-}
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));
}
}