1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.kernel.messaging;
21  
22  import com.liferay.portal.kernel.util.StackTraceUtil;
23  
24  import java.io.Serializable;
25  
26  /**
27   * <a href="MessageStatus.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Michael C. Han
30   *
31   */
32  public class MessageStatus implements Serializable {
33  
34      public long getDuration() {
35          return _endTime - _startTime;
36      }
37  
38      public String getExceptionMessage() {
39          return _exceptionMessage;
40      }
41  
42      public String getExceptionStackTrace() {
43          return _exceptionStackTrace;
44      }
45  
46      public Object getPayload() {
47          return _payload;
48      }
49  
50      public boolean hasException() {
51          if (_exceptionStackTrace != null) {
52              return true;
53          }
54          else {
55              return false;
56          }
57      }
58  
59      public void setException(Exception e) {
60          _exceptionMessage = e.getMessage();
61          _exceptionStackTrace = StackTraceUtil.getStackTrace(e);
62      }
63  
64      public void setPayload(Object payload) {
65          _payload = payload;
66      }
67  
68      public void startTimer() {
69          _startTime = System.currentTimeMillis();
70      }
71  
72      public void stopTimer() {
73          _endTime = System.currentTimeMillis();
74      }
75  
76      public String toString() {
77          StringBuilder sb = new StringBuilder();
78  
79          sb.append("{startTime=");
80          sb.append(_startTime);
81          sb.append(", endTime=");
82          sb.append(_endTime);
83          sb.append(", payload=");
84          sb.append(_payload);
85          sb.append(", errorMessage=");
86          sb.append(_exceptionMessage);
87          sb.append(", errorStackTrace=");
88          sb.append(_exceptionStackTrace);
89          sb.append("}");
90  
91          return sb.toString();
92      }
93  
94      private long _endTime;
95      private String _exceptionMessage;
96      private String _exceptionStackTrace;
97      private Object _payload;
98      private long _startTime;
99  
100 }