1 16 package org.directwebremoting.impl; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.directwebremoting.extend.ServerLoadMonitor; 23 import org.directwebremoting.extend.WaitController; 24 import org.directwebremoting.util.Logger; 25 26 31 public abstract class AbstractServerLoadMonitor implements ServerLoadMonitor 32 { 33 36 public void threadWaitStarting(WaitController controller) 37 { 38 synchronized (waitControllers) 39 { 40 waitControllers.add(controller); 41 } 42 } 43 44 47 public void threadWaitEnding(WaitController controller) 48 { 49 synchronized (waitControllers) 50 { 51 waitControllers.remove(controller); 52 } 53 } 54 55 60 public void shutdownRandomWaitControllers(int count) 61 { 62 synchronized (waitControllers) 63 { 64 for (int i = 0; i < count && waitControllers.size() > 0; i++) 65 { 66 WaitController controller = (WaitController) waitControllers.get(0); 67 controller.shutdown(); 68 } 69 } 70 } 71 72 75 public void shutdown() 76 { 77 if (shutdownCalled) 78 { 79 return; 80 } 81 82 synchronized (waitControllers) 83 { 84 List copy = new ArrayList (); 85 copy.addAll(waitControllers); 86 87 for (Iterator it = copy.iterator(); it.hasNext();) 88 { 89 WaitController controller = (WaitController) it.next(); 90 controller.shutdown(); 91 } 92 93 log.debug(" - shutdown on: " + this); 94 shutdownCalled = true; 95 } 96 } 97 98 101 private boolean shutdownCalled = false; 102 103 106 protected List waitControllers = new ArrayList (); 107 108 111 private static final Logger log = Logger.getLogger(AbstractServerLoadMonitor.class); 112 } 113 | Popular Tags |