simplifying MessageHistory
This commit is contained in:
@@ -42,7 +42,7 @@ public class MessageHistory implements Iterable<MessageHistoryEvent>, Serializab
|
||||
*/
|
||||
public MessageHistoryEvent addEvent(ComponentMetadata metadata) {
|
||||
if (metadata != null && metadata.getComponentName() != null) {
|
||||
MessageHistoryEvent event = new MessageHistoryEvent(metadata);
|
||||
MessageHistoryEvent event = new MessageHistoryEvent(metadata.getComponentType(), metadata.getComponentName());
|
||||
this.events.add(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.history;
|
||||
|
||||
import org.springframework.integration.support.ComponentMetadata;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Metadata about a historically relevant messaging event along
|
||||
@@ -25,25 +25,50 @@ import org.springframework.integration.support.ComponentMetadata;
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MessageHistoryEvent extends ComponentMetadata {
|
||||
public class MessageHistoryEvent implements Serializable {
|
||||
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
private final String type;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final long timestamp;
|
||||
|
||||
|
||||
/**
|
||||
* Create a MessageHistoryEvent with the metadata of the source component.
|
||||
*/
|
||||
public MessageHistoryEvent(ComponentMetadata metadata) {
|
||||
super(metadata);
|
||||
this.setAttribute(TIMESTAMP, System.currentTimeMillis());
|
||||
public MessageHistoryEvent(String type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp generated when this event was created.
|
||||
*/
|
||||
public long getTimestamp() {
|
||||
return this.getAttribute(TIMESTAMP, long.class);
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (this.type != null) {
|
||||
sb.append(type + ":");
|
||||
}
|
||||
if (this.name != null) {
|
||||
sb.append(name);
|
||||
//sb.append("[" + timestamp + "]");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodNameInHistory() throws Exception {
|
||||
public void testHistory() throws Exception {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
DirectChannel channel = new DirectChannel();
|
||||
@@ -283,12 +283,13 @@ public class GatewayProxyFactoryBeanTests {
|
||||
MessageHistoryEvent event1 = historyIterator.next();
|
||||
MessageHistoryEvent event2 = historyIterator.next();
|
||||
MessageHistoryEvent event3 = historyIterator.next();
|
||||
assertEquals("echo", event1.getAttribute("method", String.class));
|
||||
assertEquals("testGateway", event1.getComponentName());
|
||||
assertEquals("channel", event2.getComponentType());
|
||||
assertEquals("testChannel", event2.getComponentName());
|
||||
assertEquals("bridge", event3.getComponentType());
|
||||
assertEquals("testBridge", event3.getComponentName());
|
||||
// assertEquals("echo", event1.getAttribute("method", String.class));
|
||||
assertEquals("testGateway", event1.getName());
|
||||
assertEquals("channel", event2.getType());
|
||||
assertEquals("testChannel", event2.getName());
|
||||
assertEquals("bridge", event3.getType());
|
||||
assertEquals("testBridge", event3.getName());
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -321,6 +322,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
|
||||
public static class TestClient {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final TestService service;
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user