1 6 package org.logicalcobwebs.proxool.admin; 7 8 import java.util.Date ; 9 10 18 class Statistics implements StatisticsIF { 19 20 private Date startDate; 21 22 private Date stopDate; 23 24 private long servedCount; 25 26 private long refusedCount; 27 28 private long totalActiveTime; 29 30 33 protected Statistics(Date startDate) { 34 this.startDate = startDate; 35 } 36 37 40 protected void connectionReturned(long activeTime) { 41 totalActiveTime += activeTime; 42 servedCount++; 43 } 44 45 48 protected void connectionRefused() { 49 refusedCount++; 50 } 51 52 55 protected void setStopDate(Date stopDate) { 56 this.stopDate = stopDate; 57 } 58 59 62 public Date getStartDate() { 63 return startDate; 64 } 65 66 69 public Date getStopDate() { 70 return stopDate; 71 } 72 73 76 public long getPeriod() { 77 if (stopDate != null) { 78 return stopDate.getTime() - startDate.getTime(); 79 } else { 80 return System.currentTimeMillis() - startDate.getTime(); 81 } 82 } 83 84 87 public double getAverageActiveTime() { 88 if (servedCount > 0) { 89 return ((double) totalActiveTime / (double) servedCount); 90 } else { 91 return 0.0; 92 } 93 } 94 95 98 public double getAverageActiveCount() { 99 return (double) totalActiveTime / (double) getPeriod(); 100 } 101 102 105 public double getServedPerSecond() { 106 return (double) servedCount / ((double) getPeriod() / 1000.0); 107 } 108 109 112 public double getRefusedPerSecond() { 113 return (double) refusedCount / ((double) getPeriod() / 1000.0); 114 } 115 116 119 public long getServedCount() { 120 return servedCount; 121 } 122 123 126 public long getRefusedCount() { 127 return refusedCount; 128 } 129 130 } 131 132 133 | Popular Tags |