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/ServiceCheckSkeleton.java
Revision: 1.5
Committed: Tue May 29 17:02:35 2001 UTC (23 years ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.4: +2 -2 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

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2 tdb 1.5 package uk.org.iscream.cms.server.filter;
3 tdb 1.1
4     //---IMPORTS---
5     import java.net.*;
6     import java.io.*;
7    
8     /**
9     * A skeleton class for Service Checks to extend.
10     *
11 tdb 1.2 * @author $Author: tdb1 $
12 tdb 1.5 * @version $Id: ServiceCheckSkeleton.java,v 1.4 2001/03/14 23:25:29 tdb1 Exp $
13 tdb 1.1 */
14     public abstract class ServiceCheckSkeleton implements PluginServiceCheck {
15    
16     //---FINAL ATTRIBUTES---
17    
18     //---STATIC METHODS---
19    
20     //---CONSTRUCTORS---
21    
22     //---PUBLIC METHODS---
23    
24     /**
25     * Runs a service check on a given hostname.
26     *
27     * @param hostname The hostname to check
28     */
29     public abstract String runServiceCheck(String hostname);
30    
31     /**
32     * Checks if a service is returning a valid response, and
33     * constructs suitable XML for inclusion in a packet.
34     *
35     * @param hostname The hostname to query
36     * @param port The port to query
37     * @param expectedSubString The String to look for in the response
38     * @param XMLTag The name of the tag to be put in the XML
39     * @return The String of XML with the response information
40     */
41     protected String checkService(String hostname, int port, String expectedSubString, String XMLTag) {
42     String message, status;
43     try {
44     // connect and get response
45     String response = connectToService(hostname, port);
46     // check if the expected text is in the response
47     if(response.indexOf(expectedSubString) != -1) {
48     status = "0";
49     message = "Good Header received: "+response;
50     }
51     else {
52     status = "1";
53     message = "Bad Header received: "+response;
54     }
55     } catch (IOException e) {
56     // connect failed
57     status = "1";
58     message = "Service check failed to establish connection to host: " + e.getMessage();
59     }
60     return "<"+XMLTag+" status=\"" + status + "\" message=\"" + message + "\"></"+XMLTag+">";
61     }
62    
63     /**
64     * Connects to a service and returns the first line of text.
65     *
66     * @param hostname The hostname of the service to check
67     * @param port The port of the service to check
68     * @return The first line of text given
69     * @throws IOException if the connection fails for some reason
70     */
71     protected String connectToService(String hostname, int port) throws IOException {
72     // connect
73 tdb 1.2 Socket socket = new Socket(hostname, port);
74 tdb 1.1 BufferedReader socketIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
75     // read first line
76     String response = socketIn.readLine();
77     // close
78     socketIn.close();
79     socket.close();
80     // return first line
81     return response;
82     }
83    
84     /**
85     * Used to query the Service Check to see what it does.
86     *
87     * @return the String representation of what the Service Check does
88     */
89 tdb 1.3 public abstract String getDescription();
90 tdb 1.1
91     //---PRIVATE METHODS---
92    
93     //---ACCESSOR/MUTATOR METHODS---
94    
95     //---ATTRIBUTES---
96    
97     //---STATIC ATTRIBUTES---
98    
99     }