ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/TCPClientListener.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/TCPClientListener.java (file contents):
Revision 1.6 by tdb, Mon Jan 22 02:57:38 2001 UTC vs.
Revision 1.15 by tdb, Thu Mar 21 13:01:21 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.clientinterface;
2 > package uk.org.iscream.cms.server.clientinterface;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.util.*;
6 < import uk.ac.ukc.iscream.core.*;
7 < import uk.ac.ukc.iscream.componentmanager.*;
5 > import uk.org.iscream.cms.server.util.*;
6 > import uk.org.iscream.cms.server.core.*;
7 > import uk.org.iscream.cms.server.componentmanager.*;
8   import java.io.IOException;
9   import java.net.Socket;
10   import java.net.ServerSocket;
# Line 12 | Line 12 | import java.net.InetAddress;
12   import java.net.UnknownHostException;
13  
14   /**
15 < * Listener for incoming clients.
15 > * Listener for incoming TCP clients, and startup a Handler
16 > * a connection is received.
17   *
18   * @author  $Author$
19   * @version $Id$
# Line 26 | Line 27 | class TCPClientListener extends Thread {
27       */
28      public final String REVISION = "$Revision$";
29      
30 +    public static final int DEFPORT = 4510;
31 +    
32   //---STATIC METHODS---
33  
34   //---CONSTRUCTORS---
# Line 33 | Line 36 | class TCPClientListener extends Thread {
36          /**
37       * Constructs a new TCPClientListener
38       *
39 <         * @param port The port that the server will listen on.
37 <         * @param queue A Queue to utilise
39 >         * @param packetSorter A reference to the PacketSorter
40           */
41 <    public TCPClientListener(int port, Queue queue) {
42 <        _port = port;
43 <        _queue = queue;
41 >    public TCPClientListener(PacketSorter packetSorter) {
42 >        // set the Thread name
43 >        setName("clientinterface.TCPClientListener");
44 >        
45 >        _packetSorter = packetSorter;
46          _logger.write(toString(), Logger.SYSINIT, "started");
47      }
48  
# Line 49 | Line 53 | class TCPClientListener extends Thread {
53           * will remain in here until such a point as something goes
54           * wrong with the listening. After initially setting up the
55           * ServerSocket we go round a while loop receiving connections
56 <         * and then passing them off to other processes to deal with.
56 >         * and then passing them off to handler processes to deal with.
57           */
58      public void run(){
59 +        // setup an empty ACL defaulting to ALLOW
60 +        ACL acl = new ACL(ACL.ALLOW);
61 +        
62 +        // get our port
63 +        int portNum;
64 +        try {
65 +            String port = ConfigurationProxy.getInstance().getProperty("ClientInterface", "ClientInterface.listenPort");
66 +            portNum = Integer.parseInt(port);
67 +        } catch (PropertyNotFoundException e) {
68 +            portNum = DEFPORT;
69 +            _logger.write(toString(), Logger.WARNING, "Configuration not found, using default of "+portNum+" : "+e);
70 +        } catch (NumberFormatException e) {
71 +            portNum = DEFPORT;
72 +            _logger.write(toString(), Logger.WARNING, "Bad configuration found, using default of "+portNum+" : "+e);
73 +        }
74 +        
75          ServerSocket listenPort=null;
76                  // We use this boolean so we can break out of the while loop if we want
77          boolean run = true;
78          try{
79                          // Setup the ServerSocket so that clients can connect
80 <            listenPort = new ServerSocket(_port);
80 >                        listenPort = new ACLServerSocket(acl, portNum);
81          }
82          catch(IOException e){
83          }
# Line 73 | Line 93 | class TCPClientListener extends Thread {
93                                                                                  +"port "+listenPort.getLocalPort());
94                  }
95                  // Loop round constantly until we decide to stop
96 +                ConfigurationProxy cp = ConfigurationProxy.getInstance();
97 +        String stringACL = "";
98 +        String newStringACL = "";
99          while(run){
100 +            // get hold of the ACL in the configuration
101 +            try {
102 +                newStringACL = cp.getProperty("ClientInterface", "ClientInterface.TCPControlChannelACL");
103 +            }
104 +            catch(PropertyNotFoundException e) {
105 +                // if we can't find it, we'll just use a null ACL
106 +                newStringACL = "";
107 +                _logger.write(toString(), Logger.WARNING, "No ACL found for ClientInterface (control channel listener), using empty ACL instead: " + e);
108 +            }
109 +            // check to see if the ACL has changed
110 +            if(!newStringACL.equals(stringACL)) {
111 +                _logger.write(toString(), Logger.SYSMSG, "Reloading Access Control List");
112 +                // clear the ACL
113 +                acl.clear();
114 +                // set the default to something sane
115 +                acl.setDefaultMode(ACL.ALLOW);
116 +                // add the new ACL (this may change the default)
117 +                acl.add(newStringACL);
118 +                stringACL = newStringACL;
119 +            }
120              Socket hostSocket=null;
121              try{
122                  _logger.write(toString(), Logger.SYSMSG, "Waiting for Connection");
# Line 88 | Line 131 | class TCPClientListener extends Thread {
131                          // If we've stopped on the line above we won't want to try this !
132              if(run){
133                                  try {
134 <                                    // Setup the HostInit so it can carry on communications with the host
135 <                                    TCPControlHandler ctl = new TCPControlHandler(hostSocket, _queue);
134 >                                    // start up a ControlHandler to chat to the new Client
135 >                                    TCPControlHandler ctl = new TCPControlHandler(hostSocket, _packetSorter);
136                                      ctl.start();
137                  } catch (IOException e) {
138                      _logger.write(toString(), Logger.ERROR, e.toString());
# Line 104 | Line 147 | class TCPClientListener extends Thread {
147       * Overrides the {@link java.lang.Object#toString() Object.toString()}
148       * method to provide clean logging (every class should have this).
149       *
150 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
150 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
151       * to format the toString()
152       *
153       * @return the name of this class and its CVS revision
# Line 138 | Line 181 | class TCPClientListener extends Thread {
181       * system logger that is being used.
182       */
183      private Logger _logger = ReferenceManager.getInstance().getLogger();
141
142    /**
143         * The port on which the server should listen.
144         */
145    private int _port;
184      
185      /**
186 <         * A reference to the Queue.
186 >         * A reference to the PacketSorter.
187           */
188 <    private Queue _queue;
189 <
188 >    private PacketSorter _packetSorter;
189 >    
190   //---STATIC ATTRIBUTES---
191  
192   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines