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.28 by tdb, Thu Mar 21 22:09:13 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.filter;
2 > package uk.org.iscream.cms.server.filter;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.core.*;
6 < import uk.ac.ukc.iscream.filter.*;
7 < import uk.ac.ukc.iscream.componentmanager.*;
5 > import uk.org.iscream.cms.server.core.*;
6 > import uk.org.iscream.cms.server.filter.*;
7 > import uk.org.iscream.cms.server.componentmanager.*;
8   import java.net.Socket;
9 import java.io.InputStream;
10 import java.io.OutputStream;
11 import java.io.IOException;
9   import java.io.*;
10 < import uk.ac.ukc.iscream.util.*;
10 > import java.util.Random;
11 > import uk.org.iscream.cms.server.util.*;
12  
13   /**
14   * This provides Host heartbeat functionality
# Line 59 | Line 57 | class TCPReaderInit extends Thread {
57       */
58      public void run() {
59          try {
60 <            //variables
61 <            String filelist = "";
64 <            String lastModified = "";
65 <            String inBound = "";
60 >            // get an instance of the KeyManager
61 >            KeyManager keyman = KeyManager.getInstance();
62              
63 +            // get some information about the host
64 +            String hostname = _socket.getInetAddress().getHostName().toLowerCase();
65 +            String ipadd = _socket.getInetAddress().getHostAddress();
66 +            
67              // try for HEARTBEAT
68 <            getInBound("STARTCONFIG");
68 >            getInBound("HEARTBEAT");
69              _socketOut.println("OK");
70              
71 <            // try for CONFIG
72 <            getInBound("CONFIG");
73 <            _socketOut.println("OK");
74 <            
75 <            // try for {filelist}
76 <            filelist = getInBound();
77 <            _socketOut.println("OK");
78 <            
79 <            // try for {lastModified}
80 <            lastModified = getInBound();
81 <            // check to see if a config update has happen
82 <            boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
83 <            if(newConfig) {
84 <                // new config !
85 <                _socketOut.println("ERROR");
71 >            // look for a command:
72 >            // CONFIG - to check config
73 >            // KEY - to get the key
74 >            // ENDHEARTBEAT - to finish            
75 >            String cmd = getInBound();
76 >            while(!cmd.equals("ENDHEARTBEAT")) {
77 >                if(cmd.equals("CONFIG")) {
78 >                    // respond to CONFIG
79 >                    _socketOut.println("OK");
80 >                        
81 >                    // try for {filelist}
82 >                    String filelist = getInBound();
83 >                    _socketOut.println("OK");
84 >                    
85 >                    // try for {lastModified}
86 >                    String lastModified = getInBound();
87 >                    // check to see if a config update has happen
88 >                    boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
89 >                    if(newConfig) {
90 >                        // new config !
91 >                        _socketOut.println("ERROR");
92 >                    }
93 >                    else {
94 >                        // nothing has changed
95 >                        _socketOut.println("OK");
96 >                    }
97 >                }
98 >                else if(cmd.equals("KEY")) {
99 >                    // repsond to KEY
100 >                    // generate a key
101 >                    String key = keyman.genKey();
102 >                    // add it to the key manager
103 >                    keyman.addKey(hostname, key);
104 >                    _socketOut.println(key);
105 >                }
106 >                else {
107 >                    _socketOut.println("ERROR");
108 >                }
109 >                // get the next command
110 >                cmd = getInBound();
111              }
87            else {
88                // nothing has changed
89                _socketOut.println("OK");
90            }
112              
113 <            // try for CONFIG
93 <            getInBound("ENDHEARTBEAT");
113 >            // respond to ENDHEARTBEAT
114              _socketOut.println("OK");
115              
116              // work out some information for our heartbeat packet
117              String date = new Long(System.currentTimeMillis()/((long) 1000)).toString(); //seconds
98            String hostname = _socket.getInetAddress().getHostName().toLowerCase();
99            String ipadd = _socket.getInetAddress().getHostAddress();
118              
119              // run the service checks for this host
120              _logger.write(toString(), Logger.DEBUG, "Running service checks");
# Line 127 | Line 145 | class TCPReaderInit extends Thread {
145       * Overrides the {@link java.lang.Object#toString() Object.toString()}
146       * method to provide clean logging (every class should have this).
147       *
148 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
148 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
149       * to format the toString()
150       *
151       * @return the name of this class and its CVS revision
# Line 146 | Line 164 | class TCPReaderInit extends Thread {
164          String inBound = getInBound();
165          // check if it's what we're expecting
166          if(!inBound.equals(expected)) {
167 <            throw new IOException("protocol error - expected:"+expected+" got:" + inBound);
167 >            throw new IOException("protocol error from "+_socket.getInetAddress().getHostName()+" - expected:"+expected+" got:" + inBound);
168          }
169          // it should be ok then
170          return inBound;
# Line 162 | Line 180 | class TCPReaderInit extends Thread {
180          // it's a valid message it seems
181          return inBound;
182      }
183 <
183 >    
184   //---ACCESSOR/MUTATOR METHODS---
185  
186   //---ATTRIBUTES---
# Line 208 | Line 226 | class TCPReaderInit extends Thread {
226       * A reference to our Queue
227       */
228      Queue _queue;
229 +    
230   //---STATIC ATTRIBUTES---
231  
232   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines