1 52 53 package com.go.trove.util.tq; 54 55 import java.util.Date ; 56 57 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 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 153 public TransactionQueue getTransactionQueue() { 154 return mTransactionQueue; 155 } 156 157 160 public Date getSnapshotStart() { 161 if (mStartDate == null) { 162 mStartDate = new Date (mSnapshotStart); 163 } 164 return mStartDate; 165 } 166 167 170 public Date getSnapshotEnd() { 171 if (mEndDate == null) { 172 mEndDate = new Date (mSnapshotEnd); 173 } 174 return mEndDate; 175 } 176 177 180 public int getQueueSize() { 181 return mQueueSize; 182 } 183 184 188 public int getThreadCount() { 189 return mThreadCount; 190 } 191 192 196 public int getServicingCount() { 197 return mServicingCount; 198 } 199 200 203 public int getPeakQueueSize() { 204 return mPeakQueueSize; 205 } 206 207 210 public int getPeakThreadCount() { 211 return mPeakThreadCount; 212 } 213 214 217 public int getPeakServicingCount() { 218 return mPeakServicingCount; 219 } 220 221 225 public int getTotalEnqueueAttempts() { 226 return mTotalEnqueueAttempts; 227 } 228 229 233 public int getTotalEnqueued() { 234 return mTotalEnqueued; 235 } 236 237 241 public int getTotalServiced() { 242 return mTotalServiced; 243 } 244 245 249 public int getTotalExpired() { 250 return mTotalExpired; 251 } 252 253 257 public int getTotalServiceExceptions() { 258 return mTotalServiceExceptions; 259 } 260 261 268 public int getTotalUncaughtExceptions() { 269 return mTotalUncaughtExceptions; 270 } 271 272 276 public long getTotalQueueDuration() { 277 return mTotalQueueDuration; 278 } 279 280 284 public long getTotalServiceDuration() { 285 return mTotalServiceDuration; 286 } 287 288 290 293 public long getSnapshotDuration() { 294 return mSnapshotEnd - mSnapshotStart; 295 } 296 297 301 public int getTotalEnqueueFailures() { 302 return mTotalEnqueueAttempts - mTotalEnqueued; 303 } 304 305 309 public int getTotalUnserviced() { 310 return getTotalEnqueueFailures() + 311 mTotalExpired + mTotalServiceExceptions; 312 } 313 314 318 public double getAverageQueueDuration() { 319 return ((double)getTotalQueueDuration()) / 320 ((double)getTotalEnqueued()); 321 } 322 323 327 public double getAverageServiceDuration() { 328 return ((double)getTotalServiceDuration()) / 329 ((double)getTotalServiced()); 330 } 331 332 336 public double getEnqueueAttemptRate() { 337 return ((double)getTotalEnqueueAttempts() * 1000) / 338 ((double)getSnapshotDuration()); 339 } 340 341 345 public double getEnqueueSuccessRate() { 346 return ((double)getTotalEnqueued() * 1000) / 347 ((double)getSnapshotDuration()); 348 } 349 350 354 public double getServiceRate() { 355 return ((double)getTotalServiced() * 1000) / 356 ((double)getSnapshotDuration()); 357 } 358 359 363 public double getEnqueueFailureRatio() { 364 return 1.0d - ((double)getTotalEnqueued()) / 365 ((double)getTotalEnqueueAttempts()); 366 } 367 } 368 | Popular Tags |