use of java.util.HashMap in project camel by apache.
the class ManagedRoute method dumpRouteStatsAsXml.
public String dumpRouteStatsAsXml(boolean fullStats, boolean includeProcessors) throws Exception {
// in this logic we need to calculate the accumulated processing time for the processor in the route
// and hence why the logic is a bit more complicated to do this, as we need to calculate that from
// the bottom -> top of the route but this information is valuable for profiling routes
StringBuilder sb = new StringBuilder();
// need to calculate this value first, as we need that value for the route stat
Long processorAccumulatedTime = 0L;
// gather all the processors for this route, which requires JMX
if (includeProcessors) {
sb.append(" <processorStats>\n");
MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
if (server != null) {
// get all the processor mbeans and sort them accordingly to their index
String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
ObjectName query = ObjectName.getInstance(jmxDomain + ":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 = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedProcessorMBean.class);
// the processor must belong to this route
if (getRouteId().equals(processor.getRouteId())) {
mps.add(processor);
}
}
mps.sort(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\" state=\"%s\"", processor.getProcessorId(), processor.getIndex(), processor.getState()));
// 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");
}
// route self time is route total - processor accumulated total)
long routeSelfTime = getTotalProcessingTime() - processorAccumulatedTime;
if (routeSelfTime < 0) {
// ensure we don't calculate that as negative
routeSelfTime = 0;
}
StringBuilder answer = new StringBuilder();
answer.append("<routeStat").append(String.format(" id=\"%s\"", route.getId())).append(String.format(" state=\"%s\"", getState()));
// use substring as we only want the attributes
String stat = dumpStatsAsXml(fullStats);
answer.append(" exchangesInflight=\"").append(getInflightExchanges()).append("\"");
answer.append(" selfProcessingTime=\"").append(routeSelfTime).append("\"");
InFlightKey oldestInflightEntry = getOldestInflightEntry();
if (oldestInflightEntry == null) {
answer.append(" oldestInflightExchangeId=\"\"");
answer.append(" oldestInflightDuration=\"\"");
} else {
answer.append(" oldestInflightExchangeId=\"").append(oldestInflightEntry.exchangeId).append("\"");
answer.append(" oldestInflightDuration=\"").append(System.currentTimeMillis() - oldestInflightEntry.timeStamp).append("\"");
}
answer.append(" ").append(stat.substring(7, stat.length() - 2)).append(">\n");
if (includeProcessors) {
answer.append(sb);
}
answer.append("</routeStat>");
return answer.toString();
}
use of java.util.HashMap in project camel by apache.
the class MockEndpointTest method testSetMultipleExpectedHeaders4.
public void testSetMultipleExpectedHeaders4() throws Exception {
// to test the header value with Stream which can only be consumed once
InputStream is = new ByteArrayInputStream("Test".getBytes());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived("foo", 123);
mock.expectedHeaderReceived("bar", "Test");
Map<String, Object> map = new HashMap<String, Object>();
map.put("foo", 123);
map.put("bar", is);
template.sendBodyAndHeaders("direct:a", "Hello World", map);
mock.assertIsSatisfied();
}
use of java.util.HashMap in project camel by apache.
the class CollectionConverterTest method testToProperties.
public void testToProperties() {
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("foo", "bar");
Properties prop = CollectionConverter.toProperties(map);
assertNotNull(prop);
assertEquals(1, prop.size());
assertEquals("bar", prop.get("foo"));
}
use of java.util.HashMap in project camel by apache.
the class DefaultExchangeHolderTest method testSkipNonSerializableDataFromMap.
public void testSkipNonSerializableDataFromMap() throws Exception {
// use a mixed Map, the MyFoo is not serializable so the entire map should be skipped
Map<String, Object> map = new HashMap<String, Object>();
map.put("A", "I am okay");
map.put("B", new MyFoo("Tiger"));
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader("Foo", map);
exchange.getIn().setHeader("Bar", 123);
DefaultExchangeHolder holder = DefaultExchangeHolder.marshal(exchange);
exchange = new DefaultExchange(context);
DefaultExchangeHolder.unmarshal(exchange, holder);
// the non serializable header should be skipped
assertEquals("Hello World", exchange.getIn().getBody());
assertEquals(123, exchange.getIn().getHeader("Bar"));
assertNull(exchange.getIn().getHeader("Foo"));
}
use of java.util.HashMap in project camel by apache.
the class DefaultProducerTemplateAsyncTest method testRequestAsyncBodyAndHeaders.
public void testRequestAsyncBodyAndHeaders() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
mock.expectedHeaderReceived("foo", 123);
mock.expectedHeaderReceived("bar", "cheese");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("foo", 123);
headers.put("bar", "cheese");
Future<Object> future = template.asyncRequestBodyAndHeaders("direct:start", "Hello", headers);
long start = System.currentTimeMillis();
// you can do other stuff
String echo = template.requestBody("direct:echo", "Hi", String.class);
assertEquals("HiHi", echo);
// we can use extract body to convert to expect body type
String result = template.extractFutureBody(future, String.class);
assertMockEndpointsSatisfied();
long delta = System.currentTimeMillis() - start;
assertEquals("Hello World", result);
assertTrue("Should take longer than: " + delta, delta > 250);
}
Aggregations