1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.monitoring.statistics;
24  
25  import com.liferay.portal.monitoring.RequestStatus;
26  
27  import java.io.Serializable;
28  
29  import java.util.Map;
30  
31  import org.apache.commons.lang.time.StopWatch;
32  
33  /**
34   * <a href="BaseDataSample.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Michael C. Han
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class BaseDataSample implements DataSample, Serializable {
41  
42      public void capture(RequestStatus requestStatus) {
43          if (_stopWatch != null) {
44              _stopWatch.stop();
45  
46              _duration = _stopWatch.getTime();
47          }
48  
49          _requestStatus = requestStatus;
50      }
51  
52      public Map<String, String> getAttributes() {
53          return _attributes;
54      }
55  
56      public long getCompanyId() {
57          return _companyId;
58      }
59  
60      public String getDescription() {
61          return _description;
62      }
63  
64      public long getDuration() {
65          return _duration;
66      }
67  
68      public String getName() {
69          return _name;
70      }
71  
72      public String getNamespace() {
73          return _namespace;
74      }
75  
76      public RequestStatus getRequestStatus() {
77          return _requestStatus;
78      }
79  
80      public String getUser() {
81          return _user;
82      }
83  
84      public void prepare() {
85          if (_stopWatch == null) {
86              _stopWatch = new StopWatch();
87          }
88          _stopWatch.start();
89      }
90  
91      public void setAttributes(Map<String, String> attributes) {
92          _attributes = attributes;
93      }
94  
95      public void setCompanyId(long companyId) {
96          _companyId = companyId;
97      }
98  
99      public void setDescription(String description) {
100         _description = description;
101     }
102 
103     public void setName(String name) {
104         _name = name;
105     }
106 
107     public void setNamespace(String namespace) {
108         _namespace = namespace;
109     }
110 
111     public void setUser(String user) {
112         _user = user;
113     }
114 
115     public String toString() {
116         StringBuilder sb = new StringBuilder();
117 
118         sb.append("{attributes=");
119         sb.append(_attributes);
120         sb.append(", companyId=");
121         sb.append(_companyId);
122         sb.append(", description=");
123         sb.append(_description);
124         sb.append(", duration=");
125         sb.append(_duration);
126         sb.append(", name=");
127         sb.append(_name);
128         sb.append(", namespace=");
129         sb.append(_namespace);
130         sb.append(", requestStatus=");
131         sb.append(_requestStatus);
132         sb.append(", stopWatch=");
133         sb.append(_stopWatch);
134         sb.append(", user=");
135         sb.append(_user);
136         sb.append("}");
137 
138         return sb.toString();
139     }
140 
141     private Map<String, String> _attributes;
142     private long _companyId;
143     private String _description;
144     private long _duration;
145     private String _name;
146     private String _namespace;
147     private RequestStatus _requestStatus;
148     private transient StopWatch _stopWatch;
149     private String _user;
150 
151 }