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.22 by tdb, Tue Mar 13 16:25:57 2001 UTC vs.
Revision 1.30 by tdb, Sat May 18 18:16:02 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 < package uk.ac.ukc.iscream.filter;
21 > package uk.org.iscream.cms.server.filter;
22  
23   //---IMPORTS---
24 < import uk.ac.ukc.iscream.core.*;
25 < import uk.ac.ukc.iscream.filter.*;
26 < import uk.ac.ukc.iscream.componentmanager.*;
24 > import uk.org.iscream.cms.server.core.*;
25 > import uk.org.iscream.cms.server.filter.*;
26 > import uk.org.iscream.cms.server.componentmanager.*;
27   import java.net.Socket;
9 import java.io.InputStream;
10 import java.io.OutputStream;
11 import java.io.IOException;
28   import java.io.*;
29 < import uk.ac.ukc.iscream.util.*;
29 > import java.util.Random;
30 > import uk.org.iscream.cms.server.util.*;
31  
32   /**
33   * This provides Host heartbeat functionality
# Line 59 | Line 76 | class TCPReaderInit extends Thread {
76       */
77      public void run() {
78          try {
79 <            //variables
80 <            String filelist = "";
64 <            String lastModified = "";
65 <            String inBound = "";
79 >            // get an instance of the KeyManager
80 >            KeyManager keyman = KeyManager.getInstance();
81              
82 +            // get some information about the host
83 +            String hostname = _socket.getInetAddress().getHostName().toLowerCase();
84 +            String ipadd = _socket.getInetAddress().getHostAddress();
85 +            
86              // try for HEARTBEAT
87 <            getInBound("STARTCONFIG");
87 >            getInBound("HEARTBEAT");
88              _socketOut.println("OK");
89              
90 <            // try for CONFIG
91 <            getInBound("CONFIG");
92 <            _socketOut.println("OK");
93 <            
94 <            // try for {filelist}
95 <            filelist = getInBound();
96 <            _socketOut.println("OK");
97 <            
98 <            // try for {lastModified}
99 <            lastModified = getInBound();
100 <            // check to see if a config update has happen
101 <            boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
102 <            if(newConfig) {
103 <                // new config !
104 <                _socketOut.println("ERROR");
90 >            // look for a command:
91 >            // CONFIG - to check config
92 >            // KEY - to get the key
93 >            // ENDHEARTBEAT - to finish            
94 >            String cmd = getInBound();
95 >            while(!cmd.equals("ENDHEARTBEAT")) {
96 >                if(cmd.equals("CONFIG")) {
97 >                    // respond to CONFIG
98 >                    _socketOut.println("OK");
99 >                        
100 >                    // try for {filelist}
101 >                    String filelist = getInBound();
102 >                    _socketOut.println("OK");
103 >                    
104 >                    // try for {lastModified}
105 >                    String lastModified = getInBound();
106 >                    // check to see if a config update has happen
107 >                    boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
108 >                    if(newConfig) {
109 >                        // new config !
110 >                        _socketOut.println("ERROR");
111 >                    }
112 >                    else {
113 >                        // nothing has changed
114 >                        _socketOut.println("OK");
115 >                    }
116 >                }
117 >                else if(cmd.equals("KEY")) {
118 >                    // repsond to KEY
119 >                    // generate a key
120 >                    String key = keyman.genKey();
121 >                    // send key to host
122 >                    _socketOut.println(key);
123 >                    // add it to the key manager
124 >                    keyman.addKey(hostname, key);
125 >                }
126 >                else {
127 >                    _socketOut.println("ERROR");
128 >                }
129 >                // get the next command
130 >                cmd = getInBound();
131              }
87            else {
88                // nothing has changed
89                _socketOut.println("OK");
90            }
132              
133 <            // try for CONFIG
93 <            getInBound("ENDHEARTBEAT");
133 >            // respond to ENDHEARTBEAT
134              _socketOut.println("OK");
135              
136              // work out some information for our heartbeat packet
137              String date = new Long(System.currentTimeMillis()/((long) 1000)).toString(); //seconds
98            String hostname = _socket.getInetAddress().getHostName().toLowerCase();
99            String ipadd = _socket.getInetAddress().getHostAddress();
138              
139              // run the service checks for this host
140              _logger.write(toString(), Logger.DEBUG, "Running service checks");
# Line 127 | Line 165 | class TCPReaderInit extends Thread {
165       * Overrides the {@link java.lang.Object#toString() Object.toString()}
166       * method to provide clean logging (every class should have this).
167       *
168 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
168 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
169       * to format the toString()
170       *
171       * @return the name of this class and its CVS revision
# Line 146 | Line 184 | class TCPReaderInit extends Thread {
184          String inBound = getInBound();
185          // check if it's what we're expecting
186          if(!inBound.equals(expected)) {
187 <            throw new IOException("protocol error - expected:"+expected+" got:" + inBound);
187 >            throw new IOException("protocol error from "+_socket.getInetAddress().getHostName()+" - expected:"+expected+" got:" + inBound);
188          }
189          // it should be ok then
190          return inBound;
# Line 162 | Line 200 | class TCPReaderInit extends Thread {
200          // it's a valid message it seems
201          return inBound;
202      }
203 <
203 >    
204   //---ACCESSOR/MUTATOR METHODS---
205  
206   //---ATTRIBUTES---
# Line 208 | Line 246 | class TCPReaderInit extends Thread {
246       * A reference to our Queue
247       */
248      Queue _queue;
249 +    
250   //---STATIC ATTRIBUTES---
251  
252   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines