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.2 by ajm, Wed Dec 13 12:57:38 2000 UTC vs.
Revision 1.14 by tdb, Wed Mar 20 12:56:37 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.*;
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 11 | Line 12 | import java.net.InetAddress;
12   import java.net.UnknownHostException;
13  
14   /**
15 < * Listener for incoming clients.
16 < * Creates a local implementation of the ClientHandler interface
16 < * and registers this with the ClientInterfaceServant. It then
17 < * returns a "reference" to this ClientHandler back to the client.
15 > * Listener for incoming TCP clients, and startup a Handler
16 > * a connection is received.
17   *
18   * @author  $Author$
19   * @version $Id$
20   */
21 < class ClientListener extends Thread {
21 > class TCPClientListener extends Thread {
22  
23   //---FINAL ATTRIBUTES---
24  
# Line 28 | Line 27 | class ClientListener extends Thread {
27       */
28      public final String REVISION = "$Revision$";
29      
30 +    public static final int DEFPORT = 4510;
31 +    
32   //---STATIC METHODS---
33  
34   //---CONSTRUCTORS---
35  
36          /**
37 <     * Constructs a new ClientListener
37 >     * Constructs a new TCPClientListener
38       *
39 <         * @param port The port that the server will listen on.
39 <         * @param clit A reference to the ClientInterfaceServant.
39 >         * @param packetSorter A reference to the PacketSorter
40           */
41 <    public ClientListener(int port, ClientInterfaceServant cli) {
42 <        _port = port;
43 <        _cli = cli;
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 51 | Line 53 | class ClientListener 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 +        // get our ACL from the configuration
60 +        ACL acl = null;
61 +        try {
62 +            String stringACL = ConfigurationProxy.getInstance().getProperty("ClientInterface", "ClientInterface.TCPControlChannelACL");
63 +            acl = new ACL(stringACL);
64 +        }
65 +        catch(PropertyNotFoundException e) {
66 +            _logger.write(toString(), Logger.WARNING, "No ACL found for ClientInterface (control channel listener): " + e);
67 +        }
68 +        
69 +        // get our port
70 +        int portNum;
71 +        try {
72 +            String port = ConfigurationProxy.getInstance().getProperty("ClientInterface", "ClientInterface.listenPort");
73 +            portNum = Integer.parseInt(port);
74 +        } catch (PropertyNotFoundException e) {
75 +            portNum = DEFPORT;
76 +            _logger.write(toString(), Logger.WARNING, "Configuration not found, using default of "+portNum+" : "+e);
77 +        } catch (NumberFormatException e) {
78 +            portNum = DEFPORT;
79 +            _logger.write(toString(), Logger.WARNING, "Bad configuration found, using default of "+portNum+" : "+e);
80 +        }
81 +        
82          ServerSocket listenPort=null;
83                  // We use this boolean so we can break out of the while loop if we want
84          boolean run = true;
85          try{
86                          // Setup the ServerSocket so that clients can connect
87 <            listenPort = new ServerSocket(_port);
87 >                        // use an ACLServerSocket if we have an ACL
88 >                        if(acl != null) {
89 >                            listenPort = new ACLServerSocket(acl, portNum);
90 >                        }
91 >                        else {
92 >                listenPort = new ServerSocket(portNum);
93 >            }
94          }
95          catch(IOException e){
96          }
# Line 90 | Line 121 | class ClientListener extends Thread {
121                          // If we've stopped on the line above we won't want to try this !
122              if(run){
123                                  try {
124 <                                    // Setup the HostInit so it can carry on communications with the host
125 <                                    ClientHandler handler = new TCPClientHandler(hostSocket, _cli);
126 <                                    // register it
96 <                                    _cli.register(handler);
97 <                                    // then we can leave here.... I trust handler won't go out of scope !
124 >                                    // start up a ControlHandler to chat to the new Client
125 >                                    TCPControlHandler ctl = new TCPControlHandler(hostSocket, _packetSorter);
126 >                                    ctl.start();
127                  } catch (IOException e) {
128                      _logger.write(toString(), Logger.ERROR, e.toString());
129                  }
# Line 108 | Line 137 | class ClientListener extends Thread {
137       * Overrides the {@link java.lang.Object#toString() Object.toString()}
138       * method to provide clean logging (every class should have this).
139       *
140 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
140 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
141       * to format the toString()
142       *
143       * @return the name of this class and its CVS revision
# Line 142 | Line 171 | class ClientListener extends Thread {
171       * system logger that is being used.
172       */
173      private Logger _logger = ReferenceManager.getInstance().getLogger();
145
146    /**
147         * The port on which the server should listen.
148         */
149    private int _port;
174      
175      /**
176 <         * A reference to the ClientInterfaceServant.
176 >         * A reference to the PacketSorter.
177           */
178 <    private ClientInterfaceServant _cli;
179 <
178 >    private PacketSorter _packetSorter;
179 >    
180   //---STATIC ATTRIBUTES---
181  
182   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines