Mercurial > hg > blitz_condensed
comparison src/com/go/trove/util/tq/TransactionQueueData.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 /* ==================================================================== | |
2 * Trove - Copyright (c) 1997-2000 Walt Disney Internet Group | |
3 * ==================================================================== | |
4 * The Tea Software License, Version 1.1 | |
5 * | |
6 * Copyright (c) 2000 Walt Disney Internet Group. All rights reserved. | |
7 * | |
8 * Redistribution and use in source and binary forms, with or without | |
9 * modification, are permitted provided that the following conditions | |
10 * are met: | |
11 * | |
12 * 1. Redistributions of source code must retain the above copyright | |
13 * notice, this list of conditions and the following disclaimer. | |
14 * | |
15 * 2. Redistributions in binary form must reproduce the above copyright | |
16 * notice, this list of conditions and the following disclaimer in | |
17 * the documentation and/or other materials provided with the | |
18 * distribution. | |
19 * | |
20 * 3. The end-user documentation included with the redistribution, | |
21 * if any, must include the following acknowledgment: | |
22 * "This product includes software developed by the | |
23 * Walt Disney Internet Group (http://opensource.go.com/)." | |
24 * Alternately, this acknowledgment may appear in the software itself, | |
25 * if and wherever such third-party acknowledgments normally appear. | |
26 * | |
27 * 4. The names "Tea", "TeaServlet", "Kettle", "Trove" and "BeanDoc" must | |
28 * not be used to endorse or promote products derived from this | |
29 * software without prior written permission. For written | |
30 * permission, please contact opensource@dig.com. | |
31 * | |
32 * 5. Products derived from this software may not be called "Tea", | |
33 * "TeaServlet", "Kettle" or "Trove", nor may "Tea", "TeaServlet", | |
34 * "Kettle", "Trove" or "BeanDoc" appear in their name, without prior | |
35 * written permission of the Walt Disney Internet Group. | |
36 * | |
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
40 * DISCLAIMED. IN NO EVENT SHALL THE WALT DISNEY INTERNET GROUP OR ITS | |
41 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
42 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
43 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
44 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
45 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
48 * ==================================================================== | |
49 * | |
50 * For more information about Tea, please see http://opensource.go.com/. | |
51 */ | |
52 | |
53 package com.go.trove.util.tq; | |
54 | |
55 import java.util.Date; | |
56 | |
57 /****************************************************************************** | |
58 * This class contains a snapshot of data from a {@link TransactionQueue}. | |
59 * | |
60 * @author Brian S O'Neill | |
61 * @version | |
62 * <!--$$Revision: 1.1 $-->, <!--$$JustDate:--> 01/03/13 <!-- $--> | |
63 */ | |
64 public class TransactionQueueData implements java.io.Serializable { | |
65 private transient final TransactionQueue mTransactionQueue; | |
66 | |
67 private final long mSnapshotStart; | |
68 private final long mSnapshotEnd; | |
69 private final int mQueueSize; | |
70 private final int mThreadCount; | |
71 private final int mServicingCount; | |
72 private final int mPeakQueueSize; | |
73 private final int mPeakThreadCount; | |
74 private final int mPeakServicingCount; | |
75 private final int mTotalEnqueueAttempts; | |
76 private final int mTotalEnqueued; | |
77 private final int mTotalServiced; | |
78 private final int mTotalExpired; | |
79 private final int mTotalServiceExceptions; | |
80 private final int mTotalUncaughtExceptions; | |
81 private final long mTotalQueueDuration; | |
82 private final long mTotalServiceDuration; | |
83 | |
84 private transient Date mStartDate; | |
85 private transient Date mEndDate; | |
86 | |
87 TransactionQueueData(TransactionQueue tq, | |
88 long snapshotStart, | |
89 long snapshotEnd, | |
90 int queueSize, | |
91 int threadCount, | |
92 int servicingCount, | |
93 int peakQueueSize, | |
94 int peakThreadCount, | |
95 int peakServicingCount, | |
96 int totalEnqueueAttempts, | |
97 int totalEnqueued, | |
98 int totalServiced, | |
99 int totalExpired, | |
100 int totalServiceExceptions, | |
101 int totalUncaughtExceptions, | |
102 long totalQueueDuration, | |
103 long totalServiceDuration) { | |
104 | |
105 mTransactionQueue = tq; | |
106 mSnapshotStart = snapshotStart; | |
107 mSnapshotEnd = snapshotEnd; | |
108 mQueueSize = queueSize; | |
109 mThreadCount = threadCount; | |
110 mServicingCount = servicingCount; | |
111 mPeakQueueSize = peakQueueSize; | |
112 mPeakThreadCount = peakThreadCount; | |
113 mPeakServicingCount = peakServicingCount; | |
114 mTotalEnqueueAttempts = totalEnqueueAttempts; | |
115 mTotalEnqueued = totalEnqueued; | |
116 mTotalServiced = totalServiced; | |
117 mTotalExpired = totalExpired; | |
118 mTotalServiceExceptions = totalServiceExceptions; | |
119 mTotalUncaughtExceptions = totalUncaughtExceptions; | |
120 mTotalQueueDuration = totalQueueDuration; | |
121 mTotalServiceDuration = totalServiceDuration; | |
122 } | |
123 | |
124 /** | |
125 * Adds TransactionQueueData to another. | |
126 */ | |
127 public TransactionQueueData add(TransactionQueueData data) { | |
128 return new TransactionQueueData | |
129 (null, | |
130 Math.min(mSnapshotStart, data.mSnapshotStart), | |
131 Math.max(mSnapshotEnd, data.mSnapshotEnd), | |
132 mQueueSize + data.mQueueSize, | |
133 mThreadCount + data.mThreadCount, | |
134 mServicingCount + data.mServicingCount, | |
135 Math.max(mPeakQueueSize, data.mPeakQueueSize), | |
136 Math.max(mPeakThreadCount, data.mPeakThreadCount), | |
137 Math.max(mPeakServicingCount, data.mPeakServicingCount), | |
138 mTotalEnqueueAttempts + data.mTotalEnqueueAttempts, | |
139 mTotalEnqueued + data.mTotalEnqueued, | |
140 mTotalServiced + data.mTotalServiced, | |
141 mTotalExpired + data.mTotalExpired, | |
142 mTotalServiceExceptions + data.mTotalServiceExceptions, | |
143 mTotalUncaughtExceptions + data.mTotalUncaughtExceptions, | |
144 mTotalQueueDuration + data.mTotalQueueDuration, | |
145 mTotalServiceDuration + data.mTotalServiceDuration | |
146 ); | |
147 } | |
148 | |
149 /** | |
150 * Returns the TransactionQueue source of this data, or null if not | |
151 * applicable or missing. | |
152 */ | |
153 public TransactionQueue getTransactionQueue() { | |
154 return mTransactionQueue; | |
155 } | |
156 | |
157 /** | |
158 * Returns the date/time for when the snapshot started. | |
159 */ | |
160 public Date getSnapshotStart() { | |
161 if (mStartDate == null) { | |
162 mStartDate = new Date(mSnapshotStart); | |
163 } | |
164 return mStartDate; | |
165 } | |
166 | |
167 /** | |
168 * Returns the date/time for when the snapshot ended. | |
169 */ | |
170 public Date getSnapshotEnd() { | |
171 if (mEndDate == null) { | |
172 mEndDate = new Date(mSnapshotEnd); | |
173 } | |
174 return mEndDate; | |
175 } | |
176 | |
177 /** | |
178 * Returns the number of queued transactions at the snapshot end. | |
179 */ | |
180 public int getQueueSize() { | |
181 return mQueueSize; | |
182 } | |
183 | |
184 /** | |
185 * Returns the amount of worker threads in this TransactionQueue at the | |
186 * snapshot end. | |
187 */ | |
188 public int getThreadCount() { | |
189 return mThreadCount; | |
190 } | |
191 | |
192 /** | |
193 * Returns the amount of transactions currently being serviced at the | |
194 * snapshot end. | |
195 */ | |
196 public int getServicingCount() { | |
197 return mServicingCount; | |
198 } | |
199 | |
200 /** | |
201 * Returns the biggest queue size over the snapshot interval. | |
202 */ | |
203 public int getPeakQueueSize() { | |
204 return mPeakQueueSize; | |
205 } | |
206 | |
207 /** | |
208 * Returns the highest thread count over the snapshot interval. | |
209 */ | |
210 public int getPeakThreadCount() { | |
211 return mPeakThreadCount; | |
212 } | |
213 | |
214 /** | |
215 * Returns the highest servicing count over the snapshot interval. | |
216 */ | |
217 public int getPeakServicingCount() { | |
218 return mPeakServicingCount; | |
219 } | |
220 | |
221 /** | |
222 * Returns the total amount of transactions that were attempted to be | |
223 * enqueued over the snapshot interval. | |
224 */ | |
225 public int getTotalEnqueueAttempts() { | |
226 return mTotalEnqueueAttempts; | |
227 } | |
228 | |
229 /** | |
230 * Returns the total amount of transactions that were enqueued over the | |
231 * snapshot interval. | |
232 */ | |
233 public int getTotalEnqueued() { | |
234 return mTotalEnqueued; | |
235 } | |
236 | |
237 /** | |
238 * Returns the total amount of transactions serviced over the snapshot | |
239 * interval. | |
240 */ | |
241 public int getTotalServiced() { | |
242 return mTotalServiced; | |
243 } | |
244 | |
245 /** | |
246 * Returns the total amount of expired transactions over the snapshot | |
247 * interval. | |
248 */ | |
249 public int getTotalExpired() { | |
250 return mTotalExpired; | |
251 } | |
252 | |
253 /** | |
254 * Returns the number of transactions that were canceled because of an | |
255 * uncaught exception while being serviced. | |
256 */ | |
257 public int getTotalServiceExceptions() { | |
258 return mTotalServiceExceptions; | |
259 } | |
260 | |
261 /** | |
262 * Returns the total number of uncaught exceptions in the TransactionQueue. | |
263 * This value is usually the same as the total number of service | |
264 * exceptions. If it is larger, this does necessarily not indicate that the | |
265 * TransactionQueue has an internal error because exceptions can be | |
266 * generated while attempting to cancel a transaction. | |
267 */ | |
268 public int getTotalUncaughtExceptions() { | |
269 return mTotalUncaughtExceptions; | |
270 } | |
271 | |
272 /** | |
273 * Returns the total time, in milliseconds, that transactions were | |
274 * waiting in the queue. | |
275 */ | |
276 public long getTotalQueueDuration() { | |
277 return mTotalQueueDuration; | |
278 } | |
279 | |
280 /** | |
281 * Returns the total time, in milliseconds, that transactions were being | |
282 * serviced. | |
283 */ | |
284 public long getTotalServiceDuration() { | |
285 return mTotalServiceDuration; | |
286 } | |
287 | |
288 // Calculated data. | |
289 | |
290 /** | |
291 * Returns the length of the snapshot interval in milliseconds. | |
292 */ | |
293 public long getSnapshotDuration() { | |
294 return mSnapshotEnd - mSnapshotStart; | |
295 } | |
296 | |
297 /** | |
298 * Returns the total amount of enqueue attempts that failed because the | |
299 * queue was full. | |
300 */ | |
301 public int getTotalEnqueueFailures() { | |
302 return mTotalEnqueueAttempts - mTotalEnqueued; | |
303 } | |
304 | |
305 /** | |
306 * Returns the total amount of transactions that weren't serviced because | |
307 * the queue was full, the transaction expired, or an exception was thrown. | |
308 */ | |
309 public int getTotalUnserviced() { | |
310 return getTotalEnqueueFailures() + | |
311 mTotalExpired + mTotalServiceExceptions; | |
312 } | |
313 | |
314 /** | |
315 * Returns the average amount of time, in milliseconds, that a | |
316 * transaction was in the queue. | |
317 */ | |
318 public double getAverageQueueDuration() { | |
319 return ((double)getTotalQueueDuration()) / | |
320 ((double)getTotalEnqueued()); | |
321 } | |
322 | |
323 /** | |
324 * Returns the average amount of time, in milliseconds, it took servicing | |
325 * a transaction. | |
326 */ | |
327 public double getAverageServiceDuration() { | |
328 return ((double)getTotalServiceDuration()) / | |
329 ((double)getTotalServiced()); | |
330 } | |
331 | |
332 /** | |
333 * Returns the amount of enqueue attempts per second over the snapshot | |
334 * interval. | |
335 */ | |
336 public double getEnqueueAttemptRate() { | |
337 return ((double)getTotalEnqueueAttempts() * 1000) / | |
338 ((double)getSnapshotDuration()); | |
339 } | |
340 | |
341 /** | |
342 * Returns the amount of successful transaction enqueues per second over | |
343 * the snapshot interval. | |
344 */ | |
345 public double getEnqueueSuccessRate() { | |
346 return ((double)getTotalEnqueued() * 1000) / | |
347 ((double)getSnapshotDuration()); | |
348 } | |
349 | |
350 /** | |
351 * Returns the amount of transactions serviced per second over the | |
352 * snapshot interval. | |
353 */ | |
354 public double getServiceRate() { | |
355 return ((double)getTotalServiced() * 1000) / | |
356 ((double)getSnapshotDuration()); | |
357 } | |
358 | |
359 /** | |
360 * Returns zero if no enqueues failed, one if all enqueues failed, or | |
361 * a number in between if some failed. | |
362 */ | |
363 public double getEnqueueFailureRatio() { | |
364 return 1.0d - ((double)getTotalEnqueued()) / | |
365 ((double)getTotalEnqueueAttempts()); | |
366 } | |
367 } |