|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -42,6 +42,7 @@ import org.springframework.util.IdGenerator; |
|
|
|
* <b>IMPORTANT</b>: This class is immutable. Any mutating operation such as |
|
|
|
* <b>IMPORTANT</b>: This class is immutable. Any mutating operation such as |
|
|
|
* {@code put(..)}, {@code putAll(..)} and others will throw |
|
|
|
* {@code put(..)}, {@code putAll(..)} and others will throw |
|
|
|
* {@link UnsupportedOperationException}. |
|
|
|
* {@link UnsupportedOperationException}. |
|
|
|
|
|
|
|
* <p>Subclasses do have access to the raw headers, however, via {@link #getRawHeaders()}. |
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* One way to create message headers is to use the |
|
|
|
* One way to create message headers is to use the |
|
|
|
* {@link org.springframework.messaging.support.MessageBuilder MessageBuilder}: |
|
|
|
* {@link org.springframework.messaging.support.MessageBuilder MessageBuilder}: |
|
|
|
@ -66,7 +67,7 @@ import org.springframework.util.IdGenerator; |
|
|
|
* @see org.springframework.messaging.support.MessageBuilder |
|
|
|
* @see org.springframework.messaging.support.MessageBuilder |
|
|
|
* @see org.springframework.messaging.support.MessageHeaderAccessor |
|
|
|
* @see org.springframework.messaging.support.MessageHeaderAccessor |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public final class MessageHeaders implements Map<String, Object>, Serializable { |
|
|
|
public class MessageHeaders implements Map<String, Object>, Serializable { |
|
|
|
|
|
|
|
|
|
|
|
private static final long serialVersionUID = -4615750558355702881L; |
|
|
|
private static final long serialVersionUID = -4615750558355702881L; |
|
|
|
|
|
|
|
|
|
|
|
@ -95,13 +96,27 @@ public final class MessageHeaders implements Map<String, Object>, Serializable { |
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, Object> headers; |
|
|
|
private final Map<String, Object> headers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Constructs a minimal {@link MessageHeaders} with zero headers. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected MessageHeaders() { |
|
|
|
|
|
|
|
this.headers = new HashMap<String, Object>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Consructs a {@link MessageHeaders} from the headers map; adding (or |
|
|
|
|
|
|
|
* overwriting) the {@link #ID} and {@link #TIMESTAMP} headers. |
|
|
|
|
|
|
|
* @param headers The map. |
|
|
|
|
|
|
|
*/ |
|
|
|
public MessageHeaders(Map<String, Object> headers) { |
|
|
|
public MessageHeaders(Map<String, Object> headers) { |
|
|
|
this.headers = (headers != null) ? new HashMap<String, Object>(headers) : new HashMap<String, Object>(); |
|
|
|
this.headers = (headers != null) ? new HashMap<String, Object>(headers) : new HashMap<String, Object>(); |
|
|
|
this.headers.put(ID, ((idGenerator != null) ? idGenerator : defaultIdGenerator).generateId()); |
|
|
|
this.headers.put(ID, ((idGenerator != null) ? idGenerator : defaultIdGenerator).generateId()); |
|
|
|
this.headers.put(TIMESTAMP, System.currentTimeMillis()); |
|
|
|
this.headers.put(TIMESTAMP, System.currentTimeMillis()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected Map<String, Object> getRawHeaders() { |
|
|
|
|
|
|
|
return this.headers; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public UUID getId() { |
|
|
|
public UUID getId() { |
|
|
|
return this.get(ID, UUID.class); |
|
|
|
return this.get(ID, UUID.class); |
|
|
|
|