1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.messaging;
16  
17  import com.liferay.portal.kernel.util.StackTraceUtil;
18  import com.liferay.portal.kernel.util.StringBundler;
19  
20  import java.io.Serializable;
21  
22  /**
23   * <a href="MessageStatus.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Michael C. Han
26   */
27  public class MessageStatus implements Serializable {
28  
29      public long getDuration() {
30          return _endTime - _startTime;
31      }
32  
33      public String getExceptionMessage() {
34          return _exceptionMessage;
35      }
36  
37      public String getExceptionStackTrace() {
38          return _exceptionStackTrace;
39      }
40  
41      public Object getPayload() {
42          return _payload;
43      }
44  
45      public boolean hasException() {
46          if (_exceptionStackTrace != null) {
47              return true;
48          }
49          else {
50              return false;
51          }
52      }
53  
54      public void setException(Exception e) {
55          _exceptionMessage = e.getMessage();
56          _exceptionStackTrace = StackTraceUtil.getStackTrace(e);
57      }
58  
59      public void setPayload(Object payload) {
60          _payload = payload;
61      }
62  
63      public void startTimer() {
64          _startTime = System.currentTimeMillis();
65      }
66  
67      public void stopTimer() {
68          _endTime = System.currentTimeMillis();
69      }
70  
71      public String toString() {
72          StringBundler sb = new StringBundler(11);
73  
74          sb.append("{startTime=");
75          sb.append(_startTime);
76          sb.append(", endTime=");
77          sb.append(_endTime);
78          sb.append(", payload=");
79          sb.append(_payload);
80          sb.append(", errorMessage=");
81          sb.append(_exceptionMessage);
82          sb.append(", errorStackTrace=");
83          sb.append(_exceptionStackTrace);
84          sb.append("}");
85  
86          return sb.toString();
87      }
88  
89      private long _endTime;
90      private String _exceptionMessage;
91      private String _exceptionStackTrace;
92      private Object _payload;
93      private long _startTime;
94  
95  }