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.26 by tdb, Thu Mar 21 13:01:21 2002 UTC vs.
Revision 1.27 by tdb, Thu Mar 21 17:44:51 2002 UTC

# Line 6 | Line 6 | 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 java.util.Random;
11   import uk.org.iscream.cms.server.util.*;
12  
13   /**
# Line 27 | Line 25 | class TCPReaderInit extends Thread {
25       */
26      public final String REVISION = "$Revision$";
27      
28 +    /**
29 +     * The set of characters to be used for our key
30 +     */
31 +    private final char[] KEYSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
32 +    
33 +    /**
34 +     * The length of our key
35 +     */
36 +    private final int KEYLEN = 15;
37 +    
38   //---STATIC METHODS---
39  
40   //---CONSTRUCTORS---
# Line 59 | Line 67 | class TCPReaderInit extends Thread {
67       */
68      public void run() {
69          try {
70 <            //variables
71 <            String filelist = "";
64 <            String lastModified = "";
65 <            String inBound = "";
70 >            // get an instance of the KeyManager
71 >            KeyManager keyman = KeyManager.getInstance();
72              
73 +            // get some information about the host
74 +            String hostname = _socket.getInetAddress().getHostName().toLowerCase();
75 +            String ipadd = _socket.getInetAddress().getHostAddress();
76 +            
77              // try for HEARTBEAT
78              getInBound("HEARTBEAT");
79              _socketOut.println("OK");
80              
81 <            // try for CONFIG
82 <            getInBound("CONFIG");
83 <            _socketOut.println("OK");
84 <            
85 <            // try for {filelist}
86 <            filelist = getInBound();
87 <            _socketOut.println("OK");
88 <            
89 <            // try for {lastModified}
90 <            lastModified = getInBound();
91 <            // check to see if a config update has happen
92 <            boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
93 <            if(newConfig) {
94 <                // new config !
95 <                _socketOut.println("ERROR");
81 >            // look for a command:
82 >            // CONFIG - to check config
83 >            // KEY - to get the key
84 >            // ENDHEARTBEAT - to finish            
85 >            String cmd = getInBound();
86 >            while(!cmd.equals("ENDHEARTBEAT")) {
87 >                if(cmd.equals("CONFIG")) {
88 >                    // respond to CONFIG
89 >                    _socketOut.println("OK");
90 >                        
91 >                    // try for {filelist}
92 >                    String filelist = getInBound();
93 >                    _socketOut.println("OK");
94 >                    
95 >                    // try for {lastModified}
96 >                    String lastModified = getInBound();
97 >                    // check to see if a config update has happen
98 >                    boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
99 >                    if(newConfig) {
100 >                        // new config !
101 >                        _socketOut.println("ERROR");
102 >                    }
103 >                    else {
104 >                        // nothing has changed
105 >                        _socketOut.println("OK");
106 >                    }
107 >                }
108 >                else if(cmd.equals("KEY")) {
109 >                    // repsond to KEY
110 >                    // generate a key
111 >                    String key = keyman.genKey();
112 >                    // add it to the key manager
113 >                    keyman.addKey(hostname, key);
114 >                    _socketOut.println(key);
115 >                }
116 >                else {
117 >                    _socketOut.println("ERROR");
118 >                }
119 >                // get the next command
120 >                cmd = getInBound();
121              }
87            else {
88                // nothing has changed
89                _socketOut.println("OK");
90            }
122              
123 <            // try for CONFIG
93 <            getInBound("ENDHEARTBEAT");
123 >            // respond to ENDHEARTBEAT
124              _socketOut.println("OK");
125              
126              // work out some information for our heartbeat packet
127              String date = new Long(System.currentTimeMillis()/((long) 1000)).toString(); //seconds
98            String hostname = _socket.getInetAddress().getHostName().toLowerCase();
99            String ipadd = _socket.getInetAddress().getHostAddress();
128              
129              // run the service checks for this host
130              _logger.write(toString(), Logger.DEBUG, "Running service checks");
# Line 162 | Line 190 | class TCPReaderInit extends Thread {
190          // it's a valid message it seems
191          return inBound;
192      }
193 <
193 >    
194   //---ACCESSOR/MUTATOR METHODS---
195  
196   //---ATTRIBUTES---
# Line 208 | Line 236 | class TCPReaderInit extends Thread {
236       * A reference to our Queue
237       */
238      Queue _queue;
239 +    
240   //---STATIC ATTRIBUTES---
241  
242   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines