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.2
Committed: Sun Feb 11 18:11:05 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.1: +4 -4 lines
Log Message:
code typos fixed.

File Contents

# Content
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 * @author $Author: tdb1 $
35 * @version $Id: PluginFilterManager.java,v 1.6 2001/02/01 00:18:42 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.6 $";
45
46 /**
47 * file name suffix for plugin filter classes:
48 */
49 private final String _suffix = "__ServiceCheck";
50
51 //---STATIC METHODS---
52
53 /**
54 * Return a reference to the single 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 * apply all of the filters in the pipeline to the packet.
78 * return true if they all accept the packet.
79 * return false if any single filter rejects the packet.
80 * return true if there are no filters inthe pipeline.
81 *
82 * @param the host to run service checks for
83 * @return whether the packet can be passed on
84 */
85 public String runServiceChecks(String hostname){
86 if (!_hostPipelines.containsKey(hostname)) {
87 _hostPipelines.put(hostname, new PluginServiceCheckPipeline(hostname, this));
88 }
89 return "<services>" + ((PluginServiceCheckPipeline) _hostPipelines.get(hostname)).runPipeline() + "</services>";
90 }
91
92 /**
93 * Overrides the {@link java.lang.Object#toString() Object.toString()}
94 * method to provide clean logging (every class should have this).
95 *
96 * This uses the uk.ac.ukc.iscream.util.NameFormat class
97 * to format the toString()
98 *
99 * @return the name of this class and its CVS revision
100 */
101 public String toString() {
102 return FormatName.getName(
103 _name,
104 getClass().getName(),
105 REVISION);
106 }
107
108 //---PRIVATE METHODS---
109
110 /**
111 * Returns a reference to the specified service check.
112 * This method takes the name of the class that contains
113 * a service check implementation. It then checks to see
114 * if it has loaded that class before. If it has it returns
115 * a reference to it, if not, it loads it for the first time,
116 * remembers it, then returns that.
117 *
118 * @param className the PluginServiceCheck to be loaded
119 * @return the requested PluginServiceCheck
120 */
121 public synchronized PluginServiceCheck getServiceCheck(String className) {
122 // see if we've already got the service check loaded
123 if(_loadedServiceChecks.containsKey(className)) {
124 _logger.write(toString(), Logger.DEBUG, className + " already loaded - returning reference to it.");
125 return (PluginServiceCheck) _loadedServiceChecks.get(className);
126 }
127 // otherwise we need to load it and return
128 _logger.write(toString(), Logger.DEBUG, "attempting to load service check - " + className);
129
130 // Create an instance of the specified PluginServiceCheck
131 // then added it to the list of already loaded service checks
132 PluginServiceCheck serviceCheck = null;
133 try {
134 serviceCheck = (PluginServiceCheck)ClassLoader.getSystemClassLoader().loadClass(className).newInstance();
135 _loadedServiceChecks.put(className, serviceCheck);
136 _logger.write(toString(), Logger.DEBUG, "loaded service check - "+className+" ("+serviceCheck.getDescription()+")");
137 }
138 catch (InstantiationException e){
139 _logger.write(toString(), Logger.ERROR, "failed to instantiate - "+className);
140 _logger.write(toString(), Logger.ERROR, e.getMessage());
141 }
142 catch (Exception e){
143 _logger.write(toString(), Logger.ERROR, "failed to add - "+className);
144 _logger.write(toString(), Logger.ERROR, e.toString());
145 }
146
147 return serviceCheck;
148 }
149
150 //---ACCESSOR/MUTATOR METHODS---
151
152 //---ATTRIBUTES---
153
154 /**
155 * A hash map containing host pipelines
156 */
157 private HashMap _hostPipelines = new HashMap();
158
159 /**
160 * A hash map containing host pipelines
161 */
162 private HashMap _loadedServiceChecks = new HashMap();
163
164 /**
165 * This is the friendly identifier of the
166 * component this class is running in.
167 * eg, a Filter may be called "filter1",
168 * If this class does not have an owning
169 * component, a name from the configuration
170 * can be placed here. This name could also
171 * be changed to null for utility classes.
172 */
173 private String _name = FilterMain.NAME;
174
175 /**
176 * This holds a reference to the
177 * system logger that is being used.
178 */
179 private Logger _logger = ReferenceManager.getInstance().getLogger();
180
181 /**
182 * A reference to the reference manager in use
183 */
184 private ReferenceManager _refman = ReferenceManager.getInstance();
185
186 //---STATIC ATTRIBUTES---
187
188 /**
189 * A reference to the single instance of this class
190 */
191 private static PluginServiceCheckManager _instance;
192 }