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