List of usage examples for org.springframework.integration.history MessageHistory size
@Override public int size()
From source file:com.googlecode.msidor.springframework.integration.history.MessageHistoryParser.java
/** * Parse message history generated by spring integration and produce output with components names and components processing times * //w ww . j a v a 2 s. c o m * @param mh message headers to be parsed * @return output with components names and components processing times */ public static String parse(MessageHeaders mh) { StringBuilder sb = new StringBuilder(); //get message history MessageHistory history = mh.get(MessageHistory.HEADER_NAME, MessageHistory.class); String[] names = new String[history.size()]; long[] times = new long[history.size()]; //go thought all history entries Iterator<Properties> historyIterator = history.iterator(); int i = 0; while (historyIterator.hasNext()) { Properties gatewayHistory = historyIterator.next(); String name = gatewayHistory.getProperty("name"); String historyTimestampStr = gatewayHistory.getProperty("timestamp"); Long historyTimestamp = Long.parseLong(historyTimestampStr); names[i] = name; times[i++] = historyTimestamp; } //calculates the time deltas between components final long lastTimestamp = mh.getTimestamp(); for (int j = 0; j < names.length; j++) { if (j > 0) { sb.append("; "); } if (j + 1 < names.length) sb.append(names[j]).append("=").append(times[j + 1] - times[j]); else sb.append(names[j]).append("=").append(lastTimestamp - times[j]); } if (sb.length() > 0) { sb.append("; "); } sb.append("total=").append(lastTimestamp - times[0]); return sb.toString(); }
From source file:org.springframework.integration.jdbc.JdbcMessageStoreTests.java
@Test @Transactional/*from ww w .j ava 2 s . c o m*/ public void testWithMessageHistory() throws Exception { Message<?> message = new GenericMessage<String>("Hello"); DirectChannel fooChannel = new DirectChannel(); fooChannel.setBeanName("fooChannel"); DirectChannel barChannel = new DirectChannel(); barChannel.setBeanName("barChannel"); message = MessageHistory.write(message, fooChannel); message = MessageHistory.write(message, barChannel); messageStore.addMessage(message); message = messageStore.getMessage(message.getHeaders().getId()); MessageHistory messageHistory = MessageHistory.read(message); assertNotNull(messageHistory); assertEquals(2, messageHistory.size()); Properties fooChannelHistory = messageHistory.get(0); assertEquals("fooChannel", fooChannelHistory.get("name")); assertEquals("channel", fooChannelHistory.get("type")); }