From 9278dd1f502c1e80014714d44bcca23e55c552d3 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 7 Jan 2008 18:18:58 +0000 Subject: [PATCH] Added default id generator to GenericMessage. --- .../integration/message/GenericMessage.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/message/GenericMessage.java b/spring-integration-core/src/main/java/org/springframework/integration/message/GenericMessage.java index 65cebaeede..24464a3cd9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/message/GenericMessage.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/message/GenericMessage.java @@ -19,6 +19,8 @@ package org.springframework.integration.message; import java.util.concurrent.locks.ReentrantLock; import org.springframework.integration.SystemInterruptedException; +import org.springframework.integration.util.RandomGuidUidGenerator; +import org.springframework.integration.util.UidGenerator; import org.springframework.util.Assert; /** @@ -34,9 +36,17 @@ public class GenericMessage implements Message { private T payload; + private UidGenerator defaultUidGenerator = new RandomGuidUidGenerator(); + private ReentrantLock lock; + /** + * Create a new message with the given id and payload. + * + * @param id unique identifier for this message + * @param payload the message payload + */ public GenericMessage(Object id, T payload) { Assert.notNull(id, "id must not be null"); Assert.notNull(payload, "payload must not be null"); @@ -44,6 +54,19 @@ public class GenericMessage implements Message { this.payload = payload; } + /** + * Create a new message with the given payload. The id will be generated by + * the default {@link UidGenerator} strategy. + * + * @param payload the message payload + */ + public GenericMessage(T payload) { + Assert.notNull(payload, "payload must not be null"); + this.id = this.defaultUidGenerator.generateUid(); + this.payload = payload; + } + + public Object getId() { return this.id; }