camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1428346 - in /camel/trunk/components/camel-servletlistener/src: main/java/org/apache/camel/component/servletlistener/ test/java/org/apache/camel/component/servletlistener/ test/resources/
Date Thu, 03 Jan 2013 13:48:03 GMT
Author: davsclaus
Date: Thu Jan  3 13:48:03 2013
New Revision: 1428346

URL: http://svn.apache.org/viewvc?rev=1428346&view=rev
Log:
CAMEL-5906: Added new camel-servletlistener component for bootstrapping Camel in web app without
using spring etc. Work in progress.

Added:
    camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/JmxDisabledTest.java
      - copied, changed from r1428319, camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/SingleRouteTest.java
    camel/trunk/components/camel-servletlistener/src/test/resources/myweb7.xml
      - copied, changed from r1428319, camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml
Modified:
    camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java

Modified: camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java?rev=1428346&r1=1428345&r2=1428346&view=diff
==============================================================================
--- camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
(original)
+++ camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
Thu Jan  3 13:48:03 2013
@@ -30,12 +30,18 @@ import javax.naming.NamingException;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 
+import org.apache.camel.ManagementStatisticsLevel;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.ErrorHandlerBuilderRef;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.management.DefaultManagementAgent;
+import org.apache.camel.management.DefaultManagementLifecycleStrategy;
+import org.apache.camel.management.DefaultManagementStrategy;
+import org.apache.camel.management.ManagedManagementStrategy;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.IntrospectionSupport;
@@ -62,10 +68,6 @@ public class CamelContextServletListener
     private CamelContextLifecycle camelContextLifecycle;
     private boolean test;
 
-    // TODO: Maybe some way of having CamelContextLifecycleSupport using bean parameter binding
-    // so ppl can build their Camel app without camel-servletlistener dependency on the codebase
-    // TODO: add example and add documentation page
-
     @Override
     public void contextInitialized(ServletContextEvent sce) {
         LOG.info("CamelContextServletListener initializing ...");
@@ -91,6 +93,7 @@ public class CamelContextServletListener
         // set properties on the camel context from the init parameters
         try {
             initPropertyPlaceholder(camelContext, map);
+            initJmx(camelContext, map);
             initCamelContext(camelContext, map);
             if (!map.isEmpty()) {
                 IntrospectionSupport.setProperties(camelContext, map);
@@ -239,6 +242,56 @@ public class CamelContextServletListener
     }
 
     /**
+     * Initializes JMX on {@link ServletCamelContext} with the configuration from the given
init parameters.
+     */
+    private void initJmx(ServletCamelContext camelContext, Map<String, Object> parameters)
throws Exception {
+        // setup jmx
+        Map<String, Object> properties = IntrospectionSupport.extractProperties(parameters,
"jmx.");
+        if (properties != null && !properties.isEmpty()) {
+            String disabled = (String) properties.remove("disabled");
+            boolean disableJmx = CamelContextHelper.parseBoolean(camelContext, disabled !=
null ? disabled : "false");
+            if (disableJmx) {
+                // disable JMX which is a bit special to do
+                LOG.info("JMXAgent disabled");
+                // clear the existing lifecycle strategies define by the DefaultCamelContext
constructor
+                camelContext.getLifecycleStrategies().clear();
+                // no need to add a lifecycle strategy as we do not need one as JMX is disabled
+                camelContext.setManagementStrategy(new DefaultManagementStrategy());
+            } else {
+                LOG.info("JMXAgent enabled");
+                DefaultManagementAgent agent = new DefaultManagementAgent(camelContext);
+                IntrospectionSupport.setProperties(agent, properties);
+
+                ManagementStrategy managementStrategy = new ManagedManagementStrategy(camelContext,
agent);
+                camelContext.setManagementStrategy(managementStrategy);
+
+                // clear the existing lifecycle strategies define by the DefaultCamelContext
constructor
+                camelContext.getLifecycleStrategies().clear();
+                camelContext.addLifecycleStrategy(new DefaultManagementLifecycleStrategy(camelContext));
+                // set additional configuration from agent
+                boolean onlyId = agent.getOnlyRegisterProcessorWithCustomId() != null &&
agent.getOnlyRegisterProcessorWithCustomId();
+                camelContext.getManagementStrategy().onlyManageProcessorWithCustomId(onlyId);
+
+                String statisticsLevel = (String) properties.remove("statisticsLevel");
+                if (statisticsLevel != null) {
+                    camelContext.getManagementStrategy().setStatisticsLevel(ManagementStatisticsLevel.valueOf(statisticsLevel));
+                }
+
+                String loadStatisticsEnabled = (String) properties.remove("loadStatisticsEnabled");
+                Boolean statisticsEnabled = CamelContextHelper.parseBoolean(camelContext,
loadStatisticsEnabled != null ? loadStatisticsEnabled : "true");
+                if (statisticsEnabled != null) {
+                    camelContext.getManagementStrategy().setLoadStatisticsEnabled(statisticsEnabled);
+                }
+            }
+            // validate we could set all parameters
+            if (!properties.isEmpty()) {
+                throw new IllegalArgumentException("Error setting jmx parameters on CamelContext."
+                        + " There are " + properties.size() + " unknown parameters. [" +
properties + "]");
+            }
+        }
+    }
+
+    /**
      * Initializes the {@link ServletCamelContext} by setting the supported init parameters.
      */
     private void initCamelContext(ServletCamelContext camelContext, Map<String, Object>
parameters) throws Exception {

Copied: camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/JmxDisabledTest.java
(from r1428319, camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/SingleRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/JmxDisabledTest.java?p2=camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/JmxDisabledTest.java&p1=camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/SingleRouteTest.java&r1=1428319&r2=1428346&rev=1428346&view=diff
==============================================================================
--- camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/SingleRouteTest.java
(original)
+++ camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/JmxDisabledTest.java
Thu Jan  3 13:48:03 2013
@@ -24,10 +24,10 @@ import org.junit.Test;
 /**
  *
  */
-public class SingleRouteTest extends ServletCamelTestSupport {
+public class JmxDisabledTest extends ServletCamelTestSupport {
 
     protected String getConfiguration() {
-        return "/myweb.xml";
+        return "/myweb7.xml";
     }
 
     @Test

Copied: camel/trunk/components/camel-servletlistener/src/test/resources/myweb7.xml (from r1428319,
camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/test/resources/myweb7.xml?p2=camel/trunk/components/camel-servletlistener/src/test/resources/myweb7.xml&p1=camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml&r1=1428319&r2=1428346&rev=1428346&view=diff
==============================================================================
--- camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml (original)
+++ camel/trunk/components/camel-servletlistener/src/test/resources/myweb7.xml Thu Jan  3
13:48:03 2013
@@ -44,6 +44,13 @@
     <param-value>org.apache.camel.component.servletlistener.MyRoute</param-value>
   </context-param>
 
+  <!-- configure JMX by using names that is prefixed with jmx. -->
+  <!-- in this example we disable JMX -->
+  <context-param>
+    <param-name>jmx.disabled</param-name>
+    <param-value>true</param-value>
+  </context-param>
+
   <listener>
     <listener-class>org.apache.camel.component.servletlistener.CamelContextServletListener</listener-class>
   </listener>



Mime
View raw message