Author: davsclaus
Date: Fri Apr 24 15:32:47 2009
New Revision: 768333
URL: http://svn.apache.org/viewvc?rev=768333&view=rev
Log:
CAMEL-1528: Added option to only register processors in JMX that have custom id
set.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentDefinition.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java?rev=768333&r1=768332&r2=768333&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java
Fri Apr 24 15:32:47 2009
@@ -73,6 +73,7 @@
private String serviceUrlPath;
private Boolean usePlatformMBeanServer = true;
private Boolean createConnector;
+ private Boolean onlyRegisterProcessorWithCustomId;
protected void finalizeSettings() {
if (registryPort == null) {
@@ -103,8 +104,11 @@
if (System.getProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS) !=
null) {
usePlatformMBeanServer =
Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS);
}
- }
+ if (onlyRegisterProcessorWithCustomId == null) {
+ onlyRegisterProcessorWithCustomId =
Boolean.getBoolean(JmxSystemPropertyKeys.ONLY_REGISTER_PROCESSOR_WITH_CUSTOM_ID);
+ }
+ }
public void setRegistryPort(Integer value) {
registryPort = value;
@@ -162,6 +166,14 @@
return usePlatformMBeanServer;
}
+ public Boolean getOnlyRegisterProcessorWithCustomId() {
+ return onlyRegisterProcessorWithCustomId;
+ }
+
+ public void setOnlyRegisterProcessorWithCustomId(Boolean
onlyRegisterProcessorWithCustomId) {
+ this.onlyRegisterProcessorWithCustomId =
onlyRegisterProcessorWithCustomId;
+ }
+
public void setServer(MBeanServer value) {
server = value;
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java?rev=768333&r1=768332&r2=768333&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
Fri Apr 24 15:32:47 2009
@@ -224,6 +224,11 @@
// register all processors
for (ProcessorDefinition processor : route.getOutputs()) {
+ // skip processors that should not be registered
+ if (!registerProcessor(processor)) {
+ continue;
+ }
+
ObjectName name = null;
try {
// get the mbean name
@@ -243,7 +248,6 @@
}
// add intercept strategy that executes the JMX instrumentation for
performance metrics
- // TODO: We could do as below with an inlined implementation instead
of a separate class
routeContext.addInterceptStrategy(new
InstrumentationInterceptStrategy(registeredCounters));
// instrument the route endpoint
@@ -272,6 +276,22 @@
}
+ /**
+ * Should the given processor be registered.
+ */
+ protected boolean registerProcessor(ProcessorDefinition processor) {
+ if (agent instanceof DefaultInstrumentationAgent) {
+ DefaultInstrumentationAgent dia = (DefaultInstrumentationAgent)
agent;
+ if (dia.getOnlyRegisterProcessorWithCustomId() != null &&
dia.getOnlyRegisterProcessorWithCustomId()) {
+ // only register if the processor have an explicy id assigned
+ return processor.hasCustomIdAssigned();
+ }
+ }
+
+ // fallback to always register it
+ return true;
+ }
+
public CamelNamingStrategy getNamingStrategy() {
return namingStrategy;
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java?rev=768333&r1=768332&r2=768333&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxSystemPropertyKeys.java
Fri Apr 24 15:32:47 2009
@@ -47,6 +47,9 @@
// use jvm platform mbean server flag
public static final String USE_PLATFORM_MBS =
"org.apache.camel.jmx.usePlatformMBeanServer";
+ // whether all processors or only processors with a custom id given should
be registered
+ public static final String ONLY_REGISTER_PROCESSOR_WITH_CUSTOM_ID =
"org.apache.camel.jmx.onlyRegisterProcessorWithCustomId";
+
private JmxSystemPropertyKeys() {
// not instantiated
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=768333&r1=768332&r2=768333&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
Fri Apr 24 15:32:47 2009
@@ -530,6 +530,24 @@
return to(ExchangePattern.InOut, endpoints);
}
+ /**
+ * Sets the id of this node
+ *
+ * @param id the id
+ * @return the builder
+ */
+ @SuppressWarnings("unchecked")
+ public Type id(String id) {
+ if (getOutputs().isEmpty()) {
+ // set id on this
+ setId(id);
+ } else {
+ // set it on last output as this is what the user means to do
+ getOutputs().get(getOutputs().size() - 1).setId(id);
+ }
+
+ return (Type) this;
+ }
/**
* <a href="http://camel.apache.org/multicast.html">Multicast EIP:</a>
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest.java?rev=768333&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest.java
Fri Apr 24 15:32:47 2009
@@ -0,0 +1,120 @@
+/**
+ * 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.management;
+
+import java.lang.management.ManagementFactory;
+import java.util.List;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest extends
ContextTestSupport {
+
+ protected String domainName = DefaultInstrumentationAgent.DEFAULT_DOMAIN;
+ protected MBeanServerConnection mbsc;
+ protected long sleepForConnection;
+
+ public void testCustomId() throws Exception {
+ if (System.getProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS) != null
+ &&
!Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS)) {
+ assertEquals(domainName, mbsc.getDefaultDomain());
+ }
+
+ Set s = mbsc.queryNames(new ObjectName(domainName +
":type=endpoints,*"), null);
+ assertEquals("Could not find 2 endpoints: " + s, 6, s.size());
+
+ s = mbsc.queryNames(new ObjectName(domainName + ":name=context,*"),
null);
+ assertEquals("Could not find 1 context: " + s, 1, s.size());
+
+ s = mbsc.queryNames(new ObjectName(domainName + ":type=processors,*"),
null);
+ assertEquals("Could not find 1 processor: " + s, 1, s.size());
+ // should be mock foo
+ ObjectName on = (ObjectName) s.iterator().next();
+ assertEquals("myfoo", on.getKeyProperty("nodeid"));
+
+ s = mbsc.queryNames(new ObjectName(domainName + ":type=routes,*"),
null);
+ assertEquals("Could not find 1 route: " + s, 2, s.size());
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+
System.clearProperty(JmxSystemPropertyKeys.ONLY_REGISTER_PROCESSOR_WITH_CUSTOM_ID);
+ releaseMBeanServers();
+ mbsc = null;
+ super.tearDown();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void releaseMBeanServers() {
+ List<MBeanServer> servers = (List<MBeanServer>)
MBeanServerFactory.findMBeanServer(null);
+ for (MBeanServer server : servers) {
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+
System.setProperty(JmxSystemPropertyKeys.ONLY_REGISTER_PROCESSOR_WITH_CUSTOM_ID,
"true");
+ releaseMBeanServers();
+ super.setUp();
+ Thread.sleep(sleepForConnection);
+ mbsc = getMBeanConnection();
+ }
+
+
+ protected MBeanServerConnection getMBeanConnection() throws Exception {
+ if (mbsc == null) {
+ mbsc = ManagementFactory.getPlatformMBeanServer();
+ }
+ return mbsc;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ // sets the id of the previous node, that is the mock:foo
+ .to("mock:foo").id("myfoo")
+ .delay(10)
+ .to("mock:result");
+
+ from("direct:other")
+ .to("mock:bar")
+ .delay(10)
+ .to("mock:other");
+ }
+ };
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=768333&r1=768332&r2=768333&view=diff
==============================================================================
---
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Fri Apr 24 15:32:47 2009
@@ -346,7 +346,7 @@
private void initJMXAgent() throws Exception {
if (camelJMXAgent != null && camelJMXAgent.isDisabled()) {
- LOG.debug("JMXAgent disabled");
+ LOG.info("JMXAgent disabled");
getContext().setLifecycleStrategy(new DefaultLifecycleStrategy());
} else if (camelJMXAgent != null) {
DefaultInstrumentationAgent agent = new
DefaultInstrumentationAgent();
@@ -357,6 +357,7 @@
agent.setRegistryPort(camelJMXAgent.getRegistryPort());
agent.setServiceUrlPath(camelJMXAgent.getServiceUrlPath());
agent.setUsePlatformMBeanServer(camelJMXAgent.isUsePlatformMBeanServer());
+
agent.setOnlyRegisterProcessorWithCustomId(camelJMXAgent.getOnlyRegisterProcessorWithCustomId());
LOG.info("JMXAgent enabled: " + camelJMXAgent);
getContext().setLifecycleStrategy(new
InstrumentationLifecycleStrategy(agent));
Modified:
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentDefinition.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentDefinition.java?rev=768333&r1=768332&r2=768333&view=diff
==============================================================================
---
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentDefinition.java
(original)
+++
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentDefinition.java
Fri Apr 24 15:32:47 2009
@@ -33,6 +33,7 @@
@XmlRootElement(name = "jmxAgent")
@XmlAccessorType(XmlAccessType.FIELD)
public class CamelJMXAgentDefinition extends IdentifiedType {
+
/**
* Disable JMI (default false)
*/
@@ -40,6 +41,12 @@
private Boolean disabled = Boolean.FALSE;
/**
+ * Only register processor if a custom id was defined for it.
+ */
+ @XmlAttribute(required = false)
+ private Boolean onlyRegisterProcessorWithCustomId = Boolean.FALSE;
+
+ /**
* RMI connector registry port (default 1099)
*/
@XmlAttribute(required = false)
@@ -137,6 +144,14 @@
usePlatformMBeanServer = value != null ? value : Boolean.FALSE;
}
+ public Boolean getOnlyRegisterProcessorWithCustomId() {
+ return onlyRegisterProcessorWithCustomId;
+ }
+
+ public void setOnlyRegisterProcessorWithCustomId(Boolean
onlyRegisterProcessorWithCustomId) {
+ this.onlyRegisterProcessorWithCustomId =
onlyRegisterProcessorWithCustomId;
+ }
+
public Boolean isDisabled() {
return disabled;
}