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/PluginServiceCheckPipeline.java
Revision: 1.11
Committed: Sun Aug 1 10:40:59 2004 UTC (19 years, 9 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +3 -3 lines
Log Message:
Catch a lot of old URL's and update them. Also remove a couple of old files
that aren't used.

File Contents

# Content
1 /*
2 * i-scream central monitoring system
3 * http://www.i-scream.org
4 * 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 //---PACKAGE DECLARATION---
22 package uk.org.iscream.cms.server.filter;
23
24 //---IMPORTS---
25 import java.io.*;
26 import java.util.*;
27
28 import uk.org.iscream.cms.util.*;
29 import uk.org.iscream.cms.server.componentmanager.*;
30 import uk.org.iscream.cms.server.core.*;
31
32 /**
33 * This class setups up and manages Plugins for performing service
34 * checks. A list of plugins to use is specified in the configuration,
35 * and these are all loaded for a specific host when asked.
36 * It asks the configuration manager for references to ServiceChecks to
37 * perform, thus ensuring only one instance of a service check is loaded
38 * for all hosts.
39 *
40 * @author $Author: tdb $
41 * @version $Id: PluginServiceCheckPipeline.java,v 1.10 2003/02/05 16:43:47 tdb Exp $
42 */
43 class PluginServiceCheckPipeline {
44
45 //---FINAL ATTRIBUTES---
46
47 /**
48 * The current CVS revision of this class
49 */
50 public final String REVISION = "$Revision: 1.10 $";
51
52 /**
53 * file name suffix for plugin classes:
54 */
55 private final String _suffix = "__ServiceCheck";
56
57 //---STATIC METHODS---
58
59 //---CONSTRUCTORS---
60
61 /**
62 * Creates a new pipeline
63 *
64 * @param hostname the host this pipeline is for
65 * @param manager the manager to obtain services checks from
66 */
67 public PluginServiceCheckPipeline(String hostname, PluginServiceCheckManager manager){
68 _logger.write(toString(), Logger.SYSINIT, "Created.");
69 _hostname = hostname;
70 _manager = manager;
71 _pipeline = buildPipeline();
72 _created = System.currentTimeMillis();
73 }
74
75 //---PUBLIC METHODS---
76
77 /**
78 * Instructs this pipeline to execute
79 *
80 * @return the XML generated by all the service checks
81 */
82 public String runPipeline(){
83 // if our config has changed, rebuild the pipeline
84 if (_refman.getCM().isModified(_fileList, _lastModified)) {
85 _pipeline = buildPipeline();
86 }
87 // for each service check in the pipeline...
88 String xml = "";
89 Iterator i = _pipeline.iterator();
90 while (i.hasNext()){
91 PluginServiceCheck plugin = (PluginServiceCheck) i.next();
92 xml += plugin.runServiceCheck(_hostname);
93 }
94 return xml;
95 }
96
97 /**
98 * Overrides the {@link java.lang.Object#toString() Object.toString()}
99 * method to provide clean logging (every class should have this).
100 *
101 * This uses the uk.org.iscream.cms.util.NameFormat class
102 * to format the toString()
103 *
104 * @return the name of this class and its CVS revision
105 */
106 public String toString() {
107 return FormatName.getName(
108 _name,
109 getClass().getName(),
110 REVISION);
111 }
112
113 //---PRIVATE METHODS---
114
115 /**
116 * Builds a pipeline of service checks to be run.
117 * This method is called to read in the service checks
118 * for a particular host from the configurations. It then
119 * builds a linked list of theses checks and then returns
120 * them.
121 *
122 * @param hostname the hostname of the host to build the pipeline for
123 * @return the pipeline
124 */
125 private LinkedList buildPipeline() {
126 _logger.write(toString(), Logger.SYSMSG, "Creating plugin pipeline for service checks for - " + _hostname);
127
128 String pluginsPackage, pluginsList;
129 ConfigurationProxy cp = ConfigurationProxy.getInstance();
130 String configName = "Host."+_hostname;
131
132 _lastModified = cp.getLastModified(configName);
133 _fileList = cp.getFileList(configName);
134
135 try {
136 pluginsPackage = cp.getProperty(configName, "Host.serviceChecksPackage");
137 pluginsList = cp.getProperty(configName, "Host.serviceChecks");
138 } catch(PropertyNotFoundException e) {
139 pluginsPackage = "";
140 pluginsList = "";
141 }
142
143 LinkedList pipeline = new LinkedList();
144 _logger.write(toString(), Logger.DEBUG, "building pipeline of - " + pluginsList);
145 StringTokenizer st = new StringTokenizer(pluginsList, ";");
146 while(st.hasMoreTokens()) {
147 String className = pluginsPackage + "." + st.nextToken() + _suffix;
148 pipeline.add(_manager.getServiceCheck(className));
149 }
150 return pipeline;
151 }
152
153 //---ACCESSOR/MUTATOR METHODS---
154
155 /**
156 * Returns the system time that this
157 * instance was created at. Used for
158 * management of pipelines to determine
159 * when its use is finished.
160 *
161 * @return the time of creation
162 */
163 public long getCreated() {
164 return _created;
165 }
166
167 //---ATTRIBUTES---
168
169 /**
170 * The name of the host this pipleline is for
171 */
172 private String _hostname;
173
174 /**
175 * Holds the current pipeline of plugins
176 */
177 private LinkedList _pipeline;
178
179 /**
180 * When this pipleine was created
181 */
182 private long _created;
183
184 /**
185 * When the current pipeline configuration was last modified
186 */
187 private long _lastModified;
188
189 /**
190 * The list of files used in the configuration
191 */
192 private String _fileList;
193
194 /**
195 * The plugin manager from which we can
196 * obtain references to service checks
197 */
198 private PluginServiceCheckManager _manager;
199
200 /**
201 * This is the friendly identifier of the
202 * component this class is running in.
203 * eg, a Filter may be called "filter1",
204 * If this class does not have an owning
205 * component, a name from the configuration
206 * can be placed here. This name could also
207 * be changed to null for utility classes.
208 */
209 private String _name = FilterMain.NAME;
210
211 /**
212 * This holds a reference to the
213 * system logger that is being used.
214 */
215 private Logger _logger = ReferenceManager.getInstance().getLogger();
216
217 /**
218 * A reference to the reference manager in use
219 */
220 private ReferenceManager _refman = ReferenceManager.getInstance();
221
222 //---STATIC ATTRIBUTES---
223
224 }