1 14 package org.wings.session; 15 16 import java.text.DateFormat ; 17 import java.util.Date ; 18 19 23 public class WingsStatistics { 24 25 private static final WingsStatistics STATISTICS = new WingsStatistics(); 26 27 public static final WingsStatistics getStatistics() { 28 return STATISTICS; 29 } 30 31 private int sessionCounter = 0; 32 private int activeSessionCounter = 0; 33 private int allocatedSessionCounter = 0; 34 private final long birthDay = System.currentTimeMillis(); 35 36 private int requestCounter = 0; 37 private long requestDuration = 0; 38 39 40 public final int getRequestCount() { 41 return requestCounter; 42 } 43 44 public final long getRequestDuration() { 45 return requestDuration; 46 } 47 48 public final long getUptime() { 49 return System.currentTimeMillis() - birthDay; 50 } 51 52 synchronized final void incrementRequestCount(long duration) { 53 requestCounter++; 54 requestDuration += duration; 55 } 56 57 synchronized final void incrementSessionCount() { 58 sessionCounter++; 59 } 60 61 synchronized final void incrementActiveSessionCount() { 62 activeSessionCounter++; 63 } 64 65 synchronized final void incrementAllocatedSessionCount() { 66 allocatedSessionCounter++; 67 } 68 69 synchronized final void decrementActiveSessionCount() { 70 activeSessionCounter--; 71 } 72 73 synchronized final void decrementAllocatedSessionCount() { 74 allocatedSessionCounter--; 75 } 76 77 78 public final int getOverallSessionCount() { 79 return sessionCounter; 80 } 81 82 public final int getActiveSessionCount() { 83 return activeSessionCounter; 84 } 85 86 public final int getAllocatedSessionCount() { 87 return allocatedSessionCounter; 88 } 89 90 91 private int dispatchCounter = 0; 92 private long dispatchDuration = 0; 93 94 private int deliverCounter = 0; 95 private long deliverDuration = 0; 96 97 98 synchronized final void incrementDispatchCount(long duration) { 99 dispatchCounter++; 100 dispatchDuration += duration; 101 } 102 103 synchronized final void incrementDeliverCount(long duration) { 104 deliverCounter++; 105 deliverDuration += duration; 106 } 107 108 109 public final int getDispatchCount() { 110 return dispatchCounter; 111 } 112 113 public final long getDispatchDuration() { 114 return dispatchDuration; 115 } 116 117 public final int getDeliverCount() { 118 return deliverCounter; 119 } 120 121 public final long getDeliverDuration() { 122 return deliverDuration; 123 } 124 125 public final String toString() { 126 StringBuffer tResult = new StringBuffer (); 127 128 tResult.append("birthday: ").append(DateFormat.getDateTimeInstance().format(new Date (birthDay))).append("\n") 129 .append("sessions: ").append(sessionCounter).append(" / ").append(activeSessionCounter).append(" / ").append(allocatedSessionCounter).append("\n") 130 .append("requests: ").append(requestCounter).append(" / ").append(requestCounter == 0 ? 0 : requestDuration / requestCounter).append(" ms\n") 131 .append("dispatch: ").append(dispatchCounter).append(" / ").append(dispatchCounter == 0 ? 0 : dispatchDuration / dispatchCounter).append(" ms\n") 132 .append("deliver: ").append(deliverCounter).append(" / ").append(deliverCounter == 0 ? 0 : deliverDuration / deliverCounter).append(" ms\n"); 133 134 return tResult.toString(); 135 136 } 137 } 138 | Popular Tags |