You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/09/17 15:05:17 UTC
svn commit: r576408 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/management/ main/java/org/apache/camel/spi/
test/java/org/apache/camel/management/
Author: jstrachan
Date: Mon Sep 17 06:05:17 2007
New Revision: 576408
URL: http://svn.apache.org/viewvc?rev=576408&view=rev
Log:
updated the JMX support to properly deal with registration & deregistration along with fixing issues configuring the domain. Also made the domain default to "org.apache.camel" along with using the default platform MBeanServer by default if none other is specified
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InstrumentationAgent.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java?rev=576408&r1=576407&r2=576408&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java Mon Sep 17 06:05:17 2007
@@ -27,140 +27,175 @@
import org.apache.camel.Endpoint;
public class CamelNamingStrategy {
+ public static final String VALUE_UNKNOWN = "unknown";
+ public static final String KEY_CONTEXT = "context";
+ public static final String KEY_CLASS = "class";
+ public static final String KEY_TYPE = "type";
+ public static final String KEY_NAME = "name";
+ public static final String KEY_ROUTE = "route";
+ public static final String CLASS_ENDPOINTS = "endpoints";
+ public static final String CLASS_SERVICES = "services";
+ public static final String CLASS_ROUTES = "routes";
+ protected String domainName;
+ protected String hostName = "locahost";
- public static final String VALUE_UNKNOWN = "unknown";
- public static final String KEY_CONTEXT = "context";
- public static final String KEY_CLASS = "class";
- public static final String KEY_TYPE = "type";
- public static final String KEY_NAME = "name";
- public static final String KEY_ROUTE = "route";
- public static final String CLASS_ENDPOINTS = "endpoints";
- public static final String CLASS_SERVICES = "services";
- public static final String CLASS_ROUTES = "routes";
-
- protected String domainName = "org.apache.camel";
- protected String hostName = "locahost";
-
- public CamelNamingStrategy(String domainName) {
- if (domainName != null) {
- this.domainName = domainName;
- }
- try {
- hostName = InetAddress.getLocalHost().getHostName();
- }
- catch (UnknownHostException ex) {
- // ignore, use the default "locahost"
- }
- }
+ public CamelNamingStrategy() {
+ this("org.apache.camel");
+ }
- /**
- * Implements the naming strategy for a {@see CamelContext}.
- * The convention used for a {@see CamelContext} ObjectName is
- * "<domain>:context=<context>,name=camel".
- *
- * @param mbean
- * @return generated ObjectName
- * @throws MalformedObjectNameException
- */
- public ObjectName getObjectName(CamelContext context) throws MalformedObjectNameException {
- StringBuffer buffer = new StringBuffer();
- buffer.append(domainName + ":");
- buffer.append(KEY_CONTEXT + "=" + getContextId(context) + ",");
- buffer.append(KEY_NAME + "=" + "context");
- return new ObjectName(buffer.toString());
- }
+ public CamelNamingStrategy(String domainName) {
+ if (domainName != null) {
+ this.domainName = domainName;
+ }
+ try {
+ hostName = InetAddress.getLocalHost().getHostName();
+ }
+ catch (UnknownHostException ex) {
+ // ignore, use the default "locahost"
+ }
+ }
- /**
- * Implements the naming strategy for a {@see ManagedEndpoint}.
- * The convention used for a {@see ManagedEndpoint} ObjectName is
- * "<domain>:context=<context>,type=Endpoints,endpoint=[urlPrefix]localPart".
- *
- * @param mbean
- * @return generated ObjectName
- * @throws MalformedObjectNameException
- */
- public ObjectName getObjectName(ManagedEndpoint mbean) throws MalformedObjectNameException {
- Endpoint ep = mbean.getEndpoint();
-
- StringBuffer buffer = new StringBuffer();
- buffer.append(domainName + ":");
- buffer.append(KEY_CONTEXT + "=" + getContextId(ep.getContext()) + ",");
- buffer.append(KEY_CLASS + "=" + CLASS_ENDPOINTS + ",");
- buffer.append(KEY_NAME + "=" + getEndpointId(ep));
- return new ObjectName(buffer.toString());
- }
+ /**
+ * Implements the naming strategy for a {@see CamelContext}.
+ * The convention used for a {@see CamelContext} ObjectName is
+ * "<domain>:context=<context>,name=camel".
+ *
+ * @param context the camel context
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(CamelContext context) throws MalformedObjectNameException {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(domainName + ":");
+ buffer.append(KEY_CONTEXT + "=" + getContextId(context) + ",");
+ buffer.append(KEY_NAME + "=" + "context");
+ return createObjectName(buffer);
+ }
- /**
- * Implements the naming strategy for a {@see ServiceSpport Service}.
- * The convention used for a {@see Service} ObjectName is
- * "<domain>:context=<context>,type=Services,endpoint=[urlPrefix]localPart".
- *
- * @param mbean
- * @return generated ObjectName
- * @throws MalformedObjectNameException
- */
- public ObjectName getObjectName(CamelContext context, ManagedService mbean) throws MalformedObjectNameException {
- StringBuffer buffer = new StringBuffer();
- buffer.append(domainName + ":");
- buffer.append(KEY_CONTEXT + "=" + getContextId(context) + ",");
- buffer.append(KEY_CLASS + "=" + CLASS_SERVICES + ",");
- buffer.append(KEY_NAME + "=" + Integer.toHexString(mbean.getService().hashCode()));
- return new ObjectName(buffer.toString());
- }
+ /**
+ * Implements the naming strategy for a {@see ManagedEndpoint}.
+ * The convention used for a {@see ManagedEndpoint} ObjectName is
+ * "<domain>:context=<context>,type=Endpoints,endpoint=[urlPrefix]localPart".
+ *
+ * @param mbean
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(ManagedEndpoint mbean) throws MalformedObjectNameException {
+ Endpoint ep = mbean.getEndpoint();
- /**
- * Implements the naming strategy for a {@see ManagedRoute}.
- * The convention used for a {@see ManagedEndpoint} ObjectName is
- * "<domain>:context=<context>,type=Routes,endpoint=[urlPrefix]localPart".
- *
- * @param mbean
- * @return generated ObjectName
- * @throws MalformedObjectNameException
- */
- public ObjectName getObjectName(ManagedRoute mbean) throws MalformedObjectNameException {
- Endpoint ep = mbean.getRoute().getEndpoint();
- String ctxid = ep != null ? getContextId(ep.getContext()) : VALUE_UNKNOWN;
-
- StringBuffer buffer = new StringBuffer();
- buffer.append(domainName + ":");
- buffer.append(KEY_CONTEXT + "=" + ctxid + ",");
- buffer.append(KEY_CLASS + "=" + CLASS_ROUTES + ",");
- buffer.append(KEY_ROUTE + "=" + getEndpointId(ep));
- return new ObjectName(buffer.toString());
- }
-
- /**
- * Implements the naming strategy for a {@see PerformanceCounter}.
- * The convention used for a {@see ManagedEndpoint} ObjectName is
- * "<domain>:context=<context>,type=Routes,endpoint=[urlPrefix]localPart".
- *
- * @param mbean
- * @return generated ObjectName
- * @throws MalformedObjectNameException
- */
- public ObjectName getObjectName(CamelContext context, PerformanceCounter mbean) throws MalformedObjectNameException {
- StringBuffer buffer = new StringBuffer();
- buffer.append(domainName + ":");
- buffer.append(KEY_CONTEXT + "=" + getContextId(context) + ",");
- buffer.append(KEY_CLASS + "=" + CLASS_ROUTES + ",");
- buffer.append(KEY_ROUTE + "=" + "Route.Counter" + ","); // TODO: figure out the route id
- buffer.append(KEY_NAME + "=" + "Stats");
- return new ObjectName(buffer.toString());
- }
-
- protected String getContextId(CamelContext context) {
- String id = context != null ? Integer.toString(context.hashCode()) : VALUE_UNKNOWN;
- return hostName + "/" + id;
- }
-
- protected String getEndpointId(Endpoint ep) {
- String uri = ep.getEndpointUri();
- int pos = uri.indexOf(':');
- String id = (pos == -1) ? uri :
- "[" + uri.substring(0, pos) + "]" + uri.substring(pos + 1);
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(domainName + ":");
+ buffer.append(KEY_CONTEXT + "=" + getContextId(ep.getContext()) + ",");
+ buffer.append(KEY_CLASS + "=" + CLASS_ENDPOINTS + ",");
+ buffer.append(KEY_NAME + "=" + getEndpointId(ep));
+ return createObjectName(buffer);
+ }
+
+ /**
+ * Implements the naming strategy for a {@see ServiceSpport Service}.
+ * The convention used for a {@see Service} ObjectName is
+ * "<domain>:context=<context>,type=Services,endpoint=[urlPrefix]localPart".
+ *
+ * @param mbean
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(CamelContext context, ManagedService mbean) throws MalformedObjectNameException {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(domainName + ":");
+ buffer.append(KEY_CONTEXT + "=" + getContextId(context) + ",");
+ buffer.append(KEY_CLASS + "=" + CLASS_SERVICES + ",");
+ buffer.append(KEY_NAME + "=" + Integer.toHexString(mbean.getService().hashCode()));
+ return createObjectName(buffer);
+ }
+
+
+ /**
+ * Implements the naming strategy for a {@see ManagedRoute}.
+ * The convention used for a {@see ManagedEndpoint} ObjectName is
+ * "<domain>:context=<context>,type=Routes,endpoint=[urlPrefix]localPart".
+ *
+ * @param mbean
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(ManagedRoute mbean) throws MalformedObjectNameException {
+ Endpoint ep = mbean.getRoute().getEndpoint();
+ String ctxid = ep != null ? getContextId(ep.getContext()) : VALUE_UNKNOWN;
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(domainName + ":");
+ buffer.append(KEY_CONTEXT + "=" + ctxid + ",");
+ buffer.append(KEY_CLASS + "=" + CLASS_ROUTES + ",");
+ buffer.append(KEY_ROUTE + "=" + getEndpointId(ep));
+ return createObjectName(buffer);
+ }
+
+ /**
+ * Implements the naming strategy for a {@see PerformanceCounter}.
+ * The convention used for a {@see ManagedEndpoint} ObjectName is
+ * "<domain>:context=<context>,type=Routes,endpoint=[urlPrefix]localPart".
+ *
+ * @param mbean
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(CamelContext context, PerformanceCounter mbean) throws MalformedObjectNameException {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(domainName + ":");
+ buffer.append(KEY_CONTEXT + "=" + getContextId(context) + ",");
+ buffer.append(KEY_CLASS + "=" + CLASS_ROUTES + ",");
+ buffer.append(KEY_ROUTE + "=" + "Route.Counter" + ","); // TODO: figure out the route id
+ buffer.append(KEY_NAME + "=" + "Stats");
+ return createObjectName(buffer);
+ }
+
+ public String getDomainName() {
+ return domainName;
+ }
+
+ public void setDomainName(String domainName) {
+ this.domainName = domainName;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ protected String getContextId(CamelContext context) {
+ String id = context != null ? Integer.toString(context.hashCode()) : VALUE_UNKNOWN;
+ return hostName + "/" + id;
+ }
+
+ protected String getEndpointId(Endpoint ep) {
+ String uri = ep.getEndpointUri();
+ int pos = uri.indexOf(':');
+ String id = (pos == -1) ? uri :
+ "[" + uri.substring(0, pos) + "]" + uri.substring(pos + 1);
if (!ep.isSingleton()) {
id += "." + Integer.toString(ep.hashCode());
}
- return id;
+ id = id.replace("=", "_eq_");
+ id = id.replace(",", "_cm_");
+ return id;
}
+
+ /**
+ * Factory method to create an ObjectName escaping any required characters
+ */
+ protected ObjectName createObjectName(StringBuffer buffer) throws MalformedObjectNameException {
+ String text = buffer.toString();
+ try {
+ text = text.replace("?", "_qe_");
+ return new ObjectName(text);
+ }
+ catch (MalformedObjectNameException e) {
+ throw new MalformedObjectNameException("Could not create ObjectName from: " + text + ". Reason: " + e);
+ }
+ }
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java?rev=576408&r1=576407&r2=576408&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java Mon Sep 17 06:05:17 2007
@@ -18,6 +18,7 @@
package org.apache.camel.management;
import java.io.IOException;
+import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.rmi.RemoteException;
@@ -25,7 +26,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.lang.management.ManagementFactory;
import javax.management.InstanceAlreadyExistsException;
import javax.management.JMException;
@@ -43,14 +43,16 @@
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
-import org.apache.camel.spi.InstrumentationAgent;
import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.ServiceSupport;
+import org.apache.camel.spi.InstrumentationAgent;
+import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
-public class InstrumentationAgentImpl implements InstrumentationAgent, CamelContextAware {
+public class InstrumentationAgentImpl extends ServiceSupport implements InstrumentationAgent, CamelContextAware {
private static final transient Log LOG = LogFactory.getLog(InstrumentationAgentImpl.class);
@@ -67,12 +69,16 @@
private boolean jmxEnabled = false;
private String jmxDomainName = null;
private int jmxConnectorPort = 0;
-
+ private CamelNamingStrategy namingStrategy;
+
public InstrumentationAgentImpl() {
assembler = new MetadataMBeanInfoAssembler();
assembler.setAttributeSource(new AnnotationJmxAttributeSource());
+ //naming = new CamelNamingStrategy(agent.getMBeanServer().getDefaultDomain());
+ namingStrategy = new CamelNamingStrategy();
}
- public CamelContext getCamelContext() {
+
+ public CamelContext getCamelContext() {
return context;
}
@@ -82,7 +88,7 @@
public void setMBeanServer(MBeanServer server) {
this.server = server;
- jmxEnabled = true;
+ jmxEnabled = true;
}
public MBeanServer getMBeanServer() {
@@ -115,28 +121,44 @@
}
public void unregister(ObjectName name) throws JMException {
- }
+ server.unregisterMBean(name);
+ }
- public void start() {
- if (context == null) {
- LOG.warn("Cannot start InstrumentationAgent: CamelContext not set");
- return;
- }
-
- if (server == null) {
+ public CamelNamingStrategy getNamingStrategy() {
+ return namingStrategy;
+ }
+
+ public void setNamingStrategy(CamelNamingStrategy namingStrategy) {
+ this.namingStrategy = namingStrategy;
+ }
+
+ protected void doStart() throws Exception {
+ ObjectHelper.notNull(context, "camelContext");
+
+ if (getMBeanServer() == null) {
// The MBeanServer was not injected
createMBeanServer();
}
+ if (jmxDomainName == null) {
+ jmxDomainName = System.getProperty(SYSTEM_PROPERTY_JMX + ".domain");
+ if (jmxDomainName == null || jmxDomainName.length() == 0) {
+ jmxDomainName = DEFAULT_DOMAIN;
+ }
+ }
+ configureDomainName();
+
+ LOG.debug("Starting JMX agent on server: " + getMBeanServer());
+
if (context instanceof DefaultCamelContext) {
DefaultCamelContext dc = (DefaultCamelContext)context;
- InstrumentationLifecycleStrategy ls = new InstrumentationLifecycleStrategy(this);
+ InstrumentationLifecycleStrategy ls = new InstrumentationLifecycleStrategy(this);
dc.setLifecycleStrategy(ls);
ls.onContextCreate(context);
}
- }
-
- public void stop() {
+ }
+
+ protected void doStop() throws Exception {
//Using the array to hold the busMBeans to avoid the CurrentModificationException
Object[] mBeans = mbeans.toArray();
int caught = 0;
@@ -178,10 +200,17 @@
public void enableJmx(String domainName, int port) {
jmxEnabled = true;
- jmxDomainName = domainName;
- jmxConnectorPort = port;
+ jmxDomainName = domainName;
+ configureDomainName();
+ jmxConnectorPort = port;
}
+ protected void configureDomainName() {
+ if (jmxDomainName != null) {
+ namingStrategy.setDomainName(jmxDomainName);
+ }
+ }
+
protected void createMBeanServer() {
String hostName = DEFAULT_HOST;
boolean canAccessSystemProps = true;
@@ -203,13 +232,6 @@
// we're done here
return;
}
- }
-
- if (jmxDomainName == null) {
- jmxDomainName = System.getProperty(SYSTEM_PROPERTY_JMX + ".domain");
- if (jmxDomainName == null || jmxDomainName.length() == 0) {
- jmxDomainName = DEFAULT_DOMAIN;
- }
}
if (jmxConnectorPort <= 0) {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java?rev=576408&r1=576407&r2=576408&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java Mon Sep 17 06:05:17 2007
@@ -36,20 +36,20 @@
public class InstrumentationLifecycleStrategy implements LifecycleStrategy {
private static final transient Log LOG = LogFactory.getLog(InstrumentationProcessor.class);
- InstrumentationAgent agent;
- CamelNamingStrategy naming;
-
- public InstrumentationLifecycleStrategy(InstrumentationAgent agent) {
+ private InstrumentationAgent agent;
+ private CamelNamingStrategy namingStrategy;
+
+ public InstrumentationLifecycleStrategy(InstrumentationAgent agent) {
this.agent = agent;
- naming = new CamelNamingStrategy(agent.getMBeanServer().getDefaultDomain());
- }
+ setNamingStrategy(agent.getNamingStrategy());
+ }
public void onContextCreate(CamelContext context) {
if (context instanceof DefaultCamelContext) {
try {
DefaultCamelContext dc = (DefaultCamelContext)context;
ManagedService ms = new ManagedService(dc);
- agent.register(ms, naming.getObjectName(dc));
+ agent.register(ms, getNamingStrategy().getObjectName(dc));
}
catch(JMException e) {
LOG.warn("Could not register CamelContext MBean", e);
@@ -60,7 +60,7 @@
public void onEndpointAdd(Endpoint endpoint) {
try {
ManagedEndpoint me = new ManagedEndpoint(endpoint);
- agent.register(me, naming.getObjectName(me));
+ agent.register(me, getNamingStrategy().getObjectName(me));
}
catch(JMException e) {
LOG.warn("Could not register Endpoint MBean", e);
@@ -71,7 +71,7 @@
for (Route route: routes) {
try {
ManagedRoute mr = new ManagedRoute(route);
- agent.register(mr, naming.getObjectName(mr));
+ agent.register(mr, getNamingStrategy().getObjectName(mr));
}
catch(JMException e) {
LOG.warn("Could not register Route MBean", e);
@@ -83,7 +83,7 @@
if (service instanceof ServiceSupport) {
try {
ManagedService ms = new ManagedService((ServiceSupport)service);
- agent.register(ms, naming.getObjectName(context, ms));
+ agent.register(ms, getNamingStrategy().getObjectName(context, ms));
}
catch(JMException e) {
LOG.warn("Could not register Service MBean", e);
@@ -96,10 +96,18 @@
routeType.intercept(new InstrumentationProcessor(mc));
try {
- agent.register(mc, naming.getObjectName(context, mc));
+ agent.register(mc, getNamingStrategy().getObjectName(context, mc));
}
catch(JMException e) {
LOG.warn("Could not register Counter MBean", e);
}
}
+
+ public CamelNamingStrategy getNamingStrategy() {
+ return namingStrategy;
+ }
+
+ public void setNamingStrategy(CamelNamingStrategy namingStrategy) {
+ this.namingStrategy = namingStrategy;
+ }
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InstrumentationAgent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InstrumentationAgent.java?rev=576408&r1=576407&r2=576408&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InstrumentationAgent.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InstrumentationAgent.java Mon Sep 17 06:05:17 2007
@@ -20,7 +20,10 @@
import javax.management.MBeanServer;
import javax.management.ObjectName;
-public interface InstrumentationAgent {
+import org.apache.camel.Service;
+import org.apache.camel.management.CamelNamingStrategy;
+
+public interface InstrumentationAgent extends Service {
/**
* Registers object with management infrastructure with a specific name. Object must be annotated or
@@ -56,4 +59,5 @@
*/
MBeanServer getMBeanServer();
+ CamelNamingStrategy getNamingStrategy();
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java?rev=576408&r1=576407&r2=576408&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java Mon Sep 17 06:05:17 2007
@@ -36,12 +36,69 @@
public static final int DEFAULT_PORT = 1099;
- protected InstrumentationAgentImpl iAgent;
- protected String domainName;
+ protected InstrumentationAgentImpl iAgent;
+ protected String domainName = InstrumentationAgentImpl.DEFAULT_DOMAIN;
+ protected boolean sleepSoYouCanBrowseInJConsole = false;
- protected void enableJmx() {
+ public void testMBeansRegistered() throws Exception {
+ assertNotNull(iAgent.getMBeanServer());
+ //assertEquals(domainName, iAgent.getMBeanServer().getDefaultDomain());
+
+ resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
+
+ ObjectName name = new ObjectName(domainName + ":class=endpoints,*");
+ Set s = iAgent.getMBeanServer().queryNames(name, null);
+
+ if (sleepSoYouCanBrowseInJConsole) {
+ Thread.sleep(100000);
+ }
+ assertEquals("Could not find 2 endpoints: " + s, 2, s.size());
+ }
+
+ public void testCounters() throws Exception {
+ MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
+ resultEndpoint.expectedBodiesReceived("<hello>world!</hello>");
+ sendBody("direct:start", "<hello>world!</hello>");
+
+ resultEndpoint.assertIsSatisfied();
+
+ MBeanServer mbs = iAgent.getMBeanServer();
+ ObjectName name = new ObjectName(domainName + ":name=Stats,*");
+ Set s = mbs.queryNames(name, null);
+ assertEquals("Found mbeans: " + s, 1, s.size());
+
+ Iterator iter = s.iterator();
+ ObjectName pcob = (ObjectName)iter.next();
+
+ Long valueofNumExchanges = (Long)mbs.getAttribute(pcob, "NumExchanges");
+ assertNotNull("Expected attribute not found. MBean registerred under a " +
+ "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofNumExchanges);
+ assertTrue(valueofNumExchanges == 1);
+ Long valueofNumCompleted = (Long)mbs.getAttribute(pcob, "NumCompleted");
+ assertNotNull("Expected attribute not found. MBean registerred under a " +
+ "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofNumCompleted);
+ assertTrue(valueofNumCompleted == 1);
+ Long valueofNumFailed = (Long)mbs.getAttribute(pcob, "NumFailed");
+ assertNotNull("Expected attribute not found. MBean registerred under a " +
+ "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofNumFailed);
+ assertTrue(valueofNumFailed == 0);
+ Long valueofMinProcessingTime = (Long)mbs.getAttribute(pcob, "MinProcessingTime");
+ assertNotNull("Expected attribute not found. MBean registerred under a " +
+ "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofMinProcessingTime);
+ assertTrue(valueofMinProcessingTime > 0);
+ Long valueofMaxProcessingTime = (Long)mbs.getAttribute(pcob, "MaxProcessingTime");
+ assertNotNull("Expected attribute not found. MBean registerred under a " +
+ "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofMaxProcessingTime);
+ assertTrue(valueofMaxProcessingTime > 0);
+ Long valueofMeanProcessingTime = (Long)mbs.getAttribute(pcob, "MeanProcessingTime");
+ assertNotNull("Expected attribute not found. MBean registerred under a " +
+ "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofMeanProcessingTime);
+ assertTrue(valueofMeanProcessingTime >= valueofMinProcessingTime &&
+ valueofMeanProcessingTime <= valueofMaxProcessingTime);
+ }
+
+ protected void enableJmx() {
iAgent.enableJmx(null, 0);
- domainName = InstrumentationAgentImpl.DEFAULT_DOMAIN;
}
protected CamelContext createCamelContext() throws Exception {
@@ -52,7 +109,7 @@
return context;
}
- protected void createInstrumentationAgent(CamelContext context, int port) throws IOException {
+ protected void createInstrumentationAgent(CamelContext context, int port) throws Exception {
iAgent = new InstrumentationAgentImpl();
iAgent.setCamelContext(context);
enableJmx();
@@ -67,58 +124,10 @@
};
}
- public void testAgentConfiguration() throws Exception {
- assertNotNull(iAgent.getMBeanServer());
- assertEquals(domainName, iAgent.getMBeanServer().getDefaultDomain());
- }
-
- public void testMBeansRegistered() throws Exception {
- resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
-
- ObjectName name = new ObjectName(domainName + ":class=endpoints,*");
- Set s = iAgent.getMBeanServer().queryNames(name, null);
- assertTrue(s.size() == 2);
- }
-
- public void testCounters() throws Exception {
- MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
- resultEndpoint.expectedBodiesReceived("<hello>world!</hello>");
- sendBody("direct:start", "<hello>world!</hello>");
- resultEndpoint.assertIsSatisfied();
-
- MBeanServer mbs = iAgent.getMBeanServer();
- ObjectName name = new ObjectName(domainName + ":name=Stats,*");
- Set s = mbs.queryNames(name, null);
- assertTrue(s.size() == 1);
-
- Iterator iter = s.iterator();
- ObjectName pcob = (ObjectName)iter.next();
-
- Long valueofNumExchanges = (Long)mbs.getAttribute(pcob, "NumExchanges");
- assertNotNull("Expected attribute not found. MBean registerred under a " +
- "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofNumExchanges);
- assertTrue(valueofNumExchanges == 1);
- Long valueofNumCompleted = (Long)mbs.getAttribute(pcob, "NumCompleted");
- assertNotNull("Expected attribute not found. MBean registerred under a " +
- "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofNumCompleted);
- assertTrue(valueofNumCompleted == 1);
- Long valueofNumFailed = (Long)mbs.getAttribute(pcob, "NumFailed");
- assertNotNull("Expected attribute not found. MBean registerred under a " +
- "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofNumFailed);
- assertTrue(valueofNumFailed == 0);
- Long valueofMinProcessingTime = (Long)mbs.getAttribute(pcob, "MinProcessingTime");
- assertNotNull("Expected attribute not found. MBean registerred under a " +
- "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofMinProcessingTime);
- assertTrue(valueofMinProcessingTime > 0);
- Long valueofMaxProcessingTime = (Long)mbs.getAttribute(pcob, "MaxProcessingTime");
- assertNotNull("Expected attribute not found. MBean registerred under a " +
- "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofMaxProcessingTime);
- assertTrue(valueofMaxProcessingTime > 0);
- Long valueofMeanProcessingTime = (Long)mbs.getAttribute(pcob, "MeanProcessingTime");
- assertNotNull("Expected attribute not found. MBean registerred under a " +
- "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class", valueofMeanProcessingTime);
- assertTrue(valueofMeanProcessingTime >= valueofMinProcessingTime &&
- valueofMeanProcessingTime <= valueofMaxProcessingTime);
+ @Override
+ protected void tearDown() throws Exception {
+ iAgent.stop();
+ super.tearDown();
}
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java?rev=576408&r1=576407&r2=576408&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java Mon Sep 17 06:05:17 2007
@@ -19,6 +19,7 @@
public class JmxInstrumentationWithConnectorTest extends JmxInstrumentationUsingDefaultsTest {
+
@Override
protected void enableJmx() {
domainName = "org.apache.camel-explicit";