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/TCPReaderInit.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/TCPReaderInit.java (file contents):
Revision 1.12 by tdb, Thu Jan 18 23:13:36 2001 UTC vs.
Revision 1.21 by tdb, Tue Mar 13 02:19:46 2001 UTC

# Line 30 | Line 30 | class TCPReaderInit extends Thread {
30   //---STATIC METHODS---
31  
32   //---CONSTRUCTORS---
33 <
33 >    
34 >    /**
35 >     * Construct a new TCPReaderInit.
36 >     *
37 >     * @param socket the Socket to which the host is connected
38 >     * @param queue the Queue to which we'll add data
39 >     * @throws IOException if something goes badly wrong
40 >     */
41      public TCPReaderInit(Socket socket, Queue queue) throws IOException {
42 +        // set the Thread name
43 +        setName("filter.TCPReaderInit");
44 +        
45          _socket = socket;
46          _queue = queue;
47 +        // setup the reader & writer
48          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
49 <        _socketOut = new PrintWriter(_socket.getOutputStream());
49 >        _socketOut = new PrintWriter(_socket.getOutputStream(), true);
50          _logger.write(toString(), Logger.SYSINIT, "created");
51      }
52      
53   //---PUBLIC METHODS---
54 <
54 >    
55 >    /**
56 >     * Main run method. Will communicate with the host, inform it
57 >     * if any updates to it's configuration are needed, and send
58 >     * a heartbeat packet into the system.
59 >     */
60      public void run() {
61          try {
62              //variables
# Line 51 | Line 67 | class TCPReaderInit extends Thread {
67              inBound = _socketIn.readLine();
68              if(!inBound.equals("HEARTBEAT")) {
69                  _socketOut.println("ERROR");
54                _socketOut.flush();
70                  throw new IOException("protocol error - expecting:HEARTBEAT got:" + inBound);
71              } else {
72                  _socketOut.println("OK");
58                _socketOut.flush();
73              }
74              
75              inBound = _socketIn.readLine();
76              if(!inBound.equals("CONFIG")) {
77                  _socketOut.println("ERROR");
64                _socketOut.flush();
78                  throw new IOException("protocol error - expecting:CONFIG got:" + inBound);
79              } else {
80                  _socketOut.println("OK");
68                _socketOut.flush();
81              }
82              
83              inBound = _socketIn.readLine();
84              filelist = inBound;
85              _socketOut.println("OK");
74            _socketOut.flush();
86              
87              inBound = _socketIn.readLine();
88              lastModified = inBound;
# Line 84 | Line 95 | class TCPReaderInit extends Thread {
95              else {
96                  _socketOut.println("OK");
97              }
87            _socketOut.flush();
98              
99              inBound = _socketIn.readLine();
100              if(!inBound.equals("ENDHEARTBEAT")) {
101                  _socketOut.println("ERROR");
92                _socketOut.flush();
102                  throw new IOException("protocol error - expecting:ENDHEARTBEAT got:" + inBound);
103              } else {
104                  _socketOut.println("OK");
96                _socketOut.flush();
105              }
106  
107 <            String date = new Long(System.currentTimeMillis()).toString();
108 <            String hostname = _socket.getInetAddress().getHostName();
107 >            String date = new Long(System.currentTimeMillis()/((long) 1000)).toString();
108 >            String hostname = _socket.getInetAddress().getHostName().toLowerCase();
109              String ipadd = _socket.getInetAddress().getHostAddress();
102            String xml = "<packet type=\"heartbeat\" machine_name=\""+hostname+"\" date=\""+date+"\" ip=\""+ipadd+"\"></packet>";
110              
111 +            // run the service checks for this host
112 +            _logger.write(toString(), Logger.DEBUG, "Running service checks");
113 +            String checks = PluginServiceCheckManager.getInstance().runServiceChecks(hostname);
114 +            
115 +            // build the heartbeat packet
116 +            String xml = "<packet type=\"heartbeat\" machine_name=\""+hostname+"\" date=\""+date+"\" ip=\""+ipadd+"\">" + checks + "</packet>";
117 +            
118 +            // get it to be sent on
119              _queue.add(xml);
120              
121          } catch (Exception e) {
122 <            _logger.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
122 >            _logger.write(toString(), Logger.ERROR, "ERROR: " + e);
123          }
124          
110        _socketOut.flush();
125          // Disconnect streams & socket
126          try {
127              _socketIn.close();
# Line 116 | Line 130 | class TCPReaderInit extends Thread {
130          } catch (IOException e) {
131              _logger.write(toString(), Logger.ERROR, "exception on socket close");
132          }
133 <        _logger.write(toString(), Logger.SYSMSG, "finished");
133 >        _logger.write(toString(), Logger.DEBUG, "finished");
134      }
135      
136      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines