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

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/HostListener.java (file contents):
Revision 1.1 by tdb, Thu Nov 23 01:47:35 2000 UTC vs.
Revision 1.10 by tdb, Wed Mar 20 12:56:37 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
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 java.net.Socket;
8 < import java.net.ServerSocket;
9 < import java.io.OutputStream;
10 < import java.io.IOException;
10 < import java.net.InetAddress;
11 < import java.net.UnknownHostException;
12 < import org.omg.CORBA.*;
13 < import org.omg.CosNaming.*;
5 > import uk.org.iscream.cms.server.core.*;
6 > import uk.org.iscream.cms.server.componentmanager.*;
7 > import uk.org.iscream.cms.server.filter.*;
8 > import uk.org.iscream.cms.server.util.*;
9 > import java.net.*;
10 > import java.io.*;
11  
12   /**
13   * A socket listener to listen for new hosts registering with the system.
# Line 36 | Line 33 | class HostListener extends Thread {
33          /**
34       * Constructs a new listener
35       *
36 <     * @param logger a reference to the logger we are using
40 <     * @param configManager a reference to the ConfigurationManager we are using
41 <         * @param port The port that the server will listen on.
36 >         * @param listenPort The port that the server will listen on.
37           */
38 <    public HostListener(Logger logger, ConfigurationManager configManager, int port, NamingContextExt ncRef) {
39 <        _logger = logger;
40 <        _ncRef = ncRef;
41 <        _configManager = configManager;
47 <        _port = port;
38 >    public HostListener() {
39 >        // set the Thread name
40 >        setName("filtermanager.HostListener");
41 >        
42          _logger.write(toString(), Logger.SYSINIT, "started");
43      }
44  
51    
52
45   //---PUBLIC METHODS---
46  
47          /**
# Line 60 | Line 52 | class HostListener extends Thread {
52           * and then passing them off to other processes to deal with.
53           */
54      public void run(){
55 <        ServerSocket listenPort=null;
55 >        // get our ACL from the configuration
56 >        ACL acl = null;
57 >        try {
58 >            String stringACL = ConfigurationProxy.getInstance().getProperty("FilterManager", "FilterManager.ACL");
59 >            acl = new ACL(stringACL);
60 >        }
61 >        catch(PropertyNotFoundException e) {
62 >            _logger.write(toString(), Logger.WARNING, "No ACL found for FilterManager: " + e);
63 >        }
64 >        
65 >        ServerSocket listenSocket=null;
66                  // We use this boolean so we can break out of the while loop if we want
67          boolean run = true;
68          try{
69 +            // Work out the port we want
70 +            int listenPort = Integer.parseInt(ConfigurationProxy.getInstance().getProperty("FilterManager", "FilterManager.listenPort"));
71                          // Setup the ServerSocket so that clients can connect
72 <            listenPort = new ServerSocket(_port);
73 <        }
74 <        catch(IOException e){
75 <        }
76 <                // Log what machine/port we're listening on
77 <                try{
78 <                        _logger.write(toString(), Logger.SYSMSG, "Server listening on "
72 >                        // use an ACLServerSocket if we have an ACL
73 >                        if(acl != null) {
74 >                            listenSocket = new ACLServerSocket(acl, listenPort);
75 >                        }
76 >                        else {
77 >                listenSocket = new ServerSocket(listenPort);
78 >            }
79 >            _logger.write(toString(), Logger.SYSMSG, "Server listening on "
80                                                                                  +InetAddress.getLocalHost().getHostName()
81                                                                                  +"/"+InetAddress.getLocalHost().getHostAddress()
82 <                                                                                +" port "+listenPort.getLocalPort());
83 <                }
84 <                catch(UnknownHostException e){
82 >                                                                                +" port "+listenSocket.getLocalPort());
83 >            
84 >        }
85 >        catch(UnknownHostException e){
86                          _logger.write(toString(), Logger.SYSMSG, "Server listening on UnknownHost "
87 <                                                                                +"port "+listenPort.getLocalPort());
87 >                                                                                +"port "+listenSocket.getLocalPort());
88                  }
89 +        catch(IOException e){
90 +            _logger.write(toString(), Logger.FATAL, "IO Error, can't start FilterManager :"+e);
91 +            run = false;
92 +        }
93 +        catch(PropertyNotFoundException e){
94 +            _logger.write(toString(), Logger.FATAL, "Fatal Error, can't find config :"+e);
95 +            run = false;
96 +        }
97 +        catch(NumberFormatException e){
98 +            _logger.write(toString(), Logger.FATAL, "Invalid port configuration found :"+e);
99 +            run = false;
100 +        }
101 +
102                  // Loop round constantly until we decide to stop
103          while(run){
104              Socket hostSocket=null;
105              try{
106                  _logger.write(toString(), Logger.SYSMSG, "Waiting for Connection");
107                                  // This will block until a host connects - at which point we get a Socket
108 <                hostSocket = listenPort.accept();
108 >                hostSocket = listenSocket.accept();
109                  _logger.write(toString(), Logger.SYSMSG, "Connection accepted from: " + hostSocket.toString());
110              }
111              catch(IOException e){
# Line 97 | Line 116 | class HostListener extends Thread {
116              if(run){
117                                  try {
118                                      // Setup the HostInit so it can carry on communications with the host
119 <                    HostInit init = new HostInit(hostSocket, _configManager, _logger, _ncRef);
119 >                    HostInit init = new HostInit(hostSocket);
120                                      // and start it
121                      init.start();
122                  } catch (IOException e) {
# Line 113 | Line 132 | class HostListener extends Thread {
132       * Overrides the {@link java.lang.Object#toString() Object.toString()}
133       * method to provide clean logging (every class should have this).
134       *
135 +     * This uses the uk.org.iscream.cms.server.util.NameFormat class
136 +     * to format the toString()
137 +     *
138       * @return the name of this class and its CVS revision
139       */
140      public String toString() {
141 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
141 >        return FormatName.getName(
142 >            _name,
143 >            this.getClass().getName(),
144 >            REVISION);
145      }
146  
147   //---PRIVATE METHODS---
# Line 126 | Line 151 | class HostListener extends Thread {
151   //---ATTRIBUTES---
152      
153      /**
154 <     * A reference to the logger the system is using
154 >     * This holds a reference to the
155 >     * system logger that is being used.
156       */
157 <    Logger _logger;
157 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
158      
159      /**
160 <     * A reference to the configurator the system is using
160 >     * This is the friendly identifier of the
161 >     * component this class is running in.
162 >     * eg, a Filter may be called "filter1",
163 >     * If this class does not have an owning
164 >     * component,  a name from the configuration
165 >     * can be placed here.  This name could also
166 >     * be changed to null for utility classes.
167       */
168 <    ConfigurationManager _configManager;
137 <    
138 <    /**
139 <         * The port on which the server should listen.
140 <         */
141 <    private int _port;
142 <    
143 <    private NamingContextExt _ncRef;
168 >    private String _name = FilterManager.NAME;
169      
170   //---STATIC ATTRIBUTES---
171  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines