001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.messaging;
016    
017    import com.liferay.portal.kernel.util.StackTraceUtil;
018    import com.liferay.portal.kernel.util.StringBundler;
019    
020    import java.io.Serializable;
021    
022    /**
023     * @author Michael C. Han
024     */
025    public class MessageStatus implements Serializable {
026    
027            public long getDuration() {
028                    return _endTime - _startTime;
029            }
030    
031            public String getExceptionMessage() {
032                    return _exceptionMessage;
033            }
034    
035            public String getExceptionStackTrace() {
036                    return _exceptionStackTrace;
037            }
038    
039            public Object getPayload() {
040                    return _payload;
041            }
042    
043            public boolean hasException() {
044                    if (_exceptionStackTrace != null) {
045                            return true;
046                    }
047                    else {
048                            return false;
049                    }
050            }
051    
052            public void setException(Exception e) {
053                    _exceptionMessage = e.getMessage();
054                    _exceptionStackTrace = StackTraceUtil.getStackTrace(e);
055            }
056    
057            public void setPayload(Object payload) {
058                    _payload = payload;
059            }
060    
061            public void startTimer() {
062                    _startTime = System.currentTimeMillis();
063            }
064    
065            public void stopTimer() {
066                    _endTime = System.currentTimeMillis();
067            }
068    
069            public String toString() {
070                    StringBundler sb = new StringBundler(11);
071    
072                    sb.append("{startTime=");
073                    sb.append(_startTime);
074                    sb.append(", endTime=");
075                    sb.append(_endTime);
076                    sb.append(", payload=");
077                    sb.append(_payload);
078                    sb.append(", errorMessage=");
079                    sb.append(_exceptionMessage);
080                    sb.append(", errorStackTrace=");
081                    sb.append(_exceptionStackTrace);
082                    sb.append("}");
083    
084                    return sb.toString();
085            }
086    
087            private long _endTime;
088            private String _exceptionMessage;
089            private String _exceptionStackTrace;
090            private Object _payload;
091            private long _startTime;
092    
093    }