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.6
Committed: Tue May 29 17:02:35 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.5: +7 -7 lines
Log Message:
Major change in the java package naming. This has been held off for some time
now, but it really needed doing. The future packaging of all i-scream products
will be;

uk.org.iscream.<product>.<subpart>.*

In the case of the central monitoring system server this will be;

uk.org.iscream.cms.server.*

The whole server has been changed to follow this structure, and tested to a
smallish extent. Further changes in other parts of the CMS will follow.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.cms.server.filter;
3
4 //---IMPORTS---
5 import java.io.*;
6 import java.util.*;
7
8 import uk.org.iscream.cms.server.util.*;
9 import uk.org.iscream.cms.server.componentmanager.*;
10 import uk.org.iscream.cms.server.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 * @author $Author: tdb1 $
35 * @version $Id: PluginServiceCheckManager.java,v 1.5 2001/03/14 23:25:29 tdb1 Exp $
36 */
37 class PluginServiceCheckManager {
38
39 //---FINAL ATTRIBUTES---
40
41 /**
42 * The current CVS revision of this class
43 */
44 public final String REVISION = "$Revision: 1.5 $";
45
46 /**
47 * file name suffix for plugin service check classes:
48 */
49 private final String _suffix = "__ServiceCheck";
50
51 //---STATIC METHODS---
52
53 /**
54 * Return a reference to the singleton class.
55 * Construct it if it does not already exist, otherwise just return the reference.
56 */
57 public static PluginServiceCheckManager getInstance() {
58 if (_instance == null){
59 _instance = new PluginServiceCheckManager();
60 }
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 private PluginServiceCheckManager(){
71 _logger.write(toString(), Logger.SYSINIT, "created");
72 }
73
74 //---PUBLIC METHODS---
75
76 /**
77 * run all registered service checks on a given host,
78 * returning XML data with information about the check.
79 *
80 * @param hostname the host to run service checks for
81 * @return the xml output from the service checks
82 */
83 public String runServiceChecks(String hostname){
84 if (!_hostPipelines.containsKey(hostname)) {
85 _hostPipelines.put(hostname, new PluginServiceCheckPipeline(hostname, this));
86 }
87 return "<services>" + ((PluginServiceCheckPipeline) _hostPipelines.get(hostname)).runPipeline() + "</services>";
88 }
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.org.iscream.cms.server.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 _logger.write(toString(), Logger.DEBUG, "got request for service check - " + className);
121 // 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 }