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