Author: ningjiang
Date: Wed Jun 4 01:07:26 2008
New Revision: 663026
URL: http://svn.apache.org/viewvc?rev=663026&view=rev
Log:
CAMEL-575 patch applied with thanks to William
Added:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
(with props)
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
(with props)
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/lifecycleStrategyInjection.xml
(with props)
Modified:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Modified:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=663026&r1=663025&r2=663026&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Wed Jun 4 01:07:26 2008
@@ -39,6 +39,7 @@
import org.apache.camel.model.dataformat.DataFormatType;
import org.apache.camel.processor.interceptor.Debugger;
import org.apache.camel.spi.InstrumentationAgent;
+import org.apache.camel.spi.LifecycleStrategy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
@@ -102,7 +103,6 @@
@XmlTransient
private BeanPostProcessor beanPostProcessor;
-
public CamelContextFactoryBean() {
// Lets keep track of the class loader for when we actually do start
things up
@@ -124,24 +124,18 @@
public void afterPropertiesSet() throws Exception {
// lets see if we can find a debugger to add
// TODO there should be a neater way to do this!
- Debugger debugger = null;
- String[] names =
getApplicationContext().getBeanNamesForType(Debugger.class, true, true);
- if (names.length == 1) {
- debugger = (Debugger) getApplicationContext().getBean(names[0],
Debugger.class);
- }
- if (debugger == null) {
- ApplicationContext parentContext =
getApplicationContext().getParent();
- if (parentContext != null) {
- names = parentContext.getBeanNamesForType(Debugger.class,
true, true);
- if (names.length == 1) {
- debugger = (Debugger) parentContext.getBean(names[0],
Debugger.class);
- }
- }
- }
+ Debugger debugger = getBeanForType(Debugger.class);
+
if (debugger != null) {
getContext().addInterceptStrategy(debugger);
}
+ LifecycleStrategy lifecycleStrategy =
getBeanForType(LifecycleStrategy.class);
+
+ if (lifecycleStrategy != null) {
+ getContext().setLifecycleStrategy(lifecycleStrategy);
+ }
+
// Set the application context and camelContext for the
beanPostProcessor
if (beanPostProcessor != null) {
if (beanPostProcessor instanceof ApplicationContextAware) {
@@ -155,7 +149,13 @@
// lets force any lazy creation
getContext().addRouteDefinitions(routes);
// set the instrumentation agent here
+
if (instrumentationAgent == null && isJmxEnabled()) {
+
+ if (lifecycleStrategy != null) {
+ LOG.warn("lifecycleStrategy will be overriden by
InstrumentationLifecycleStrategy");
+ }
+
SpringInstrumentationAgent agent = new
SpringInstrumentationAgent();
if (camelJMXAgent != null) {
agent.enableJmx(camelJMXAgent.getJmxDomainName(),
camelJMXAgent.getConnectorPath(), camelJMXAgent.getConnectorPort());
@@ -176,14 +176,33 @@
}
instrumentationAgent = agent;
instrumentationAgent.start();
- }
-
+ }
+
LOG.debug("Found JAXB created routes: " + getRoutes());
findRouteBuiders();
installRoutes();
}
+ private <T> T getBeanForType(Class<T> clazz) {
+ T bean = null;
+ String[] names = getApplicationContext().getBeanNamesForType(clazz,
true, true);
+ if (names.length == 1) {
+ bean = (T) getApplicationContext().getBean(names[0], clazz);
+ }
+ if (bean == null) {
+ ApplicationContext parentContext =
getApplicationContext().getParent();
+ if (parentContext != null) {
+ names = parentContext.getBeanNamesForType(clazz, true, true);
+ if (names.length == 1) {
+ bean = (T) parentContext.getBean(names[0], clazz);
+ }
+ }
+ }
+ return bean;
+
+ }
+
public void destroy() throws Exception {
getContext().stop();
}
Added:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java?rev=663026&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
(added)
+++
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
Wed Jun 4 01:07:26 2008
@@ -0,0 +1,62 @@
+/**
+ * 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.camel.spring;
+
+import java.util.Collection;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Route;
+import org.apache.camel.Service;
+import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * Dummy LifecycleStrategy for LifecycleStrategy injection test.
+ *
+ * @version $Revision$
+ *
+ */
+public class DummyLifecycleStrategy implements LifecycleStrategy {
+
+ public void onContextCreate(CamelContext context) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onEndpointAdd(Endpoint<? extends Exchange> endpoint) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onRouteContextCreate(RouteContext routeContext) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onRoutesAdd(Collection<Route> routes) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onServiceAdd(CamelContext context, Service service) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java?rev=663026&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
(added)
+++
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
Wed Jun 4 01:07:26 2008
@@ -0,0 +1,42 @@
+/**
+ * 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.camel.spring;
+
+import org.apache.camel.CamelContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Test for LifecycleStrategy injection.
+ *
+ * @version $Revision$
+ *
+ */
+public class LifecycleStrategyInjectionTest extends SpringTestSupport {
+
+
+ @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ setUseRouteBuilder(false);
+ return new
ClassPathXmlApplicationContext("org/apache/camel/spring/lifecycleStrategyInjection.xml");
+ }
+
+ public void testInjectedStrategy() throws Exception {
+ CamelContext context = createCamelContext();
+ assertTrue(context.getLifecycleStrategy() instanceof
DummyLifecycleStrategy);
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/lifecycleStrategyInjection.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/lifecycleStrategyInjection.xml?rev=663026&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/lifecycleStrategyInjection.xml
(added)
+++
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/lifecycleStrategyInjection.xml
Wed Jun 4 01:07:26 2008
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:camel="http://activemq.apache.org/camel/schema/spring"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="lifecycleStrategy"
class="org.apache.camel.spring.DummyLifecycleStrategy"/>
+
+ <camel:camelContext id="camel">
+ <camel:route>
+ <camel:from uri="seda:start"/>
+ <camel:to uri="mock:result"/>
+ </camel:route>
+ </camel:camelContext>
+
+</beans>
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/lifecycleStrategyInjection.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/lifecycleStrategyInjection.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/lifecycleStrategyInjection.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml