Moved 'id' to the Message instead of MessageHeader

This commit is contained in:
Mark Fisher
2007-12-02 16:30:31 +00:00
parent 8b6d97f8e0
commit fa9be80d0e
4 changed files with 92 additions and 33 deletions

View File

@@ -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();
}
}

View File

@@ -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;
}

View File

@@ -23,8 +23,14 @@ package org.springframework.integration.message;
*/
public interface Message {
Object getId();
MessageHeader getHeader();
Object getPayload();
void lock();
void unlock();
}

View File

@@ -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 <i>id</i>
* and <i>correlationId</i>) as well as information that
* is relevant for specific messaging endpoints. For the
* latter, String values may be stored as <i>properties</i>
* and Object values may be stored as <i>attributes</i>.
* A holder for Message metadata. This includes information that is used by the
* messaging system (such <i>correlationId</i>) as well as information that is
* relevant for specific messaging endpoints. For the latter, String values may
* be stored as <i>properties</i> and Object values may be stored as
* <i>attributes</i>.
*
* @author Mark Fisher
*/
public class MessageHeader {
private Object id;
private Object correlationId;
private String replyChannelName;
@@ -50,15 +47,6 @@ public class MessageHeader {
private Map<String, Object> attributes = new ConcurrentHashMap<String, Object>();
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 <code>null</code>
* to indicate 'never expire'. The default is <code>null</code>.
* Set the expiration date for this message or <code>null</code> to
* indicate 'never expire'. The default is <code>null</code>.
*/
public void setExpiration(Date expiration) {
this.expiration = expiration;
}
/**
* Return the expiration date for this message or
* <code>null</code> to indicate 'never expire'.
* Return the expiration date for this message or <code>null</code> to
* indicate 'never expire'.
*/
public Date getExpiration() {
return this.expiration;