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.monitoring.statistics;
16  
17  import com.liferay.portal.kernel.util.StringBundler;
18  import com.liferay.portal.monitoring.RequestStatus;
19  
20  import java.io.Serializable;
21  
22  import java.util.Map;
23  
24  import org.apache.commons.lang.time.StopWatch;
25  
26  /**
27   * <a href="BaseDataSample.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Michael C. Han
30   * @author Brian Wing Shun Chan
31   */
32  public class BaseDataSample implements DataSample, Serializable {
33  
34      public void capture(RequestStatus requestStatus) {
35          if (_stopWatch != null) {
36              _stopWatch.stop();
37  
38              _duration = _stopWatch.getTime();
39          }
40  
41          _requestStatus = requestStatus;
42      }
43  
44      public Map<String, String> getAttributes() {
45          return _attributes;
46      }
47  
48      public long getCompanyId() {
49          return _companyId;
50      }
51  
52      public String getDescription() {
53          return _description;
54      }
55  
56      public long getDuration() {
57          return _duration;
58      }
59  
60      public String getName() {
61          return _name;
62      }
63  
64      public String getNamespace() {
65          return _namespace;
66      }
67  
68      public RequestStatus getRequestStatus() {
69          return _requestStatus;
70      }
71  
72      public String getUser() {
73          return _user;
74      }
75  
76      public void prepare() {
77          if (_stopWatch == null) {
78              _stopWatch = new StopWatch();
79          }
80          _stopWatch.start();
81      }
82  
83      public void setAttributes(Map<String, String> attributes) {
84          _attributes = attributes;
85      }
86  
87      public void setCompanyId(long companyId) {
88          _companyId = companyId;
89      }
90  
91      public void setDescription(String description) {
92          _description = description;
93      }
94  
95      public void setName(String name) {
96          _name = name;
97      }
98  
99      public void setNamespace(String namespace) {
100         _namespace = namespace;
101     }
102 
103     public void setUser(String user) {
104         _user = user;
105     }
106 
107     public String toString() {
108         StringBundler sb = new StringBundler(19);
109 
110         sb.append("{attributes=");
111         sb.append(_attributes);
112         sb.append(", companyId=");
113         sb.append(_companyId);
114         sb.append(", description=");
115         sb.append(_description);
116         sb.append(", duration=");
117         sb.append(_duration);
118         sb.append(", name=");
119         sb.append(_name);
120         sb.append(", namespace=");
121         sb.append(_namespace);
122         sb.append(", requestStatus=");
123         sb.append(_requestStatus);
124         sb.append(", stopWatch=");
125         sb.append(_stopWatch);
126         sb.append(", user=");
127         sb.append(_user);
128         sb.append("}");
129 
130         return sb.toString();
131     }
132 
133     private Map<String, String> _attributes;
134     private long _companyId;
135     private String _description;
136     private long _duration;
137     private String _name;
138     private String _namespace;
139     private RequestStatus _requestStatus;
140     private transient StopWatch _stopWatch;
141     private String _user;
142 
143 }