You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/11/27 11:05:02 UTC

svn commit: r721141 - in /servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix: common/ common/osgi/ jbi/deployer/

Author: gnodet
Date: Thu Nov 27 02:04:59 2008
New Revision: 721141

URL: http://svn.apache.org/viewvc?rev=721141&view=rev
Log:
SMX4NMR-54: SA should be undeployed correctly when the osgi bundle is stopped

Modified:
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java?rev=721141&r1=721140&r2=721141&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java Thu Nov 27 02:04:59 2008
@@ -254,7 +254,9 @@
                 throw failure("undeploy", "ServiceUnit should be in a SHUTDOWN state", null);
             }
             Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
-            doUndeploy(su);
+            if (serviceUnitRootPath != null) {
+                doUndeploy(su);
+            }
             component.getRegistry().unregisterServiceUnit(su);
             if (logger.isDebugEnabled()) {
                 logger.debug("Service unit undeployed");

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java?rev=721141&r1=721140&r2=721141&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java Thu Nov 27 02:04:59 2008
@@ -21,10 +21,14 @@
 import java.util.Collection;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.ArrayList;
+
+import javax.jbi.management.DeploymentException;
 
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.jbi.deployer.DeployedAssembly;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
 import org.springframework.osgi.context.BundleContextAware;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.DisposableBean;
@@ -36,6 +40,8 @@
     private BundleContext bundleContext;
     private ApplicationContext applicationContext;
     private Collection<Endpoint> endpoints;
+    private String assemblyName;
+    private Collection<ServiceRegistration> endpointRegistrations;
 
     public void setBundleContext(BundleContext bundleContext) {
         this.bundleContext = bundleContext;
@@ -58,27 +64,43 @@
     }
 
     public String getName() {
-        return bundleContext.getBundle().getSymbolicName();
+        return assemblyName;
+    }
+
+    public void deploy() {
+        endpointRegistrations = new ArrayList<ServiceRegistration>();
+        for (Endpoint ep : getEndpoints()) {
+            EndpointWrapper wrapper = new EndpointWrapperImpl(ep, applicationContext.getClassLoader());
+            Dictionary props = new Properties();
+            ServiceRegistration reg = bundleContext.registerService(EndpointWrapper.class.getName(), wrapper, props);
+            endpointRegistrations.add(reg);
+        }
     }
 
     public Map<String, String> getServiceUnits() {
+        if (endpointRegistrations == null) {
+            throw new IllegalStateException("Service assembly has not been deployed");
+        }
         Map<String, String> sus = new HashMap<String, String>();
         for (Endpoint ep : getEndpoints()) {
+            if (ep.getServiceUnit() == null) {
+                throw new IllegalStateException("Endpoint has not been ");
+            }
             sus.put(ep.getServiceUnit().getName(), ep.getServiceUnit().getComponent().getComponentName());
         }
         return sus;
     }
 
     public void afterPropertiesSet() throws Exception {
-        Collection<Endpoint> eps = getEndpoints();
-        for (Endpoint ep : eps) {
-            EndpointWrapper wrapper = new EndpointWrapperImpl(ep, applicationContext.getClassLoader());
-            Dictionary props = new Properties();
-            bundleContext.registerService(EndpointWrapper.class.getName(), wrapper, props);
-        }
+        this.assemblyName = bundleContext.getBundle().getSymbolicName();
         bundleContext.registerService(DeployedAssembly.class.getName(), this, new Properties());
     }
 
     public void destroy() throws Exception {
+        if (endpointRegistrations != null) {
+            for (ServiceRegistration reg : endpointRegistrations) {
+                reg.unregister();
+            }
+        }
     }
 }

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java?rev=721141&r1=721140&r2=721141&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java Thu Nov 27 02:04:59 2008
@@ -27,6 +27,11 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+/**
+ * This class is used by components bundles to track endpoints that they know about.
+ * Endpoints are wrapped into {@link EndpointWrapper} interfaces to be able to access
+ * the underlying object easily and bypass spring-DM proxies.
+ */
 public class EndpointTracker {
 
     private static final Log LOGGER = LogFactory.getLog(EndpointTracker.class);
@@ -58,17 +63,8 @@
     }
 
     public void unregister(EndpointWrapper wrapper, Map properties) throws Exception {
-        if (LOGGER.isDebugEnabled()) {
-            LOGGER.debug("[" + component.getComponentName() + "] Endpoint unregistered with properties: " + properties);
-        }
-        // Do not access the wrapper using wrapper.getEndpoint(), has the osgi context may already be shut down
-        OsgiServiceUnit su = endpoints.remove(wrapper);
-        if (su != null && component.isKnownEndpoint(su.getEndpoint())) {
-            if (LOGGER.isDebugEnabled()) {
-    	        LOGGER.debug("[" + component.getComponentName() + "] Endpoint recognized");
-            }
-            component.getRegistry().unregisterServiceUnit(su);
-        }
+        // The endpoints are deployed by the JBI deployer when the DeployedAssembly is processed.
+        // The JBI deployer is responsible for managing the SA lifecycle and will undeploy the SU itself
     }
 
     public static class OsgiServiceUnit extends DefaultServiceUnit {

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java?rev=721141&r1=721140&r2=721141&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java Thu Nov 27 02:04:59 2008
@@ -31,6 +31,8 @@
 
     String getName();
 
+    void deploy();
+
     Map<String, String> getServiceUnits();
 
 }