You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2012/11/23 16:06:08 UTC
svn commit: r1412907 - in
/camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands:
ContextInfo.java RouteInfo.java
Author: cmoulliard
Date: Fri Nov 23 15:06:07 2012
New Revision: 1412907
URL: http://svn.apache.org/viewvc?rev=1412907&view=rev
Log:
CAMEL-5816 : Improve code to display a warning message on the console when jmx agent has been disabled for camel
Modified:
camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java
camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteInfo.java
Modified: camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java?rev=1412907&r1=1412906&r2=1412907&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java (original)
+++ camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java Fri Nov 23 15:06:07 2012
@@ -28,6 +28,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Route;
import org.apache.camel.management.DefaultManagementAgent;
+import org.apache.camel.spi.ManagementAgent;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -65,73 +66,82 @@ public class ContextInfo extends OsgiCom
System.out.println(StringEscapeUtils.unescapeJava("\tStatus: " + camelContext.getStatus()));
System.out.println(StringEscapeUtils.unescapeJava("\tUptime: " + camelContext.getUptime()));
- // the statistics are in the mbenas
+ // the statistics are in the mbeans
ObjectName contextMBean = null;
- MBeanServer mBeanServer = camelContext.getManagementStrategy().getManagementAgent().getMBeanServer();
- Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(DefaultManagementAgent.DEFAULT_DOMAIN + ":type=context,name=\"" + name + "\",*"), null);
- Iterator<ObjectName> iterator = set.iterator();
- if (iterator.hasNext()) {
- contextMBean = iterator.next();
- }
-
- if (mBeanServer.isRegistered(contextMBean)) {
- Long exchangesTotal = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesTotal");
- System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Total: " + exchangesTotal));
- Long exchangesCompleted = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesCompleted");
- System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Completed: " + exchangesCompleted));
- Long exchangesFailed = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesFailed");
- System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Failed: " + exchangesFailed));
- Long minProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "MinProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tMin Processing Time: " + minProcessingTime + "ms"));
- Long maxProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "MaxProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tMax Processing Time: " + maxProcessingTime + "ms"));
- Long meanProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "MeanProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tMean Processing Time: " + meanProcessingTime + "ms"));
- Long totalProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "TotalProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tTotal Processing Time: " + totalProcessingTime + "ms"));
- Long lastProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "LastProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tLast Processing Time: " + lastProcessingTime + "ms"));
-
- String load01 = (String) mBeanServer.getAttribute(contextMBean, "Load01");
- String load05 = (String) mBeanServer.getAttribute(contextMBean, "Load05");
- String load15 = (String) mBeanServer.getAttribute(contextMBean, "Load15");
- System.out.println(StringEscapeUtils.unescapeJava("\tLoad Avg: " + load01 + ", " + load05 + ", " + load15));
-
- // Test for null to see if a any exchanges have been processed first to avoid NPE
- Object firstExchangeTimestampObj = mBeanServer.getAttribute(contextMBean, "FirstExchangeCompletedTimestamp");
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (firstExchangeTimestampObj == null) {
- // Print an empty value for scripting
- System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date:"));
- } else {
- Date firstExchangeTimestamp = (Date) firstExchangeTimestampObj;
- System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date: " + format.format(firstExchangeTimestamp)));
+ ManagementAgent agent = camelContext.getManagementStrategy().getManagementAgent();
+ if (agent != null) {
+ MBeanServer mBeanServer = agent.getMBeanServer();
+
+ Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(DefaultManagementAgent.DEFAULT_DOMAIN + ":type=context,name=\"" + name + "\",*"), null);
+ Iterator<ObjectName> iterator = set.iterator();
+ if (iterator.hasNext()) {
+ contextMBean = iterator.next();
}
- // Again, check for null to avoid NPE
- Object lastExchangeCompletedTimestampObj = mBeanServer.getAttribute(contextMBean, "LastExchangeCompletedTimestamp");
- if (lastExchangeCompletedTimestampObj == null) {
- // Print an empty value for scripting
- System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date:"));
- } else {
- Date lastExchangeCompletedTimestamp = (Date) lastExchangeCompletedTimestampObj;
- System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date: " + format.format(lastExchangeCompletedTimestamp)));
- }
+ if (mBeanServer.isRegistered(contextMBean)) {
+ Long exchangesTotal = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesTotal");
+ System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Total: " + exchangesTotal));
+ Long exchangesCompleted = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesCompleted");
+ System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Completed: " + exchangesCompleted));
+ Long exchangesFailed = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesFailed");
+ System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Failed: " + exchangesFailed));
+ Long minProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "MinProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tMin Processing Time: " + minProcessingTime + "ms"));
+ Long maxProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "MaxProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tMax Processing Time: " + maxProcessingTime + "ms"));
+ Long meanProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "MeanProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tMean Processing Time: " + meanProcessingTime + "ms"));
+ Long totalProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "TotalProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tTotal Processing Time: " + totalProcessingTime + "ms"));
+ Long lastProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "LastProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tLast Processing Time: " + lastProcessingTime + "ms"));
+
+ String load01 = (String) mBeanServer.getAttribute(contextMBean, "Load01");
+ String load05 = (String) mBeanServer.getAttribute(contextMBean, "Load05");
+ String load15 = (String) mBeanServer.getAttribute(contextMBean, "Load15");
+ System.out.println(StringEscapeUtils.unescapeJava("\tLoad Avg: " + load01 + ", " + load05 + ", " + load15));
+
+ // Test for null to see if a any exchanges have been processed first to avoid NPE
+ Object firstExchangeTimestampObj = mBeanServer.getAttribute(contextMBean, "FirstExchangeCompletedTimestamp");
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ if (firstExchangeTimestampObj == null) {
+ // Print an empty value for scripting
+ System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date:"));
+ } else {
+ Date firstExchangeTimestamp = (Date) firstExchangeTimestampObj;
+ System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date: " + format.format(firstExchangeTimestamp)));
+ }
- long activeRoutes = 0;
- long inactiveRoutes = 0;
- List<Route> routeList = camelContext.getRoutes();
- for (Route route : routeList) {
- if (camelContext.getRouteStatus(route.getId()).isStarted()) {
- activeRoutes++;
+ // Again, check for null to avoid NPE
+ Object lastExchangeCompletedTimestampObj = mBeanServer.getAttribute(contextMBean, "LastExchangeCompletedTimestamp");
+ if (lastExchangeCompletedTimestampObj == null) {
+ // Print an empty value for scripting
+ System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date:"));
} else {
- inactiveRoutes++;
+ Date lastExchangeCompletedTimestamp = (Date) lastExchangeCompletedTimestampObj;
+ System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date: " + format.format(lastExchangeCompletedTimestamp)));
}
- }
- System.out.println(StringEscapeUtils.unescapeJava("\tNumber of running routes: " + activeRoutes));
- System.out.println(StringEscapeUtils.unescapeJava("\tNumber of not running routes: " + inactiveRoutes));
+ long activeRoutes = 0;
+ long inactiveRoutes = 0;
+ List<Route> routeList = camelContext.getRoutes();
+ for (Route route : routeList) {
+ if (camelContext.getRouteStatus(route.getId()).isStarted()) {
+ activeRoutes++;
+ } else {
+ inactiveRoutes++;
+ }
+ }
+ System.out.println(StringEscapeUtils.unescapeJava("\tNumber of running routes: " + activeRoutes));
+ System.out.println(StringEscapeUtils.unescapeJava("\tNumber of not running routes: " + inactiveRoutes));
+
+ }
+
+ } else {
+ System.out.println("");
+ System.out.println(StringEscapeUtils.unescapeJava("\u001B[31mJMX Agent of Camel is not reachable. Maybe it has been disabled on the camel Context"));
+ System.out.println(StringEscapeUtils.unescapeJava("In consequence, the statistics are not available.\u001B[0m"));
}
System.out.println("");
Modified: camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteInfo.java?rev=1412907&r1=1412906&r2=1412907&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteInfo.java (original)
+++ camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteInfo.java Fri Nov 23 15:06:07 2012
@@ -29,6 +29,7 @@ import org.apache.camel.Route;
import org.apache.camel.management.DefaultManagementAgent;
import org.apache.camel.model.ModelHelper;
import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.spi.ManagementAgent;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -71,59 +72,66 @@ public class RouteInfo extends OsgiComma
System.out.println(StringEscapeUtils.unescapeJava("\u001B[1mStatistics\u001B[0m"));
CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
if (camelContext != null) {
- MBeanServer mBeanServer = camelContext.getManagementStrategy().getManagementAgent().getMBeanServer();
- Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(DefaultManagementAgent.DEFAULT_DOMAIN + ":type=routes,name=\"" + route + "\",*"), null);
- Iterator<ObjectName> iterator = set.iterator();
- if (iterator.hasNext()) {
- ObjectName routeMBean = iterator.next();
- Long exchangesTotal = (Long) mBeanServer.getAttribute(routeMBean, "ExchangesTotal");
- System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Total: " + exchangesTotal));
- Long exchangesCompleted = (Long) mBeanServer.getAttribute(routeMBean, "ExchangesCompleted");
- System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Completed: " + exchangesCompleted));
- Long exchangesFailed = (Long) mBeanServer.getAttribute(routeMBean, "ExchangesFailed");
- System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Failed: " + exchangesFailed));
- Long minProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "MinProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tMin Processing Time: " + minProcessingTime + "ms"));
- Long maxProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "MaxProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tMax Processing Time: " + maxProcessingTime + "ms"));
- Long meanProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "MeanProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tMean Processing Time: " + meanProcessingTime + "ms"));
- Long totalProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "TotalProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tTotal Processing Time: " + totalProcessingTime + "ms"));
- Long lastProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "LastProcessingTime");
- System.out.println(StringEscapeUtils.unescapeJava("\tLast Processing Time: " + lastProcessingTime + "ms"));
- String load01 = (String) mBeanServer.getAttribute(routeMBean, "Load01");
- String load05 = (String) mBeanServer.getAttribute(routeMBean, "Load05");
- String load15 = (String) mBeanServer.getAttribute(routeMBean, "Load15");
- System.out.println(StringEscapeUtils.unescapeJava("\tLoad Avg: " + load01 + ", " + load05 + ", " + load15));
-
- // Test for null to see if a any exchanges have been processed first to avoid NPE
- Object firstExchangeTimestampObj = mBeanServer.getAttribute(routeMBean, "FirstExchangeCompletedTimestamp");
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (firstExchangeTimestampObj == null) {
- // Print an empty value for scripting
- System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date:"));
- } else {
- Date firstExchangeTimestamp = (Date) firstExchangeTimestampObj;
- System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date: " + format.format(firstExchangeTimestamp)));
- }
-
- // Again, check for null to avoid NPE
- Object lastExchangeCompletedTimestampObj = mBeanServer.getAttribute(routeMBean, "LastExchangeCompletedTimestamp");
- if (lastExchangeCompletedTimestampObj == null) {
- // Print an empty value for scripting
- System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date:"));
- } else {
- Date lastExchangeCompletedTimestamp = (Date) lastExchangeCompletedTimestampObj;
- System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date: " + format.format(lastExchangeCompletedTimestamp)));
+ ManagementAgent agent = camelContext.getManagementStrategy().getManagementAgent();
+ if (agent != null) {
+ MBeanServer mBeanServer = agent.getMBeanServer();
+ Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(DefaultManagementAgent.DEFAULT_DOMAIN + ":type=routes,name=\"" + route + "\",*"), null);
+ Iterator<ObjectName> iterator = set.iterator();
+ if (iterator.hasNext()) {
+ ObjectName routeMBean = iterator.next();
+ Long exchangesTotal = (Long) mBeanServer.getAttribute(routeMBean, "ExchangesTotal");
+ System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Total: " + exchangesTotal));
+ Long exchangesCompleted = (Long) mBeanServer.getAttribute(routeMBean, "ExchangesCompleted");
+ System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Completed: " + exchangesCompleted));
+ Long exchangesFailed = (Long) mBeanServer.getAttribute(routeMBean, "ExchangesFailed");
+ System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Failed: " + exchangesFailed));
+ Long minProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "MinProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tMin Processing Time: " + minProcessingTime + "ms"));
+ Long maxProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "MaxProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tMax Processing Time: " + maxProcessingTime + "ms"));
+ Long meanProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "MeanProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tMean Processing Time: " + meanProcessingTime + "ms"));
+ Long totalProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "TotalProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tTotal Processing Time: " + totalProcessingTime + "ms"));
+ Long lastProcessingTime = (Long) mBeanServer.getAttribute(routeMBean, "LastProcessingTime");
+ System.out.println(StringEscapeUtils.unescapeJava("\tLast Processing Time: " + lastProcessingTime + "ms"));
+ String load01 = (String) mBeanServer.getAttribute(routeMBean, "Load01");
+ String load05 = (String) mBeanServer.getAttribute(routeMBean, "Load05");
+ String load15 = (String) mBeanServer.getAttribute(routeMBean, "Load15");
+ System.out.println(StringEscapeUtils.unescapeJava("\tLoad Avg: " + load01 + ", " + load05 + ", " + load15));
+
+ // Test for null to see if a any exchanges have been processed first to avoid NPE
+ Object firstExchangeTimestampObj = mBeanServer.getAttribute(routeMBean, "FirstExchangeCompletedTimestamp");
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ if (firstExchangeTimestampObj == null) {
+ // Print an empty value for scripting
+ System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date:"));
+ } else {
+ Date firstExchangeTimestamp = (Date) firstExchangeTimestampObj;
+ System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date: " + format.format(firstExchangeTimestamp)));
+ }
+
+ // Again, check for null to avoid NPE
+ Object lastExchangeCompletedTimestampObj = mBeanServer.getAttribute(routeMBean, "LastExchangeCompletedTimestamp");
+ if (lastExchangeCompletedTimestampObj == null) {
+ // Print an empty value for scripting
+ System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date:"));
+ } else {
+ Date lastExchangeCompletedTimestamp = (Date) lastExchangeCompletedTimestampObj;
+ System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date: " + format.format(lastExchangeCompletedTimestamp)));
+ }
}
+ } else {
+ System.out.println("");
+ System.out.println(StringEscapeUtils.unescapeJava("\u001B[31mJMX Agent of Camel is not reachable. Maybe it has been disabled on the camel Context"));
+ System.out.println(StringEscapeUtils.unescapeJava("In consequence, the statistics are not available.\u001B[0m"));
}
+
+ System.out.println("");
+ System.out.println(StringEscapeUtils.unescapeJava("\u001B[1mDefinition\u001B[0m"));
+ RouteDefinition definition = camelController.getRouteDefinition(route, camelRoute.getRouteContext().getCamelContext().getName());
+ System.out.println(StringEscapeUtils.unescapeJava(ModelHelper.dumpModelAsXml(definition)));
}
- System.out.println("");
- System.out.println(StringEscapeUtils.unescapeJava("\u001B[1mDefinition\u001B[0m"));
- RouteDefinition definition = camelController.getRouteDefinition(route, camelRoute.getRouteContext().getCamelContext().getName());
- System.out.println(StringEscapeUtils.unescapeJava(ModelHelper.dumpModelAsXml(definition)));
return null;
}
-
}