001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package flex.messaging.messages;
022
023 import java.util.HashMap;
024
025 /**
026 * @author Franck WOLFF
027 */
028 public class AsyncMessage extends AbstractMessage {
029
030 private static final long serialVersionUID = 1L;
031
032 public static final String SUBTOPIC_HEADER = "DSSubtopic";
033 public static final String DESTINATION_CLIENT_ID_HEADER = "DSDstClientId";
034
035 private String correlationId;
036
037 public AsyncMessage() {
038 super();
039
040 setHeaders(new HashMap<String, Object>());
041 }
042
043 public AsyncMessage(Message request) {
044 this(request, false);
045 }
046
047 public AsyncMessage(Message request, boolean keepClientId) {
048 super(request, keepClientId);
049
050 setHeaders(new HashMap<String, Object>());
051 this.correlationId = request.getMessageId();
052 }
053
054 public String getCorrelationId() {
055 return correlationId;
056 }
057
058 public void setCorrelationId(String correlationId) {
059 this.correlationId = correlationId;
060 }
061
062 @Override
063 public AsyncMessage clone() {
064 AsyncMessage msg = new AsyncMessage();
065 msg.setBody(getBody());
066 msg.setClientId(getClientId());
067 msg.setCorrelationId(getCorrelationId());
068 msg.setDestination(getDestination());
069 msg.setMessageId(getMessageId());
070 msg.setHeaders(new HashMap<String, Object>(getHeaders()));
071 msg.setTimestamp(getTimestamp());
072 msg.setTimeToLive(getTimeToLive());
073 return msg;
074 }
075
076 @Override
077 public String toString() {
078 return toString("");
079 }
080
081 public String toString(String indent) {
082 StringBuilder sb = new StringBuilder(512);
083 sb.append(getClass().getName()).append(" {");
084 toString(sb, indent, null);
085 sb.append('\n').append(indent).append('}');
086 return sb.toString();
087 }
088
089 @Override
090 protected void toString(StringBuilder sb, String indent, String bodyMessage) {
091 sb.append('\n').append(indent).append(" correlationId = ").append(correlationId);
092 super.toString(sb, indent, bodyMessage);
093 }
094 }