String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=processors,*");
Set<ObjectName> names = server.queryNames(query, null);
List<ManagedProcessorMBean> mps = new ArrayList<ManagedProcessorMBean>();
for (ObjectName on : names) {
ManagedProcessorMBean processor = MBeanServerInvocationHandler.newProxyInstance(server, on, ManagedProcessorMBean.class, true);
// the processor must belong to this route
if (getRouteId().equals(processor.getRouteId())) {
mps.add(processor);
}
}
Collections.sort(mps, new OrderProcessorMBeans());
// walk the processors in reverse order, and calculate the accumulated total time
Map<String, Long> accumulatedTimes = new HashMap<String, Long>();
Collections.reverse(mps);
for (ManagedProcessorMBean processor : mps) {
processorAccumulatedTime += processor.getTotalProcessingTime();
accumulatedTimes.put(processor.getProcessorId(), processorAccumulatedTime);
}
// and reverse back again
Collections.reverse(mps);
// and now add the sorted list of processors to the xml output
for (ManagedProcessorMBean processor : mps) {
sb.append(" <processorStat").append(String.format(" id=\"%s\" index=\"%s\"", processor.getProcessorId(), processor.getIndex()));
// do we have an accumulated time then append that
Long accTime = accumulatedTimes.get(processor.getProcessorId());
if (accTime != null) {
sb.append(" accumulatedProcessingTime=\"").append(accTime).append("\"");
}
// use substring as we only want the attributes
sb.append(" ").append(processor.dumpStatsAsXml(fullStats).substring(7)).append("\n");
}
}
sb.append(" </processorStats>\n");
}