1 16 package org.directwebremoting.impl; 17 18 import java.util.Random ; 19 20 import org.directwebremoting.extend.ServerLoadMonitor; 21 import org.directwebremoting.extend.WaitController; 22 import org.directwebremoting.util.HitMonitor; 23 24 30 public class ThreadDroppingServerLoadMonitor extends AbstractServerLoadMonitor implements ServerLoadMonitor 31 { 32 35 public long getConnectedTime() 36 { 37 return connectedTime; 38 } 39 40 43 public int getDisconnectedTime() 44 { 45 return disconnectedTime; 46 } 47 48 51 public void threadWaitStarting(WaitController controller) 52 { 53 hitMonitor.recordHit(); 54 super.threadWaitStarting(controller); 55 56 checkLoading(); 57 } 58 59 62 public void threadWaitEnding(WaitController controller) 63 { 64 super.threadWaitEnding(controller); 65 } 66 67 70 private void checkLoading() 71 { 72 float hitsPerSecond = (float) hitMonitor.getHitsInLastPeriod() / SECONDS_MONITORED; 73 74 float load = hitsPerSecond / maxHitsPerSecond; 76 77 disconnectedTime = (int) (disconnectedTime * load); 78 if (disconnectedTime == 0) 79 { 80 disconnectedTime = 1; 81 } 82 } 83 84 87 public void setMaxHitsPerSecond(int maxHitsPerSecond) 88 { 89 this.maxHitsPerSecond = maxHitsPerSecond; 90 } 91 92 98 protected int maxHitsPerSecond = 100; 99 100 104 protected Random random = new Random (); 105 106 110 protected int connectedTime = 60000; 111 112 115 protected int disconnectedTime = 1; 116 117 121 protected static final int SECONDS_MONITORED = 10; 122 123 126 protected HitMonitor hitMonitor = new HitMonitor(SECONDS_MONITORED); 127 } 128 | Popular Tags |