You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2010/05/21 13:42:34 UTC

svn commit: r946975 - in /servicemix/components/engines/servicemix-camel/trunk/src: main/java/org/apache/servicemix/camel/osgi/ main/resources/META-INF/spring/ test/java/org/apache/servicemix/camel/osgi/

Author: gertv
Date: Fri May 21 11:42:33 2010
New Revision: 946975

URL: http://svn.apache.org/viewvc?rev=946975&view=rev
Log:
SMXCOMP-749: No shutdown timeout for Camel JBI endpoints that are deployed with spring XML in ServiceMix 4

Added:
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponentTest.java
Modified:
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java?rev=946975&r1=946974&r2=946975&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java Fri May 21 11:42:33 2010
@@ -28,6 +28,7 @@ import org.apache.servicemix.camel.Camel
 import org.apache.servicemix.camel.CamelSpringDeployer;
 import org.apache.servicemix.common.BaseServiceUnitManager;
 import org.apache.servicemix.common.Deployer;
+import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.ServiceMixComponent;
 import org.apache.servicemix.common.xbean.ClassLoaderXmlPreprocessor;
 import org.apache.xbean.classloader.JarFileClassLoader;
@@ -56,6 +57,8 @@ public class OsgiCamelJbiComponent exten
     private static final Log LOG = LogFactory.getLog(OsgiCamelJbiComponent.class);
     private BundleContext bundleContext;
 
+    private long shutdownTimeout;
+
     public void setBundleContext(BundleContext bundleContext) {
         this.bundleContext = bundleContext;
     }
@@ -145,4 +148,17 @@ public class OsgiCamelJbiComponent exten
                                           parents.toArray(new ClassLoader[parents.size()]));
         }
     }
+
+    @Override
+    public void prepareShutdown(Endpoint endpoint) throws InterruptedException {
+        prepareShutdown(endpoint, shutdownTimeout);
+    }
+
+    public long getShutdownTimeout() {
+        return shutdownTimeout;
+    }
+
+    public void setShutdownTimeout(long shutdownTimeout) {
+        this.shutdownTimeout = shutdownTimeout;
+    }
 }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml?rev=946975&r1=946974&r2=946975&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml Fri May 21 11:42:33 2010
@@ -19,28 +19,39 @@
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:ctx="http://www.springframework.org/schema/context"
        xmlns:osgi="http://www.springframework.org/schema/osgi"
-       xmlns:util="http://www.springframework.org/schema/util"
+       xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
        xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
-  http://www.springframework.org/schema/util
-  http://www.springframework.org/schema/util/spring-util.xsd
+  http://www.springframework.org/schema/context
+  http://www.springframework.org/schema/context/spring-context.xsd  
   http://www.springframework.org/schema/osgi
-  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+  http://www.springframework.org/schema/osgi/spring-osgi.xsd
+  http://www.springframework.org/schema/osgi-compendium
+  http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">
 
-    <bean id="servicemix-camel" class="org.apache.servicemix.camel.osgi.OsgiCamelJbiComponent">
-    </bean>
+  <!-- Configuration Admin PID org.apache.servicemix.jbi -->
+  <osgix:cm-properties id="cmProps" persistent-id="org.apache.servicemix.jbi">
+    <prop key="shutdownTimeout">0</prop>
+  </osgix:cm-properties>
 
-    <osgi:service ref="servicemix-camel">
-        <osgi:interfaces>
-            <value>javax.jbi.component.Component</value>
-            <value>org.apache.servicemix.camel.CamelComponent</value>
-        </osgi:interfaces>
-        <osgi:service-properties>
-            <entry key="NAME" value="servicemix-camel" />
-            <entry key="TYPE" value="service-engine" />
-        </osgi:service-properties>
-    </osgi:service>
+  <ctx:property-placeholder properties-ref="cmProps"/>
+
+  <bean id="servicemix-camel" class="org.apache.servicemix.camel.osgi.OsgiCamelJbiComponent">
+    <property name="shutdownTimeout" value="${shutdownTimeout}"/>
+  </bean>
+
+  <osgi:service ref="servicemix-camel">
+    <osgi:interfaces>
+      <value>javax.jbi.component.Component</value>
+      <value>org.apache.servicemix.camel.CamelComponent</value>
+    </osgi:interfaces>
+    <osgi:service-properties>
+      <entry key="NAME" value="servicemix-camel"/>
+      <entry key="TYPE" value="service-engine"/>
+    </osgi:service-properties>
+  </osgi:service>
 
 </beans>

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponentTest.java?rev=946975&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponentTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponentTest.java Fri May 21 11:42:33 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.camel.osgi;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.endpoints.SimpleEndpoint;
+
+/**
+ * Test cases for {@link org.apache.servicemix.camel.osgi.OsgiCamelJbiComponent}
+ */
+public class OsgiCamelJbiComponentTest extends TestCase {
+
+    private static final Long TIMEOUT = 1000l;
+
+    public void testShutdownTimeout() throws InterruptedException {
+        final ThreadLocal<Long> shutdownTimeout = new ThreadLocal<Long>();
+        shutdownTimeout.set(-1l);
+
+        OsgiCamelJbiComponent component = new OsgiCamelJbiComponent() {
+            @Override
+            public void prepareShutdown(Endpoint endpoint, long timeout) throws InterruptedException {
+                shutdownTimeout.set(timeout);
+            }
+        };
+
+        final Endpoint endpoint = new MockEndpoint();
+
+        // the default shutdown timeout should be 0
+        component.prepareShutdown(endpoint);
+        assertEquals("The default timeout is 0",
+                     new Long(0), shutdownTimeout.get());
+
+        // another value can be configured on the component
+        component.setShutdownTimeout(TIMEOUT);
+        component.prepareShutdown(endpoint);
+        assertEquals("If a value is configured, that value should be used",
+                     TIMEOUT, shutdownTimeout.get());
+
+    }
+
+    public static class MockEndpoint extends SimpleEndpoint {
+
+        public MockEndpoint() {
+            super();
+            setService(new QName("urn:test", "service"));
+            setEndpoint("endpoint");
+        }
+
+        @Override
+        public MessageExchange.Role getRole() {
+            return null;
+        }
+
+        @Override
+        public void process(MessageExchange exchange) throws Exception {
+            // graciously do nothing
+        }
+    }
+}
\ No newline at end of file