1 25 package org.jrobin.mrtg.server; 26 27 import org.jrobin.mrtg.Debug; 28 import org.jrobin.mrtg.MrtgConstants; 29 30 import java.util.Vector ; 31 32 class Timer extends Thread implements MrtgConstants { 33 private volatile boolean active = true; 34 35 Timer() { 36 start(); 37 } 38 39 public void run() { 40 DeviceList deviceList; 41 deviceList = Server.getInstance().getDeviceList(); 42 Debug.print("Scheduler started"); 43 while(active) { 44 Vector routers = deviceList.getRouters(); 45 for(int i = 0; i < routers.size(); i++) { 46 Device router = (Device) routers.get(i); 47 Vector links = router.getLinks(); 48 for (int j = 0; j < links.size(); j++) { 49 Port link = (Port) links.get(j); 50 if(router.isActive() && link.isActive() && 51 link.isDue() && !link.isSampling()) { 52 new SnmpReader(router, link).start(); 53 try { 54 sleep((long)(1 + Math.random() * SCHEDULER_DELAY)); 55 } catch (InterruptedException e) { 56 e.printStackTrace(); 57 } 58 } 59 } 60 } 61 synchronized(this) { 63 try { 64 wait(SCHEDULER_RESOLUTION * 1000L); 65 } 66 catch (InterruptedException e) { 67 } 68 } 69 } 70 Debug.print("Scheduler ended"); 71 } 72 73 void terminate() { 74 active = false; 75 synchronized(this) { 76 notify(); 77 } 78 } 79 } 80 | Popular Tags |