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.3
Committed: Sun Feb 11 19:45:11 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.2: +4 -3 lines
Log Message:
added debugging lines, modified configuration obtaining

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: ajm4 $
35 * @version $Id: PluginServiceCheckManager.java,v 1.2 2001/02/11 18:11:05 ajm4 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.2 $";
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 _logger.write(toString(), Logger.DEBUG, "got request for service check - " + className);
123 // see if we've already got the service check loaded
124 if(_loadedServiceChecks.containsKey(className)) {
125 _logger.write(toString(), Logger.DEBUG, className + " already loaded - returning reference to it.");
126 return (PluginServiceCheck) _loadedServiceChecks.get(className);
127 }
128 // otherwise we need to load it and return
129 _logger.write(toString(), Logger.DEBUG, "attempting to load service check - " + className);
130
131 // Create an instance of the specified PluginServiceCheck
132 // then added it to the list of already loaded service checks
133 PluginServiceCheck serviceCheck = null;
134 try {
135 serviceCheck = (PluginServiceCheck)ClassLoader.getSystemClassLoader().loadClass(className).newInstance();
136 _loadedServiceChecks.put(className, serviceCheck);
137 _logger.write(toString(), Logger.DEBUG, "loaded service check - "+className+" ("+serviceCheck.getDescription()+")");
138 }
139 catch (InstantiationException e){
140 _logger.write(toString(), Logger.ERROR, "failed to instantiate - "+className);
141 _logger.write(toString(), Logger.ERROR, e.getMessage());
142 }
143 catch (Exception e){
144 _logger.write(toString(), Logger.ERROR, "failed to add - "+className);
145 _logger.write(toString(), Logger.ERROR, e.toString());
146 }
147
148 return serviceCheck;
149 }
150
151 //---ACCESSOR/MUTATOR METHODS---
152
153 //---ATTRIBUTES---
154
155 /**
156 * A hash map containing host pipelines
157 */
158 private HashMap _hostPipelines = new HashMap();
159
160 /**
161 * A hash map containing host pipelines
162 */
163 private HashMap _loadedServiceChecks = new HashMap();
164
165 /**
166 * This is the friendly identifier of the
167 * component this class is running in.
168 * eg, a Filter may be called "filter1",
169 * If this class does not have an owning
170 * component, a name from the configuration
171 * can be placed here. This name could also
172 * be changed to null for utility classes.
173 */
174 private String _name = FilterMain.NAME;
175
176 /**
177 * This holds a reference to the
178 * system logger that is being used.
179 */
180 private Logger _logger = ReferenceManager.getInstance().getLogger();
181
182 /**
183 * A reference to the reference manager in use
184 */
185 private ReferenceManager _refman = ReferenceManager.getInstance();
186
187 //---STATIC ATTRIBUTES---
188
189 /**
190 * A reference to the single instance of this class
191 */
192 private static PluginServiceCheckManager _instance;
193 }