You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/03/16 23:04:55 UTC

svn commit: r755018 - in /tuscany/java/sca/modules: implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/ implementation-osgi-runtime/src/test/java/calculator/dosgi/test/ node-impl-osgi/ node-impl-osgi/META-INF/ ...

Author: rfeng
Date: Mon Mar 16 22:04:54 2009
New Revision: 755018

URL: http://svn.apache.org/viewvc?rev=755018&view=rev
Log:
Start to hook up the osgi-based node

Added:
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java   (with props)
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java
      - copied, changed from r754969, tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java
Removed:
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java
Modified:
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
    tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java
    tuscany/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/node-impl-osgi/pom.xml

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java?rev=755018&r1=755017&r2=755018&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java Mon Mar 16 22:04:54 2009
@@ -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();
-            }
-        }
-
-    }
-
 }

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java?rev=755018&r1=755017&r2=755018&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java Mon Mar 16 22:04:54 2009
@@ -85,6 +85,7 @@
 
             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 @@
             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));
                 }
             }

Modified: tuscany/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF?rev=755018&r1=755017&r2=755018&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/node-impl-osgi/META-INF/MANIFEST.MF Mon Mar 16 22:04:54 2009
@@ -26,6 +26,7 @@
 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,

Modified: tuscany/java/sca/modules/node-impl-osgi/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/pom.xml?rev=755018&r1=755017&r2=755018&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/pom.xml (original)
+++ tuscany/java/sca/modules/node-impl-osgi/pom.xml Mon Mar 16 22:04:54 2009
@@ -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>
 

Added: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java?rev=755018&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java (added)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java Mon Mar 16 22:04:54 2009
@@ -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();
+            }
+        }
+
+    }
+
+}

Propchange: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java (from r754969, tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java)
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java?p2=tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java&p1=tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java&r1=754969&r2=755018&rev=755018&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationManager.java (original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java Mon Mar 16 22:04:54 2009
@@ -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 @@
 /**
  * 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 @@
         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) {