Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.karaf.commands;
 
 import java.util.Date;
 import java.util.Map;
 import java.util.Set;
 
 
Command to display detailed information about a Camel route.
 
 @Command(scope = "camel", name = "route-info", description = "Display information about a Camel route.")
 public class RouteInfo extends CamelCommandSupport {
 
     @Argument(index = 0, name = "route", description = "The Camel route ID.", required = true, multiValued = false)
     String route;
 
     @Argument(index = 1, name = "context", description = "The Camel context name.", required = false, multiValued = false)
     String context;
 
     public Object doExecute() throws Exception {
         Route camelRoute = .getRoute();
 
         if (camelRoute == null) {
             ..println("Camel route " +  + " not found.");
             return null;
         }
 
         ..println(StringEscapeUtils.unescapeJava("\u001B[1m\u001B[33mCamel Route " + camelRoute.getId() + "\u001B[0m"));
         ..println(StringEscapeUtils.unescapeJava("\tCamel Context: " + camelRoute.getRouteContext().getCamelContext().getName()));
         ..println("");
         ..println(StringEscapeUtils.unescapeJava("\u001B[1mProperties\u001B[0m"));
         for (Map.Entry<StringObjectentry : camelRoute.getProperties().entrySet()) {
             ..println(StringEscapeUtils.unescapeJava("\t" + entry.getKey() + " = " + entry.getValue()));
         }
         ..println("");
         ..println(StringEscapeUtils.unescapeJava("\u001B[1mStatistics\u001B[0m"));
         CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
         if (camelContext != null) {
             ManagementAgent agent = camelContext.getManagementStrategy().getManagementAgent();
             if (agent != null) {
                 MBeanServer mBeanServer = agent.getMBeanServer();
                 Set<ObjectNameset = mBeanServer.queryNames(new ObjectName(agent.getMBeanObjectDomainName() + ":type=routes,name=\"" +  + "\",*"), null);
                 Iterator<ObjectNameiterator = set.iterator();
                 if (iterator.hasNext()) {
                     ObjectName routeMBean = iterator.next();
 
                     // the route must be part of the camel context
                     String camelId = (StringmBeanServer.getAttribute(routeMBean"CamelId");
                     if (camelId != null && camelId.equals(camelContext.getName())) {
                         Integer inflightExchange = (IntegermBeanServer.getAttribute(routeMBean"InflightExchanges");
                         ..println(StringEscapeUtils.unescapeJava("\tInflight Exchanges: " + inflightExchange));
                         Long exchangesTotal = (LongmBeanServer.getAttribute(routeMBean"ExchangesTotal");
                         ..println(StringEscapeUtils.unescapeJava("\tExchanges Total: " + exchangesTotal));
                         Long exchangesCompleted = (LongmBeanServer.getAttribute(routeMBean"ExchangesCompleted");
                         ..println(StringEscapeUtils.unescapeJava("\tExchanges Completed: " + exchangesCompleted));
                         Long exchangesFailed = (LongmBeanServer.getAttribute(routeMBean"ExchangesFailed");
                         ..println(StringEscapeUtils.unescapeJava("\tExchanges Failed: " + exchangesFailed));
                         Long minProcessingTime = (LongmBeanServer.getAttribute(routeMBean"MinProcessingTime");
                         ..println(StringEscapeUtils.unescapeJava("\tMin Processing Time: " + minProcessingTime + " ms"));
                         Long maxProcessingTime = (LongmBeanServer.getAttribute(routeMBean"MaxProcessingTime");
                         ..println(StringEscapeUtils.unescapeJava("\tMax Processing Time: " + maxProcessingTime + " ms"));
                         Long meanProcessingTime = (LongmBeanServer.getAttribute(routeMBean"MeanProcessingTime");
                         ..println(StringEscapeUtils.unescapeJava("\tMean Processing Time: " + meanProcessingTime + " ms"));
                         Long totalProcessingTime = (LongmBeanServer.getAttribute(routeMBean"TotalProcessingTime");
                         ..println(StringEscapeUtils.unescapeJava("\tTotal Processing Time: " + totalProcessingTime + " ms"));
                         Long lastProcessingTime = (LongmBeanServer.getAttribute(routeMBean"LastProcessingTime");
                         ..println(StringEscapeUtils.unescapeJava("\tLast Processing Time: " + lastProcessingTime + " ms"));
                         Long deltaProcessingTime = (LongmBeanServer.getAttribute(routeMBean"DeltaProcessingTime");
                         ..println(StringEscapeUtils.unescapeJava("\tDelta Processing Time: " + deltaProcessingTime + " ms"));
                         String load01 = (StringmBeanServer.getAttribute(routeMBean"Load01");
                        String load05 = (StringmBeanServer.getAttribute(routeMBean"Load05");
                        String load15 = (StringmBeanServer.getAttribute(routeMBean"Load15");
                        ..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 resetTimestampObj = mBeanServer.getAttribute(routeMBean"ResetTimestamp");
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        if (resetTimestampObj == null) {
                            // Print an empty value for scripting
                            ..println(StringEscapeUtils.unescapeJava("\tReset Statistics Date:"));
                        } else {
                            Date firstExchangeTimestamp = (DateresetTimestampObj;
                            ..println(StringEscapeUtils.unescapeJava("\tReset Statistics Date: " + format.format(firstExchangeTimestamp)));
                        }
                        // Test for null to see if a any exchanges have been processed first to avoid NPE
                        Object firstExchangeTimestampObj = mBeanServer.getAttribute(routeMBean"FirstExchangeCompletedTimestamp");
                        if (firstExchangeTimestampObj == null) {
                            // Print an empty value for scripting
                            ..println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date:"));
                        } else {
                            Date firstExchangeTimestamp = (DatefirstExchangeTimestampObj;
                            ..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
                            ..println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date:"));
                        } else {
                            Date lastExchangeCompletedTimestamp = (DatelastExchangeCompletedTimestampObj;
                            ..println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed Date: " + format.format(lastExchangeCompletedTimestamp)));
                        }
                    }
                }
            } else {
                ..println("");
                ..println(StringEscapeUtils.unescapeJava("\u001B[31mJMX Agent of Camel is not reachable. Maybe it has been disabled on the Camel context"));
                ..println(StringEscapeUtils.unescapeJava("In consequence, some statistics are not available.\u001B[0m"));
            }
            ..println("");
            ..println(StringEscapeUtils.unescapeJava("\u001B[1mDefinition\u001B[0m"));
            RouteDefinition definition = .getRouteDefinition(camelRoute.getRouteContext().getCamelContext().getName());
            ..println(StringEscapeUtils.unescapeJava(ModelHelper.dumpModelAsXml(definition)));
        }
        return null;
    }
New to GrepCode? Check out our FAQ X