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
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 }