You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2008/01/28 09:55:53 UTC
svn commit: r615770 - in
/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management:
InstrumentationAgentImpl.java InstrumentationLifecycleStrategy.java
ManagedEndpoint.java ManagedRoute.java ManagedService.java
PerformanceCounter.java
Author: ningjiang
Date: Mon Jan 28 00:55:52 2008
New Revision: 615770
URL: http://svn.apache.org/viewvc?rev=615770&view=rev
Log:
Better formate of the management code
Modified:
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/management/ManagedEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java
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=615770&r1=615769&r2=615770&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 Jan 28 00:55:52 2008
@@ -52,75 +52,79 @@
import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
-public class InstrumentationAgentImpl extends ServiceSupport implements InstrumentationAgent, CamelContextAware {
+public class InstrumentationAgentImpl extends ServiceSupport implements InstrumentationAgent,
+ CamelContextAware {
private static final transient Log LOG = LogFactory.getLog(InstrumentationAgentImpl.class);
-
- public static final String SYSTEM_PROPERTY_JMX = "org.apache.camel.jmx";
- public static final String DEFAULT_DOMAIN = "org.apache.camel";
- public static final String DEFAULT_HOST = "localhost";
- public static final int DEFAULT_PORT = 1099;
-
- private MBeanServer server;
- private CamelContext context;
+
+ public static final String SYSTEM_PROPERTY_JMX = "org.apache.camel.jmx";
+ public static final String DEFAULT_DOMAIN = "org.apache.camel";
+ public static final String DEFAULT_HOST = "localhost";
+ public static final int DEFAULT_PORT = 1099;
+
+ private MBeanServer server;
+ private CamelContext context;
private Set<ObjectName> mbeans = new HashSet<ObjectName>();
private MetadataMBeanInfoAssembler assembler;
private JMXConnectorServer cs;
- private boolean jmxEnabled = false;
- private String jmxDomainName = null;
- private int jmxConnectorPort = 0;
+ 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());
+ assembler = new MetadataMBeanInfoAssembler();
+ assembler.setAttributeSource(new AnnotationJmxAttributeSource());
+ // naming = new
+ // CamelNamingStrategy(agent.getMBeanServer().getDefaultDomain());
namingStrategy = new CamelNamingStrategy();
}
public CamelContext getCamelContext() {
- return context;
- }
+ return context;
+ }
- public void setCamelContext(CamelContext camelContext) {
- context = camelContext;
- }
+ public void setCamelContext(CamelContext camelContext) {
+ context = camelContext;
+ }
- public void setMBeanServer(MBeanServer server) {
- this.server = server;
+ public void setMBeanServer(MBeanServer server) {
+ this.server = server;
jmxEnabled = true;
- }
-
- public MBeanServer getMBeanServer() {
+ }
+
+ public MBeanServer getMBeanServer() {
if (server == null) {
server = ManagementFactory.getPlatformMBeanServer();
}
return server;
- }
+ }
- public void register(Object obj, ObjectName name) throws JMException {
- register(obj, name, false);
- }
+ public void register(Object obj, ObjectName name) throws JMException {
+ register(obj, name, false);
+ }
- public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
+ public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
try {
- registerMBeanWithServer(obj, name, forceRegistration);
- } catch (NotCompliantMBeanException e) {
- //If this is not a "normal" MBean, then try to deploy it using JMX annotations
- ModelMBeanInfo mbi = null;
- mbi = assembler.getMBeanInfo(obj, name.toString());
- RequiredModelMBean mbean = (RequiredModelMBean)server.instantiate(RequiredModelMBean.class.getName());
+ registerMBeanWithServer(obj, name, forceRegistration);
+ } catch (NotCompliantMBeanException e) {
+ // If this is not a "normal" MBean, then try to deploy it using JMX
+ // annotations
+ ModelMBeanInfo mbi = null;
+ mbi = assembler.getMBeanInfo(obj, name.toString());
+ RequiredModelMBean mbean = (RequiredModelMBean)server.instantiate(RequiredModelMBean.class
+ .getName());
mbean.setModelMBeanInfo(mbi);
try {
- mbean.setManagedResource(obj, "ObjectReference");
+ mbean.setManagedResource(obj, "ObjectReference");
} catch (InvalidTargetObjectTypeException itotex) {
throw new JMException(itotex.getMessage());
}
registerMBeanWithServer(mbean, name, forceRegistration);
- }
- }
+ }
+ }
- public void unregister(ObjectName name) throws JMException {
+ public void unregister(ObjectName name) throws JMException {
server.unregisterMBean(name);
}
@@ -136,9 +140,9 @@
ObjectHelper.notNull(context, "camelContext");
if (getMBeanServer() == null) {
- // The MBeanServer was not injected
- createMBeanServer();
- }
+ // The MBeanServer was not injected
+ createMBeanServer();
+ }
if (jmxDomainName == null) {
jmxDomainName = System.getProperty(SYSTEM_PROPERTY_JMX + ".domain");
@@ -147,23 +151,24 @@
}
}
configureDomainName();
-
+
LOG.debug("Starting JMX agent on server: " + getMBeanServer());
- if (context instanceof DefaultCamelContext) {
- DefaultCamelContext dc = (DefaultCamelContext)context;
- InstrumentationLifecycleStrategy ls = new InstrumentationLifecycleStrategy(this);
- dc.setLifecycleStrategy(ls);
- ls.onContextCreate(context);
- }
+ if (context instanceof DefaultCamelContext) {
+ DefaultCamelContext dc = (DefaultCamelContext)context;
+ InstrumentationLifecycleStrategy ls = new InstrumentationLifecycleStrategy(this);
+ dc.setLifecycleStrategy(ls);
+ ls.onContextCreate(context);
+ }
}
protected void doStop() throws Exception {
- //Using the array to hold the busMBeans to avoid the CurrentModificationException
+ // Using the array to hold the busMBeans to avoid the
+ // CurrentModificationException
Object[] mBeans = mbeans.toArray();
int caught = 0;
for (Object name : mBeans) {
- mbeans.remove((ObjectName)name);
+ mbeans.remove((ObjectName)name);
try {
unregister((ObjectName)name);
} catch (JMException jmex) {
@@ -172,38 +177,38 @@
}
}
if (caught > 0) {
- LOG.warn("A number of " + caught +
- " exceptions caught while unregistering MBeans during stop operation. " +
- "See INFO log for details.");
- }
- }
-
- private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration)
- throws JMException {
-
- ObjectInstance instance = null;
- try {
- instance = server.registerMBean(obj, name);
- } catch (InstanceAlreadyExistsException e) {
- if (forceRegistration) {
- server.unregisterMBean(name);
- instance = server.registerMBean(obj, name);
- } else {
- throw e;
- }
- }
-
- if (instance != null) {
- mbeans.add(name);
- }
+ LOG.warn("A number of " + caught
+ + " exceptions caught while unregistering MBeans during stop operation. "
+ + "See INFO log for details.");
+ }
+ }
+
+ private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration)
+ throws JMException {
+
+ ObjectInstance instance = null;
+ try {
+ instance = server.registerMBean(obj, name);
+ } catch (InstanceAlreadyExistsException e) {
+ if (forceRegistration) {
+ server.unregisterMBean(name);
+ instance = server.registerMBean(obj, name);
+ } else {
+ throw e;
+ }
+ }
+
+ if (instance != null) {
+ mbeans.add(name);
+ }
}
- public void enableJmx(String domainName, int port) {
- jmxEnabled = true;
+ public void enableJmx(String domainName, int port) {
+ jmxEnabled = true;
jmxDomainName = domainName;
configureDomainName();
jmxConnectorPort = port;
- }
+ }
protected void configureDomainName() {
if (jmxDomainName != null) {
@@ -215,103 +220,98 @@
String hostName = DEFAULT_HOST;
boolean canAccessSystemProps = true;
try {
- // we'll do it this way mostly to determine if we should lookup the hostName
+ // we'll do it this way mostly to determine if we should lookup the
+ // hostName
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertiesAccess();
}
- }
- catch (SecurityException se) {
+ } catch (SecurityException se) {
canAccessSystemProps = false;
}
- if (canAccessSystemProps) {
- if (!jmxEnabled) {
- jmxEnabled = null != System.getProperty(SYSTEM_PROPERTY_JMX);
- if (!jmxEnabled) {
- // we're done here
- return;
- }
- }
-
- if (jmxConnectorPort <= 0) {
- String portKey = SYSTEM_PROPERTY_JMX + ".port";
- String portValue = System.getProperty(portKey);
- if (portValue != null && portValue.length() > 0) {
- try {
- jmxConnectorPort = Integer.parseInt(portValue);
- }
- catch (NumberFormatException nfe) {
- LOG.info("Invalid port number specified via System property [" +
- portKey + "=" + portValue + "]. Using default: " + DEFAULT_PORT);
- jmxConnectorPort = DEFAULT_PORT;
- }
- }
- }
-
- try {
+ if (canAccessSystemProps) {
+ if (!jmxEnabled) {
+ jmxEnabled = null != System.getProperty(SYSTEM_PROPERTY_JMX);
+ if (!jmxEnabled) {
+ // we're done here
+ return;
+ }
+ }
+
+ if (jmxConnectorPort <= 0) {
+ String portKey = SYSTEM_PROPERTY_JMX + ".port";
+ String portValue = System.getProperty(portKey);
+ if (portValue != null && portValue.length() > 0) {
+ try {
+ jmxConnectorPort = Integer.parseInt(portValue);
+ } catch (NumberFormatException nfe) {
+ LOG.info("Invalid port number specified via System property [" + portKey + "="
+ + portValue + "]. Using default: " + DEFAULT_PORT);
+ jmxConnectorPort = DEFAULT_PORT;
+ }
+ }
+ }
+
+ try {
hostName = InetAddress.getLocalHost().getHostName();
- }
- catch (UnknownHostException uhe) {
- LOG.info("Cannot determine host name. Using default: " + DEFAULT_PORT, uhe);
+ } catch (UnknownHostException uhe) {
+ LOG.info("Cannot determine host name. Using default: " + DEFAULT_PORT, uhe);
hostName = DEFAULT_HOST;
- }
- }
- else {
- jmxDomainName = jmxDomainName != null ? jmxDomainName : DEFAULT_DOMAIN;
- jmxConnectorPort = jmxConnectorPort > 0 ? jmxConnectorPort : DEFAULT_PORT;
+ }
+ } else {
+ jmxDomainName = jmxDomainName != null ? jmxDomainName : DEFAULT_DOMAIN;
+ jmxConnectorPort = jmxConnectorPort > 0 ? jmxConnectorPort : DEFAULT_PORT;
hostName = DEFAULT_HOST;
- }
-
- if (!jmxEnabled) {
- return;
- }
-
- // jmx is enabled but there's no MBeanServer, so create one
- List servers = MBeanServerFactory.findMBeanServer(jmxDomainName);
- if (servers.size() == 0) {
- server = MBeanServerFactory.createMBeanServer(jmxDomainName);
- }
- else {
- server = (MBeanServer)servers.get(0);
- }
+ }
+
+ if (!jmxEnabled) {
+ return;
+ }
+
+ // jmx is enabled but there's no MBeanServer, so create one
+ List servers = MBeanServerFactory.findMBeanServer(jmxDomainName);
+ if (servers.size() == 0) {
+ server = MBeanServerFactory.createMBeanServer(jmxDomainName);
+ } else {
+ server = (MBeanServer)servers.get(0);
+ }
- // we need a connector too
- try {
+ // we need a connector too
+ try {
createJmxConnector(hostName);
- }
- catch (IOException ioe) {
- LOG.warn("Could not create and start jmx connector.", ioe);
- }
+ } catch (IOException ioe) {
+ LOG.warn("Could not create and start jmx connector.", ioe);
+ }
}
-
+
protected void createJmxConnector(String host) throws IOException {
- if (jmxConnectorPort > 0) {
- try {
- LocateRegistry.createRegistry(jmxConnectorPort);
- } catch (RemoteException ex) {
- // the registry may had been created
- LocateRegistry.getRegistry(jmxConnectorPort);
- }
-
- // Create an RMI connector and start it
- JMXServiceURL url = new JMXServiceURL(
- "service:jmx:rmi:///jndi/rmi://" + host + ":" + jmxConnectorPort + "/jmxrmi");
- cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
-
- // Start the connector server asynchronously (in a separate thread).
- Thread connectorThread = new Thread() {
- public void run() {
- try {
- cs.start();
- } catch (IOException ioe) {
- LOG.warn("Could not start jmx connector thread.", ioe);
- }
- }
- };
- connectorThread.setName("JMX Connector Thread [" + url + "]");
- connectorThread.start();
- LOG.info("Jmx connector thread started on " + url);
- }
- }
+ if (jmxConnectorPort > 0) {
+ try {
+ LocateRegistry.createRegistry(jmxConnectorPort);
+ } catch (RemoteException ex) {
+ // the registry may had been created
+ LocateRegistry.getRegistry(jmxConnectorPort);
+ }
+
+ // Create an RMI connector and start it
+ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":"
+ + jmxConnectorPort + "/jmxrmi");
+ cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
+
+ // Start the connector server asynchronously (in a separate thread).
+ Thread connectorThread = new Thread() {
+ public void run() {
+ try {
+ cs.start();
+ } catch (IOException ioe) {
+ LOG.warn("Could not start jmx connector thread.", ioe);
+ }
+ }
+ };
+ connectorThread.setName("JMX Connector Thread [" + url + "]");
+ connectorThread.start();
+ LOG.info("Jmx connector thread started on " + url);
+ }
+ }
}
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=615770&r1=615769&r2=615770&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 Jan 28 00:55:52 2008
@@ -41,13 +41,13 @@
private CamelNamingStrategy namingStrategy;
public InstrumentationLifecycleStrategy(InstrumentationAgent agent) {
- this.agent = agent;
+ this.agent = agent;
setNamingStrategy(agent.getNamingStrategy());
}
-
- public void onContextCreate(CamelContext context) {
- if (context instanceof DefaultCamelContext) {
- try {
+
+ public void onContextCreate(CamelContext context) {
+ if (context instanceof DefaultCamelContext) {
+ try {
DefaultCamelContext dc = (DefaultCamelContext)context;
ManagedService ms = new ManagedService(dc);
agent.register(ms, getNamingStrategy().getObjectName(dc));
@@ -57,53 +57,49 @@
}
}
- public void onEndpointAdd(Endpoint<? extends Exchange> endpoint) {
- try {
- ManagedEndpoint me = new ManagedEndpoint(endpoint);
- agent.register(me, getNamingStrategy().getObjectName(me));
- }
- catch(JMException e) {
- LOG.warn("Could not register Endpoint MBean", e);
- }
- }
-
- public void onRoutesAdd(Collection<Route> routes) {
- for (Route route: routes) {
- try {
- ManagedRoute mr = new ManagedRoute(route);
- agent.register(mr, getNamingStrategy().getObjectName(mr));
- }
- catch(JMException e) {
- LOG.warn("Could not register Route MBean", e);
- }
- }
- }
-
- public void onServiceAdd(CamelContext context, Service service) {
- if (service instanceof ServiceSupport) {
- try {
- ManagedService ms = new ManagedService((ServiceSupport)service);
- agent.register(ms, getNamingStrategy().getObjectName(context, ms));
- }
- catch(JMException e) {
- LOG.warn("Could not register Service MBean", e);
- }
- }
- }
+ public void onEndpointAdd(Endpoint<? extends Exchange> endpoint) {
+ try {
+ ManagedEndpoint me = new ManagedEndpoint(endpoint);
+ agent.register(me, getNamingStrategy().getObjectName(me));
+ } catch (JMException e) {
+ LOG.warn("Could not register Endpoint MBean", e);
+ }
+ }
- public void onRouteContextCreate(RouteContext routeContext) {
+ public void onRoutesAdd(Collection<Route> routes) {
+ for (Route route : routes) {
+ try {
+ ManagedRoute mr = new ManagedRoute(route);
+ agent.register(mr, getNamingStrategy().getObjectName(mr));
+ } catch (JMException e) {
+ LOG.warn("Could not register Route MBean", e);
+ }
+ }
+ }
+
+ public void onServiceAdd(CamelContext context, Service service) {
+ if (service instanceof ServiceSupport) {
+ try {
+ ManagedService ms = new ManagedService((ServiceSupport)service);
+ agent.register(ms, getNamingStrategy().getObjectName(context, ms));
+ } catch (JMException e) {
+ LOG.warn("Could not register Service MBean", e);
+ }
+ }
+ }
+
+ public void onRouteContextCreate(RouteContext routeContext) {
PerformanceCounter mc = new PerformanceCounter();
routeContext.getRoute().intercept(new InstrumentationProcessor(mc));
/*
- * Merge performance counter with the MBean it represents instead
- * of registering a new MBean
+ * Merge performance counter with the MBean it represents instead of
+ * registering a new MBean
*/
try {
- agent.register(mc, getNamingStrategy().getObjectName(
- routeContext.getCamelContext(), mc, routeContext));
- }
- catch(JMException e) {
+ agent.register(mc, getNamingStrategy().getObjectName(routeContext.getCamelContext(), mc,
+ routeContext));
+ } catch (JMException e) {
LOG.warn("Could not register Counter MBean", e);
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java?rev=615770&r1=615769&r2=615770&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java Mon Jan 28 00:55:52 2008
@@ -22,23 +22,21 @@
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
-@ManagedResource(
- description="Managed Endpoint",
- currencyTimeLimit=15)
+@ManagedResource(description = "Managed Endpoint", currencyTimeLimit = 15)
public class ManagedEndpoint {
-
- private Endpoint<? extends Exchange> endpoint;
- public ManagedEndpoint(Endpoint<? extends Exchange> endpoint) {
- this.endpoint = endpoint;
- }
-
- public Endpoint<? extends Exchange> getEndpoint() {
- return endpoint;
- }
-
- @ManagedAttribute(description = "Endpoint Uri")
- public String getUri() throws Exception {
- return endpoint.getEndpointUri();
- }
+ private Endpoint<? extends Exchange> endpoint;
+
+ public ManagedEndpoint(Endpoint<? extends Exchange> endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public Endpoint<? extends Exchange> getEndpoint() {
+ return endpoint;
+ }
+
+ @ManagedAttribute(description = "Endpoint Uri")
+ public String getUri() throws Exception {
+ return endpoint.getEndpointUri();
+ }
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java?rev=615770&r1=615769&r2=615770&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java Mon Jan 28 00:55:52 2008
@@ -26,42 +26,40 @@
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
-@ManagedResource(
- description="Managed Route",
- currencyTimeLimit=15)
+@ManagedResource(description = "Managed Route", currencyTimeLimit = 15)
public class ManagedRoute extends PerformanceCounter {
-
- public static final String VALUE_UNKNOWN = "Unknown";
- private Route<? extends Exchange> route;
- private String description;
-
- ManagedRoute(Route<? extends Exchange> route) {
- this.route = route;
- this.description = route.toString();
- }
-
- public Route<? extends Exchange> getRoute() {
- return route;
- }
-
- @ManagedAttribute(description = "Route Endpoint Uri")
- public String getEndpointUri() {
- Endpoint<? extends Exchange> ep = route.getEndpoint();
- return ep != null ? ep.getEndpointUri() : VALUE_UNKNOWN;
- }
-
- @ManagedAttribute(description = "Route description")
- public String getDescription() {
- return description;
- }
- @ManagedOperation(description = "Start Route")
+ public static final String VALUE_UNKNOWN = "Unknown";
+ private Route<? extends Exchange> route;
+ private String description;
+
+ ManagedRoute(Route<? extends Exchange> route) {
+ this.route = route;
+ this.description = route.toString();
+ }
+
+ public Route<? extends Exchange> getRoute() {
+ return route;
+ }
+
+ @ManagedAttribute(description = "Route Endpoint Uri")
+ public String getEndpointUri() {
+ Endpoint<? extends Exchange> ep = route.getEndpoint();
+ return ep != null ? ep.getEndpointUri() : VALUE_UNKNOWN;
+ }
+
+ @ManagedAttribute(description = "Route description")
+ public String getDescription() {
+ return description;
+ }
+
+ @ManagedOperation(description = "Start Route")
public void start() throws IOException {
- throw new IOException("Not supported");
+ throw new IOException("Not supported");
}
- @ManagedOperation(description = "Stop Route")
+ @ManagedOperation(description = "Stop Route")
public void stop() throws IOException {
- throw new IOException("Not supported");
+ throw new IOException("Not supported");
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java?rev=615770&r1=615769&r2=615770&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java Mon Jan 28 00:55:52 2008
@@ -25,43 +25,41 @@
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
-@ManagedResource(
- description="Managed Service",
- currencyTimeLimit=15)
+@ManagedResource(description = "Managed Service", currencyTimeLimit = 15)
public class ManagedService {
- private ServiceSupport service;
-
- public ManagedService(ServiceSupport service) {
- this.service = service;
- }
-
- public Service getService() {
- return service;
- }
-
- @ManagedAttribute(description = "Service running state")
+ private ServiceSupport service;
+
+ public ManagedService(ServiceSupport service) {
+ this.service = service;
+ }
+
+ public Service getService() {
+ return service;
+ }
+
+ @ManagedAttribute(description = "Service running state")
public boolean isStarted() throws IOException {
- return service.isStarted();
+ return service.isStarted();
}
- @ManagedOperation(description = "Start Service")
+ @ManagedOperation(description = "Start Service")
public void start() throws IOException {
- try {
- service.start();
- }
- catch (Exception e) {
- throw new IOException(e.getMessage());
- }
- }
-
- @ManagedOperation(description = "Stop Service")
- public void stop() throws IOException {
- try {
- service.stop();
- }
- catch (Exception e) {
- throw new IOException(e.getMessage());
- }
- }
+ try {
+ service.start();
+ }
+ catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ @ManagedOperation(description = "Stop Service")
+ public void stop() throws IOException {
+ try {
+ service.stop();
+ }
+ catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java?rev=615770&r1=615769&r2=615770&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java Mon Jan 28 00:55:52 2008
@@ -23,65 +23,63 @@
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
-@ManagedResource(
- description="PerformanceCounter",
- currencyTimeLimit=15)
+@ManagedResource(description = "PerformanceCounter", currencyTimeLimit = 15)
public class PerformanceCounter extends Counter {
- private AtomicLong numCompleted = new AtomicLong(0L);
- private long minProcessingTime = -1L;
- private long maxProcessingTime = -1L;
- private double totalProcessingTime = 0;
-
- @Override
- @ManagedOperation(description = "Reset counters")
- public synchronized void reset() {
- super.reset();
- numCompleted.set(0L);
- minProcessingTime = 0L;
- maxProcessingTime = 0L;
- totalProcessingTime = 0;
- }
-
- @ManagedAttribute(description = "Number of successful exchanges")
- public long getNumCompleted() throws Exception {
- return numCompleted.get();
- }
-
- @ManagedAttribute(description = "Number of failed exchanges")
- public long getNumFailed() throws Exception {
- return numExchanges.get() - numCompleted.get();
- }
-
- @ManagedAttribute(description = "Min Processing Time [usec]")
- public synchronized long getMinProcessingTime() throws Exception {
- return minProcessingTime;
- }
-
- @ManagedAttribute(description = "Mean Processing Time [usec]")
- public synchronized long getMeanProcessingTime() throws Exception {
- long count = numCompleted.get();
- return count > 0 ? (long)totalProcessingTime / count : 0L;
- }
-
- @ManagedAttribute(description = "Max Processing Time [usec]")
- public synchronized long getMaxProcessingTime() throws Exception {
- return maxProcessingTime;
- }
-
- public synchronized void completedExchange(long time) {
- increment();
- numCompleted.incrementAndGet();
- totalProcessingTime += time;
- if (minProcessingTime < 0 || time < minProcessingTime) {
- minProcessingTime = time;
- }
- if (time > maxProcessingTime) {
- maxProcessingTime = time;
- }
- }
-
- public void completedExchange() {
- numExchanges.incrementAndGet();
- }
+ private AtomicLong numCompleted = new AtomicLong(0L);
+ private long minProcessingTime = -1L;
+ private long maxProcessingTime = -1L;
+ private double totalProcessingTime = 0;
+
+ @Override
+ @ManagedOperation(description = "Reset counters")
+ public synchronized void reset() {
+ super.reset();
+ numCompleted.set(0L);
+ minProcessingTime = 0L;
+ maxProcessingTime = 0L;
+ totalProcessingTime = 0;
+ }
+
+ @ManagedAttribute(description = "Number of successful exchanges")
+ public long getNumCompleted() throws Exception {
+ return numCompleted.get();
+ }
+
+ @ManagedAttribute(description = "Number of failed exchanges")
+ public long getNumFailed() throws Exception {
+ return numExchanges.get() - numCompleted.get();
+ }
+
+ @ManagedAttribute(description = "Min Processing Time [usec]")
+ public synchronized long getMinProcessingTime() throws Exception {
+ return minProcessingTime;
+ }
+
+ @ManagedAttribute(description = "Mean Processing Time [usec]")
+ public synchronized long getMeanProcessingTime() throws Exception {
+ long count = numCompleted.get();
+ return count > 0 ? (long)totalProcessingTime / count : 0L;
+ }
+
+ @ManagedAttribute(description = "Max Processing Time [usec]")
+ public synchronized long getMaxProcessingTime() throws Exception {
+ return maxProcessingTime;
+ }
+
+ public synchronized void completedExchange(long time) {
+ increment();
+ numCompleted.incrementAndGet();
+ totalProcessingTime += time;
+ if (minProcessingTime < 0 || time < minProcessingTime) {
+ minProcessingTime = time;
+ }
+ if (time > maxProcessingTime) {
+ maxProcessingTime = time;
+ }
+ }
+
+ public void completedExchange() {
+ numExchanges.incrementAndGet();
+ }
}