ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/PluginServiceCheckManager.java
Revision: 1.8
Committed: Tue May 21 16:47:17 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.7: +3 -2 lines
Log Message:
Added URL to GPL headers.

File Contents

# User Rev Content
1 tdb 1.7 /*
2     * i-scream central monitoring system
3 tdb 1.8 * http://www.i-scream.org.uk
4 tdb 1.7 * Copyright (C) 2000-2002 i-scream
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21 ajm 1.1 //---PACKAGE DECLARATION---
22 tdb 1.6 package uk.org.iscream.cms.server.filter;
23 ajm 1.1
24     //---IMPORTS---
25     import java.io.*;
26     import java.util.*;
27    
28 tdb 1.6 import uk.org.iscream.cms.server.util.*;
29     import uk.org.iscream.cms.server.componentmanager.*;
30     import uk.org.iscream.cms.server.core.*;
31 ajm 1.1
32     /**
33     * This class setups up and manages Plugins for performing service
34     * checks. When asked to run some service checks it runs the checks
35     * on the service check pipeline for that host. If the pipleline does
36     * not exist it creates a new one.
37     *
38     * This is a singleton class.
39     *
40     * ###
41     * This does not fully manage the pipelines, it should check
42     * if a host has not heartbeated for a while and thus remove
43     * the pipeline. At the moment it does not.
44     * A suggestions for doing this is to use the getCreated()
45     * method on the PluginServiceCheckPipeline. This tells you when
46     * according to the system time the pipeline was created. You could
47     * then have a thread that periodically checks to see if a host
48     * has not run its pipeline in say two heartbeats, and thus
49     * this indicates that it is no longer running. The pipeline
50     * could then be removed from the hashmap and thus be eligable
51     * for gc.
52     * ###
53     *
54 tdb 1.7 * @author $Author: tdb $
55 tdb 1.8 * @version $Id: PluginServiceCheckManager.java,v 1.7 2002/05/18 18:16:02 tdb Exp $
56 ajm 1.1 */
57     class PluginServiceCheckManager {
58    
59     //---FINAL ATTRIBUTES---
60    
61     /**
62     * The current CVS revision of this class
63     */
64 tdb 1.8 public final String REVISION = "$Revision: 1.7 $";
65 ajm 1.1
66     /**
67 tdb 1.4 * file name suffix for plugin service check classes:
68 ajm 1.1 */
69     private final String _suffix = "__ServiceCheck";
70    
71     //---STATIC METHODS---
72    
73     /**
74 tdb 1.4 * Return a reference to the singleton class.
75 ajm 1.1 * Construct it if it does not already exist, otherwise just return the reference.
76     */
77     public static PluginServiceCheckManager getInstance() {
78     if (_instance == null){
79 ajm 1.2 _instance = new PluginServiceCheckManager();
80 ajm 1.1 }
81     return _instance;
82     }
83    
84     //---CONSTRUCTORS---
85    
86     /**
87     * Private Constructor - this part creates the filter pipeline
88     * This is a singleton class, btw.
89     */
90 ajm 1.2 private PluginServiceCheckManager(){
91 ajm 1.1 _logger.write(toString(), Logger.SYSINIT, "created");
92     }
93    
94     //---PUBLIC METHODS---
95    
96     /**
97 tdb 1.4 * run all registered service checks on a given host,
98     * returning XML data with information about the check.
99 ajm 1.1 *
100 tdb 1.4 * @param hostname the host to run service checks for
101     * @return the xml output from the service checks
102 ajm 1.1 */
103     public String runServiceChecks(String hostname){
104     if (!_hostPipelines.containsKey(hostname)) {
105 ajm 1.2 _hostPipelines.put(hostname, new PluginServiceCheckPipeline(hostname, this));
106 ajm 1.1 }
107 ajm 1.2 return "<services>" + ((PluginServiceCheckPipeline) _hostPipelines.get(hostname)).runPipeline() + "</services>";
108 ajm 1.1 }
109    
110     /**
111     * Overrides the {@link java.lang.Object#toString() Object.toString()}
112     * method to provide clean logging (every class should have this).
113     *
114 tdb 1.6 * This uses the uk.org.iscream.cms.server.util.NameFormat class
115 ajm 1.1 * to format the toString()
116     *
117     * @return the name of this class and its CVS revision
118     */
119     public String toString() {
120     return FormatName.getName(
121     _name,
122     getClass().getName(),
123     REVISION);
124     }
125    
126     //---PRIVATE METHODS---
127    
128     /**
129     * Returns a reference to the specified service check.
130     * This method takes the name of the class that contains
131     * a service check implementation. It then checks to see
132     * if it has loaded that class before. If it has it returns
133     * a reference to it, if not, it loads it for the first time,
134     * remembers it, then returns that.
135     *
136     * @param className the PluginServiceCheck to be loaded
137     * @return the requested PluginServiceCheck
138     */
139     public synchronized PluginServiceCheck getServiceCheck(String className) {
140 ajm 1.3 _logger.write(toString(), Logger.DEBUG, "got request for service check - " + className);
141 ajm 1.1 // see if we've already got the service check loaded
142     if(_loadedServiceChecks.containsKey(className)) {
143     _logger.write(toString(), Logger.DEBUG, className + " already loaded - returning reference to it.");
144     return (PluginServiceCheck) _loadedServiceChecks.get(className);
145     }
146     // otherwise we need to load it and return
147     _logger.write(toString(), Logger.DEBUG, "attempting to load service check - " + className);
148    
149     // Create an instance of the specified PluginServiceCheck
150     // then added it to the list of already loaded service checks
151     PluginServiceCheck serviceCheck = null;
152     try {
153     serviceCheck = (PluginServiceCheck)ClassLoader.getSystemClassLoader().loadClass(className).newInstance();
154     _loadedServiceChecks.put(className, serviceCheck);
155     _logger.write(toString(), Logger.DEBUG, "loaded service check - "+className+" ("+serviceCheck.getDescription()+")");
156     }
157     catch (InstantiationException e){
158     _logger.write(toString(), Logger.ERROR, "failed to instantiate - "+className);
159     _logger.write(toString(), Logger.ERROR, e.getMessage());
160     }
161     catch (Exception e){
162     _logger.write(toString(), Logger.ERROR, "failed to add - "+className);
163     _logger.write(toString(), Logger.ERROR, e.toString());
164     }
165    
166     return serviceCheck;
167     }
168    
169     //---ACCESSOR/MUTATOR METHODS---
170    
171     //---ATTRIBUTES---
172    
173     /**
174     * A hash map containing host pipelines
175     */
176     private HashMap _hostPipelines = new HashMap();
177    
178     /**
179     * A hash map containing host pipelines
180     */
181     private HashMap _loadedServiceChecks = new HashMap();
182    
183     /**
184     * This is the friendly identifier of the
185     * component this class is running in.
186     * eg, a Filter may be called "filter1",
187     * If this class does not have an owning
188     * component, a name from the configuration
189     * can be placed here. This name could also
190     * be changed to null for utility classes.
191     */
192     private String _name = FilterMain.NAME;
193    
194     /**
195     * This holds a reference to the
196     * system logger that is being used.
197     */
198     private Logger _logger = ReferenceManager.getInstance().getLogger();
199    
200     /**
201     * A reference to the reference manager in use
202     */
203     private ReferenceManager _refman = ReferenceManager.getInstance();
204    
205     //---STATIC ATTRIBUTES---
206    
207     /**
208     * A reference to the single instance of this class
209     */
210     private static PluginServiceCheckManager _instance;
211     }