diff --git a/spring-eai-core/src/main/java/org/springframework/integration/message/AbstractMessage.java b/spring-eai-core/src/main/java/org/springframework/integration/message/AbstractMessage.java
new file mode 100644
index 0000000000..43f5768bcb
--- /dev/null
+++ b/spring-eai-core/src/main/java/org/springframework/integration/message/AbstractMessage.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.message;
+
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.springframework.integration.SystemInterruptedException;
+
+/**
+ * Base Message class defining common properties such as id, header, and lock.
+ *
+ * @author Mark Fisher
+ */
+public abstract class AbstractMessage implements Message {
+
+ private Object id;
+
+ private MessageHeader header = new MessageHeader();
+
+ private ReentrantLock lock;
+
+
+ protected AbstractMessage(Object id) {
+ if (id == null) {
+ throw new IllegalArgumentException("id must not be null");
+ }
+ this.id = id;
+ }
+
+ public Object getId() {
+ return this.id;
+ }
+
+ public MessageHeader getHeader() {
+ return this.header;
+ }
+
+ protected void setHeader(MessageHeader header) {
+ this.header = header;
+ }
+
+ public void lock() {
+ this.lock.lock();
+ }
+
+ public void lockInterruptibly() {
+ try {
+ lock.lockInterruptibly();
+ }
+ catch (InterruptedException e) {
+ throw new SystemInterruptedException("Unable to obtain lock for message", e);
+ }
+ }
+
+ public void unlock() {
+ lock.unlock();
+ }
+
+}
diff --git a/spring-eai-core/src/main/java/org/springframework/integration/message/DocumentMessage.java b/spring-eai-core/src/main/java/org/springframework/integration/message/DocumentMessage.java
index d7290c82d8..219654891a 100644
--- a/spring-eai-core/src/main/java/org/springframework/integration/message/DocumentMessage.java
+++ b/spring-eai-core/src/main/java/org/springframework/integration/message/DocumentMessage.java
@@ -17,28 +17,20 @@
package org.springframework.integration.message;
/**
- * A simple Message implementation that encapsulates
- * a single Object as its payload.
- *
+ * A simple Message implementation that encapsulates a single Object payload.
+ *
* @author Mark Fisher
*/
-public class DocumentMessage implements Message {
-
- private MessageHeader header;
+public class DocumentMessage extends AbstractMessage {
private Object payload;
public DocumentMessage(Object id, Object payload) {
- this.header = new MessageHeader(id);
+ super(id);
this.payload = payload;
}
-
- public MessageHeader getHeader() {
- return this.header;
- }
-
public Object getPayload() {
return this.payload;
}
diff --git a/spring-eai-core/src/main/java/org/springframework/integration/message/Message.java b/spring-eai-core/src/main/java/org/springframework/integration/message/Message.java
index a441aa0777..6614df3ccd 100644
--- a/spring-eai-core/src/main/java/org/springframework/integration/message/Message.java
+++ b/spring-eai-core/src/main/java/org/springframework/integration/message/Message.java
@@ -23,8 +23,14 @@ package org.springframework.integration.message;
*/
public interface Message {
+ Object getId();
+
MessageHeader getHeader();
Object getPayload();
+ void lock();
+
+ void unlock();
+
}
diff --git a/spring-eai-core/src/main/java/org/springframework/integration/message/MessageHeader.java b/spring-eai-core/src/main/java/org/springframework/integration/message/MessageHeader.java
index 66680ea3af..bee2950938 100644
--- a/spring-eai-core/src/main/java/org/springframework/integration/message/MessageHeader.java
+++ b/spring-eai-core/src/main/java/org/springframework/integration/message/MessageHeader.java
@@ -22,19 +22,16 @@ import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
/**
- * A holder for Message metadata. This includes information
- * that is used by the messaging system (such as id
- * and correlationId) as well as information that
- * is relevant for specific messaging endpoints. For the
- * latter, String values may be stored as properties
- * and Object values may be stored as attributes.
+ * A holder for Message metadata. This includes information that is used by the
+ * messaging system (such correlationId) as well as information that is
+ * relevant for specific messaging endpoints. For the latter, String values may
+ * be stored as properties and Object values may be stored as
+ * attributes.
*
* @author Mark Fisher
*/
public class MessageHeader {
- private Object id;
-
private Object correlationId;
private String replyChannelName;
@@ -50,15 +47,6 @@ public class MessageHeader {
private Map attributes = new ConcurrentHashMap();
- public MessageHeader(Object id) {
- this.id = id;
- }
-
-
- public Object getId() {
- return this.id;
- }
-
public Object getCorrelationId() {
return this.correlationId;
}
@@ -80,16 +68,16 @@ public class MessageHeader {
}
/**
- * Set the expiration date for this message or null
- * to indicate 'never expire'. The default is null.
+ * Set the expiration date for this message or null to
+ * indicate 'never expire'. The default is null.
*/
public void setExpiration(Date expiration) {
this.expiration = expiration;
}
/**
- * Return the expiration date for this message or
- * null to indicate 'never expire'.
+ * Return the expiration date for this message or null to
+ * indicate 'never expire'.
*/
public Date getExpiration() {
return this.expiration;