servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r701368 - in /servicemix/components/shared-libraries/trunk/servicemix-common: ./ src/main/java/org/apache/servicemix/common/osgi/ src/main/java/org/apache/servicemix/jbi/ src/main/java/org/apache/servicemix/jbi/deployer/
Date Fri, 03 Oct 2008 12:45:04 GMT
Author: gnodet
Date: Fri Oct  3 05:45:04 2008
New Revision: 701368

URL: http://svn.apache.org/viewvc?rev=701368&view=rev
Log:
SMX4NMR-24: JBI endpoints not using the JBI packaging should still abide by the JBI lifecycle
to be able to cleanly shutdown a JBI application

Added:
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/deployer/
    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/pom.xml
    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

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml?rev=701368&r1=701367&r2=701368&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml Fri Oct  3 05:45:04
2008
@@ -39,11 +39,15 @@
         org.apache.servicemix;resolution:=optional,
         org.apache.servicemix.jbi*;resolution:=optional,
         org.apache.servicemix.components*;resolution:=optional,
+        org.apache.servicemix.jbi.deployer;resolution:=optional,
         *
     </servicemix.osgi.import>
     <servicemix.osgi.export.pkg>
         org.apache.servicemix.common
     </servicemix.osgi.export.pkg>
+    <servicemix.osgi.private>
+        org.apache.servicemix.jbi.deployer
+    </servicemix.osgi.private>
   </properties>
 
   <dependencies>

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=701368&r1=701367&r2=701368&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
Fri Oct  3 05:45:04 2008
@@ -19,15 +19,19 @@
 import java.util.Dictionary;
 import java.util.Properties;
 import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
 
 import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.jbi.deployer.DeployedAssembly;
 import org.osgi.framework.BundleContext;
 import org.springframework.osgi.context.BundleContextAware;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.DisposableBean;
 import org.springframework.context.ApplicationContextAware;
 import org.springframework.context.ApplicationContext;
 
-public class EndpointExporter implements BundleContextAware, ApplicationContextAware, InitializingBean
{
+public class EndpointExporter implements BundleContextAware, ApplicationContextAware, InitializingBean,
DisposableBean, DeployedAssembly {
 
     private BundleContext bundleContext;
     private ApplicationContext applicationContext;
@@ -45,16 +49,36 @@
         this.endpoints = endpoints;
     }
 
-    public void afterPropertiesSet() throws Exception {
+    public Collection<Endpoint> getEndpoints() {
         Collection<Endpoint> eps = this.endpoints;
         if (eps == null) {
             eps = this.applicationContext.getBeansOfType(Endpoint.class).values();
         }
+        return eps;
+    }
+
+    public String getName() {
+        return bundleContext.getBundle().getSymbolicName();
+    }
+
+    public Map<String, String> getServiceUnits() {
+        Map<String, String> sus = new HashMap<String, String>();
+        for (Endpoint ep : getEndpoints()) {
+            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);
         }
+        bundleContext.registerService(DeployedAssembly.class.getName(), this, new Properties());
     }
 
+    public void destroy() throws Exception {
+    }
 }

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=701368&r1=701367&r2=701368&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
Fri Oct  3 05:45:04 2008
@@ -23,9 +23,7 @@
 
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.DefaultComponent;
-import org.apache.servicemix.common.ServiceUnit;
 import org.apache.servicemix.common.DefaultServiceUnit;
-import org.apache.servicemix.id.IdGenerator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -56,16 +54,6 @@
             OsgiServiceUnit su = new OsgiServiceUnit(component, endpoint, wrapper.getClassLoader());
             endpoints.put(wrapper, su);
             component.getRegistry().registerServiceUnit(su);
-            if (component.isStarted()) {
-                ClassLoader cl = Thread.currentThread().getContextClassLoader();
-                try {
-                    Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
-                    su.start();
-                } finally {
-                    Thread.currentThread().setContextClassLoader(cl);
-                }
-            }
-
         }
     }
 
@@ -79,31 +67,20 @@
             if (LOGGER.isDebugEnabled()) {
     	        LOGGER.debug("[" + component.getComponentName() + "] Endpoint recognized");
             }
-            try {
-                ClassLoader cl = Thread.currentThread().getContextClassLoader();
-                try {
-                    Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
-                    su.stop();
-                } finally {
-                    Thread.currentThread().setContextClassLoader(cl);
-                }
-            } finally {
-                component.getRegistry().unregisterServiceUnit(su);
-            }
+            component.getRegistry().unregisterServiceUnit(su);
         }
     }
 
     public static class OsgiServiceUnit extends DefaultServiceUnit {
-        private static final IdGenerator idGenerator = new IdGenerator();
         private final Endpoint endpoint;
         private final ClassLoader classLoader;
         public OsgiServiceUnit(DefaultComponent component, Endpoint endpoint, ClassLoader
classLoader) throws DeploymentException {
             this.component = component;
-            this.name = idGenerator.generateSanitizedId();
             this.endpoint = endpoint;
             this.classLoader = classLoader;
             this.endpoint.setServiceUnit(this);
             this.endpoint.validate();
+            this.name = endpoint.getKey();
             addEndpoint(this.endpoint);
         }
         public Endpoint getEndpoint() {

Added: 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=701368&view=auto
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java
(added)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java
Fri Oct  3 05:45:04 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.servicemix.jbi.deployer;
+
+import java.util.Map;
+
+/**
+ * This interface should be used by service assemblies deployed using another packaging
+ * than the JBI packaging to be able to leverage the JBI life cycle.
+ *
+ * This file is a copy of the file from the ServiceMix 4 NMR project and can be removed
+ * once this project has been released.  The package is not exported from this OSGi bundle
+ * and it should be imported from the NMR project.
+ *
+ */
+public interface DeployedAssembly {
+
+    String getName();
+
+    Map<String, String> getServiceUnits();
+
+}



Mime
View raw message