Added CompositeMessage and added the 'nextTarget' header to MessageHeaders (and the corresponding methods in MessageBuilder).

This commit is contained in:
Mark Fisher
2008-08-08 21:30:49 +00:00
parent e88776463a
commit a7acc62371
3 changed files with 62 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2002-2008 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.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* @author Mark Fisher
*/
public class CompositeMessage extends GenericMessage<List<Message<?>>> implements Iterable<Message<?>> {
public CompositeMessage(Message<?>[] messages) {
this(Arrays.asList(messages));
}
public CompositeMessage(List<Message<?>> messages) {
super(Collections.unmodifiableList(messages));
}
public Iterator<Message<?>> iterator() {
return this.getPayload().iterator();
}
}

View File

@@ -111,7 +111,19 @@ public final class MessageBuilder<T> {
return this.setHeader(MessageHeaders.CORRELATION_ID, correlationId);
}
public MessageBuilder<T> setReturnAddress(Object returnAddress) {
public MessageBuilder<T> setNextTarget(MessageTarget nextTarget) {
return this.setHeader(MessageHeaders.NEXT_TARGET, nextTarget);
}
public MessageBuilder<T> setNextTarget(String nextTarget) {
return this.setHeader(MessageHeaders.NEXT_TARGET, nextTarget);
}
public MessageBuilder<T> setReturnAddress(MessageTarget returnAddress) {
return this.setHeader(MessageHeaders.RETURN_ADDRESS, returnAddress);
}
public MessageBuilder<T> setReturnAddress(String returnAddress) {
return this.setHeader(MessageHeaders.RETURN_ADDRESS, returnAddress);
}

View File

@@ -36,6 +36,8 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
public static final String CORRELATION_ID = "internal.header.correlationId";
public static final String NEXT_TARGET = "internal.header.nextTarget";
public static final String RETURN_ADDRESS = "internal.header.returnAddress";
public static final String EXPIRATION_DATE = "internal.header.exprirationDate";
@@ -72,6 +74,10 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
return this.get(RETURN_ADDRESS);
}
public Object getNextTarget() {
return this.get(NEXT_TARGET);
}
public Integer getSequenceNumber() {
Integer sequenceNumber = this.get(SEQUENCE_NUMBER, Integer.class);
return (sequenceNumber != null ? sequenceNumber : 0);