1
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
39 public class BaseDataSample implements DataSample, Serializable {
40
41 public void capture(RequestStatus requestStatus) {
42 if (_stopWatch != null) {
43 _stopWatch.stop();
44
45 _duration = _stopWatch.getTime();
46 }
47
48 _requestStatus = requestStatus;
49 }
50
51 public Map<String, String> getAttributes() {
52 return _attributes;
53 }
54
55 public long getCompanyId() {
56 return _companyId;
57 }
58
59 public String getDescription() {
60 return _description;
61 }
62
63 public long getDuration() {
64 return _duration;
65 }
66
67 public String getName() {
68 return _name;
69 }
70
71 public String getNamespace() {
72 return _namespace;
73 }
74
75 public RequestStatus getRequestStatus() {
76 return _requestStatus;
77 }
78
79 public String getUser() {
80 return _user;
81 }
82
83 public void prepare() {
84 if (_stopWatch == null) {
85 _stopWatch = new StopWatch();
86 }
87 _stopWatch.start();
88 }
89
90 public void setAttributes(Map<String, String> attributes) {
91 _attributes = attributes;
92 }
93
94 public void setCompanyId(long companyId) {
95 _companyId = companyId;
96 }
97
98 public void setDescription(String description) {
99 _description = description;
100 }
101
102 public void setName(String name) {
103 _name = name;
104 }
105
106 public void setNamespace(String namespace) {
107 _namespace = namespace;
108 }
109
110 public void setUser(String user) {
111 _user = user;
112 }
113
114 public String toString() {
115 StringBuilder sb = new StringBuilder();
116
117 sb.append("{attributes=");
118 sb.append(_attributes);
119 sb.append(", companyId=");
120 sb.append(_companyId);
121 sb.append(", description=");
122 sb.append(_description);
123 sb.append(", duration=");
124 sb.append(_duration);
125 sb.append(", name=");
126 sb.append(_name);
127 sb.append(", namespace=");
128 sb.append(_namespace);
129 sb.append(", requestStatus=");
130 sb.append(_requestStatus);
131 sb.append(", stopWatch=");
132 sb.append(_stopWatch);
133 sb.append(", user=");
134 sb.append(_user);
135 sb.append("}");
136
137 return sb.toString();
138 }
139
140 private Map<String, String> _attributes;
141 private long _companyId;
142 private String _description;
143 private long _duration;
144 private String _name;
145 private String _namespace;
146 private RequestStatus _requestStatus;
147 private transient StopWatch _stopWatch;
148 private String _user;
149
150 }