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.4
Committed: Mon Feb 12 00:34:11 2001 UTC (23 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.3: +8 -10 lines
Log Message:
Comment changes really. This wasn't copy/pasted at all was it ? :-)

File Contents

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