Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/altara/mars/engine/Probe.java


1   /* MARS Network Monitoring Engine
2      Copyright (C) 1999 Brian H. Trammell
3      Copyright (C) 2002 Leapfrog Research & Development, LLC
4   
5     This program is free software; you can redistribute it and/or
6     modify it under the terms of the GNU General Public License
7     as published by the Free Software Foundation; either version 2
8     of the License, or (at your option) any later version.
9   
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, it is available at 
17    http:///www.gnu.org/copyleft/gpl.html, or by writing to the
18    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA  02111-1307, USA.
20  */
21  
22  package org.altara.mars.engine;
23  
24  import java.io.*;
25  import java.net.*;
26  import java.util.*;
27  import org.altara.mars.*;
28  
29  /** Probe is the abstract superclass of all MARS service probes.
30  */
31  
32  public abstract class Probe implements Runnable, Serializable {
33    
34    protected Service service;
35  
36    protected Probe() {
37      this(null);
38    }
39  
40    protected Probe(Service service) {
41      this.service = service;
42    }
43  
44    public void setService(Service service) {
45      this.service = service;
46    }
47  
48    public Service getService() {
49      return service;
50    }
51  
52    public boolean canRun() {
53      if (service == null) return false;
54      return service.isDue();
55    }
56  
57    public final void run() {
58      try {
59        // check for runnability first
60        if (!canRun()) {
61          return;
62        }
63  
64        // get the current controller
65        Controller controller = Main.getMain().getController();
66      
67        // runnable, so run the probe
68        Status oldStatus = service.getStatus();
69        service.setStatus(doProbe());
70        Status newStatus = service.getStatus();
71  
72        // first notify the probe was run
73        controller.probeRun(service,newStatus);
74  
75        // then check for status change
76        if (oldStatus.getCode() != newStatus.getCode()) {
77          controller.statusChanged(service,oldStatus,newStatus);
78        } 
79  
80      } catch (Exception ex) {
81        // if the probe fails unexpectedly, let the user know
82        // (don't know why this would happen, but we need to
83        // distinguish it from a known-down state).
84        Status stat = new Status(Status.PROBEFAIL);
85        stat.setProperty("exception",ex.toString());
86        service.setStatus(stat);
87      }
88    }
89  
90    public String toString() {
91      return "Probe on "+service.toString();
92    }
93  
94    protected abstract Status doProbe() throws Exception;
95  }