ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/HostInit.java
Revision: 1.6
Committed: Mon Nov 20 18:55:24 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.5: +6 -6 lines
Log Message:
A lot of changes from Configurator to ConfigurationManager.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3 //---IMPORTS---
4 import uk.ac.ukc.iscream.core.*;
5 import java.net.Socket;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8 import java.io.IOException;
9 import java.io.*;
10
11 /**
12 * <ONE LINE DESCRIPTION>
13 * <DETAILED DESCRIPTION>
14 *
15 * @author $Author: tdb1 $
16 * @version $Id: HostInit.java,v 1.5 2000/11/16 18:14:05 tdb1 Exp $
17 */
18 class HostInit extends Thread {
19
20 //---FINAL ATTRIBUTES---
21
22 /**
23 * The current CVS revision of this class
24 */
25 public final String REVISION = "$Revision: 1.5 $";
26
27 //---STATIC METHODS---
28
29 //---CONSTRUCTORS---
30
31 public HostInit(Socket socket, ConfigurationManager configManager, Logger logger) throws IOException {
32 _configManager = configManager;
33 _logger = logger;
34 _socket = socket;
35 _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
36 _socketOut = new PrintWriter(_socket.getOutputStream());
37 _logger.write(toString(), Logger.SYSINIT, "created");
38 }
39
40 //---PUBLIC METHODS---
41
42 public void run() {
43 try {
44 String inBound = _socketIn.readLine();
45 if (!inBound.equals("STARTCONFIG")) {
46 _socketOut.println("ERROR");
47 _socketOut.flush();
48 throw new IOException("Protocol Error");
49 }
50
51 Configuration myConfig = _configManager.getConfiguration(_socket.getInetAddress().getHostName().toLowerCase());
52 if (myConfig == null) {
53 _socketOut.println("ERROR");
54 throw new IOException("No Configuration File For Host");
55 } else {
56 _socketOut.println("OK");
57 _socketOut.flush();
58
59 // get lastmodified
60 inBound = _socketIn.readLine();
61 if(!inBound.equals("LASTMODIFIED")) {
62 // protocol error
63 _socketOut.println("ERROR");
64 _socketOut.flush();
65 throw new IOException("Protocol Error");
66 }
67 else {
68 // send info
69 _socketOut.println(myConfig.getLastModified());
70 _socketOut.flush();
71 }
72
73 // get properties
74 inBound = _socketIn.readLine();
75 while(!inBound.equals("ENDCONFIG")) {
76
77 // get the property
78 try {
79 String returnedProperty = myConfig.getProperty(inBound);
80
81 _socketOut.println(returnedProperty);
82 _socketOut.flush();
83
84 } catch (org.omg.CORBA.MARSHAL e) {
85 _socketOut.println("ERROR");
86 _socketOut.flush();
87 }
88 inBound = _socketIn.readLine();
89 }
90 _logger.write(toString(), Logger.SYSMSG, "configured host");
91 _socketOut.println("OK");
92 _socketOut.flush();
93 }
94
95 } catch (Exception e) {
96 _logger.write(toString(), Logger.ERROR, e.toString());
97 }
98
99 _socketOut.flush();
100 // Disconnect streams & socket
101 try {
102 _socketIn.close();
103 _socketOut.close();
104 _socket.close();
105 } catch (IOException e) {
106 _logger.write(toString(), Logger.ERROR, "exception on socket close");
107 }
108 _logger.write(toString(), Logger.SYSMSG, "finished");
109 }
110
111 /**
112 * Overrides the {@link java.lang.Object#toString() Object.toString()}
113 * method to provide clean logging (every class should have this).
114 *
115 * @return the name of this class and its CVS revision
116 */
117 public String toString() {
118 return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
119 + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
120
121 }
122
123 //---PRIVATE METHODS---
124
125 //---ACCESSOR/MUTATOR METHODS---
126
127 //---ATTRIBUTES---
128
129 ConfigurationManager _configManager;
130 Logger _logger;
131 Socket _socket;
132 BufferedReader _socketIn;
133 PrintWriter _socketOut;
134
135 //---STATIC ATTRIBUTES---
136
137 }