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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/HostInit.java (file contents):
Revision 1.16 by tdb, Wed Feb 7 13:47:22 2001 UTC vs.
Revision 1.29 by tdb, Fri Mar 22 10:43:06 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.filtermanager;
2 > package uk.org.iscream.cms.server.filtermanager;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.core.*;
6 < import uk.ac.ukc.iscream.filter.*;
7 < import uk.ac.ukc.iscream.util.*;
8 < import uk.ac.ukc.iscream.componentmanager.*;
9 < import java.net.Socket;
5 > import uk.org.iscream.cms.server.core.*;
6 > import uk.org.iscream.cms.server.filter.*;
7 > import uk.org.iscream.cms.server.util.*;
8 > import uk.org.iscream.cms.server.componentmanager.*;
9 > import java.net.*;
10   import java.io.*;
11 + import java.util.*;
12  
13   /**
14   * Handles setting up a host.
# Line 36 | Line 37 | class HostInit extends Thread {
37       * @param socket The socket to which the host is connected
38       */
39      public HostInit(Socket socket) throws IOException {
40 +        // set the Thread name
41 +        setName("filtermanager.HostInit");
42 +        
43          _socket = socket;
44          // setup reader & writer
45          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
# Line 50 | Line 54 | class HostInit extends Thread {
54       * the host to determine it's setup.
55       */
56      public void run() {
57 +        // get a hook on the config proxy
58 +        ConfigurationProxy cp = ConfigurationProxy.getInstance();
59 +        // this is our config name
60 +        String configName = "Host." + _socket.getInetAddress().getHostName().toLowerCase();
61          try {
62 <            String inBound = _socketIn.readLine();
63 <            if (!inBound.equals("STARTCONFIG")) {
64 <                _socketOut.println("ERROR");
65 <                throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
66 <            }
67 <
68 <            Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase());
69 <            if (myConfig == null) {
70 <                _socketOut.println("ERROR");
71 <                throw new IOException("error in host configuration");
72 <            } else {
73 <                _socketOut.println("OK");
74 <                
75 <                // get lastmodified
76 <                inBound = _socketIn.readLine();
77 <                if(!inBound.equals("LASTMODIFIED")) {
78 <                        // protocol error
62 >            // try for STARTCONFIG
63 >            getInBound("STARTCONFIG");
64 >            _socketOut.println("OK");
65 >            
66 >            // try for LASTMODIFIED
67 >            getInBound("LASTMODIFIED");
68 >            _socketOut.println(cp.getLastModified(configName));
69 >            
70 >            // try for FILELIST
71 >            getInBound("FILELIST");
72 >            _socketOut.println(cp.getFileList(configName));
73 >            
74 >            // try for FQDN
75 >            getInBound("FQDN");
76 >            _socketOut.println(_socket.getInetAddress().getHostName().toLowerCase());
77 >            
78 >            // get properties
79 >            String reqProperty = getInBound();
80 >            while(!reqProperty.equals("ENDCONFIG")) {
81 >                // get the property
82 >                try {
83 >                    String returnedProperty = cp.getProperty(configName, "Host."+reqProperty);
84 >                    _socketOut.println(returnedProperty);
85 >                } catch (PropertyNotFoundException e) {
86                      _socketOut.println("ERROR");
72                    throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
87                  }
88 <                else {
89 <                        // send info
90 <                        _socketOut.println(myConfig.getLastModified());
88 >                // get the next request
89 >                reqProperty = _socketIn.readLine();
90 >            }
91 >            _logger.write(toString(), Logger.SYSMSG, "configured host");
92 >            _socketOut.println("OK");
93 >            
94 >            // get filter reference
95 >            getInBound("FILTER");
96 >                // send info
97 >                String filterList = cp.getProperty(configName, "Host.filter");
98 >                FilterInfo filterInfoRef = null;
99 >                String filter = null;
100 >                StringTokenizer st = new StringTokenizer(filterList, ";");
101 >            while (filterInfoRef==null && st.hasMoreTokens()) {
102 >                filter = st.nextToken();
103 >                _logger.write(toString(), Logger.DEBUG, " looking for filter- " + filter);
104 >                try {
105 >                    filterInfoRef = FilterInfoHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.FilterInfo." + filter));
106 >                } catch (ComponentCORBAException e) {
107 >                    _logger.write(toString(), Logger.DEBUG, " unable to find filter- " + filter);
108                  }
78                
79                // get config fileList
80                inBound = _socketIn.readLine();
81                if(!inBound.equals("FILELIST")) {
82                        // protocol error
83                    _socketOut.println("ERROR");
84                    throw new IOException("protocol error - expected:FILELIST got:" + inBound);
85                }
86                else {
87                        // send info
88                        _socketOut.println(myConfig.getFileList());
89                }
90
91                // get properties
92                inBound = _socketIn.readLine();
93                while(!inBound.equals("ENDCONFIG")) {
94                          
95                    // get the property
96                    try {
97                        String returnedProperty = myConfig.getProperty("Host."+inBound);    
98                        
99                        _socketOut.println(returnedProperty);
100    
101                    } catch (org.omg.CORBA.MARSHAL e) {
102                        _socketOut.println("ERROR");
103                    }
104                    inBound = _socketIn.readLine();
105                }
106                _logger.write(toString(), Logger.SYSMSG, "configured host");
107                _socketOut.println("OK");
108                
109                // get filter reference
110                inBound = _socketIn.readLine();
111                if(!inBound.equals("FILTER")) {
112                        // protocol error
113                    _socketOut.println("ERROR");
114                    throw new IOException("protocol error - expected:FILTER got:" + inBound);
115                }
116                else {
117                        // send info
118                        String parentFilter =  myConfig.getProperty("Host.filter");
119                        _logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
120                    Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter));
121                        _socketOut.println(filter.getHostName() + ";"
122                                         + filter.getUDPPort() + ";"
123                                         + filter.getTCPPort());
124                }
125                
126                // confirm that all is ok
127                inBound = _socketIn.readLine();
128                if(!inBound.equals("END")) {
129                        // protocol error
130                    _socketOut.println("ERROR");
131                    throw new IOException("protocol error - expected:END got:" + inBound);
132                }
133                else {
134                        // send ok
135                        _socketOut.println("OK");
136                }
137
109              }
110 +                
111 +                // hopefully we found a filter
112 +            if(filterInfoRef != null) {
113 +                _logger.write(toString(), Logger.DEBUG, " found filter- " + filter);
114 +                // tell the host about it...
115 +                    _socketOut.println(filterInfoRef.getHostName() + ";"
116 +                                     + filterInfoRef.getUDPPort() + ";"
117 +                                     + filterInfoRef.getTCPPort());
118 +                }
119 +                else {
120 +                    // ...or throw a wobbly (and tell the host!)
121 +                    _socketOut.println("ERROR");
122 +                    throw new IOException("unable to find filter for host");
123 +                }
124              
125 +            // confirm ok with END
126 +            getInBound("END");
127 +            _socketOut.println("OK");
128 +            
129          } catch (Exception e) {
130 <            _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
130 >            _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
131          }
132          
144        _socketOut.flush();
133          // Disconnect streams & socket
134          try {
135              _socketIn.close();
# Line 157 | Line 145 | class HostInit 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 170 | Line 158 | class HostInit extends Thread {
158      }
159  
160   //---PRIVATE METHODS---
161 +
162 +    private String getInBound(String expected) throws IOException {
163 +        // grab the input
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);
168 +        }
169 +        // it should be ok then
170 +        return inBound;
171 +    }
172 +    
173 +    private String getInBound() throws IOException {
174 +        // grab the input
175 +        String inBound = _socketIn.readLine();
176 +        // check for null's, likely disconnection
177 +        if(inBound == null) {
178 +            throw new IOException("got null from host, maybe it died");
179 +        }
180 +        // it's a valid message it seems
181 +        return inBound;
182 +    }
183  
184   //---ACCESSOR/MUTATOR METHODS---
185  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines