KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > mrtg > server > Timer


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

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 JavaDoc;
31
32 class Timer extends Thread JavaDoc 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 JavaDoc routers = deviceList.getRouters();
45             for(int i = 0; i < routers.size(); i++) {
46                 Device router = (Device) routers.get(i);
47                 Vector JavaDoc 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 JavaDoc e) {
56                             e.printStackTrace();
57                         }
58                     }
59                 }
60             }
61             // sleep for a while
62
synchronized(this) {
63                 try {
64                     wait(SCHEDULER_RESOLUTION * 1000L);
65                 }
66                 catch (InterruptedException JavaDoc 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