Chapter 3. Subscription-based notifications 85
through this connection as shown in Example 3-3. Information about socket
connection is read from a properties file.
Example 3-3 feedToContentAdapter method implementation
private static boolean feedToContentAdapter(String sfeeded) {
try {
PropertyResourceBundle pr =
(PropertyResourceBundle)PropertyResourceBundle.getBundle(propertiesFile);
host = pr.getString("MonitoringContentAdapter.host");
port =
Integer.parseInt(pr.getString("MonitoringContentAdapter.port"));
Socket socket = new Socket(host, port);
OutputStreamWriter out = new
OutputStreamWriter(socket.getOutputStream());
out.write(sfeeded,0,sfeeded.length()-1);
out.flush();
out.close();
} catch (UnknownHostException e) {
return false;
} catch (IOException e) {
return false;
}
return true;
}
7. In the main method, define an infinite loop with the following attributes:
a. Wait and sleep for five minutes so that the server is checked every five
minutes for a status change.
b. Read the properties file to obtain the URL addresses and the quantity of
servers that are monitored.
c. For each monitored server, try to establish an HTTP connection.
d. Depending on the HTTP connection results, set the server status
message. (One message status is generated for the whole group of
servers.) Send the server status message to the content adapter using the
function defined earlier. (In this example, it is feedToContentAdapter.)