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.3 by tdb, Thu Jan 18 23:08:42 2001 UTC vs.
Revision 1.16 by tdb, Sat May 18 18:16:01 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 < package uk.ac.ukc.iscream.clientinterface;
21 > package uk.org.iscream.cms.server.clientinterface;
22  
23   //---IMPORTS---
24 < import uk.ac.ukc.iscream.util.*;
25 < import uk.ac.ukc.iscream.core.*;
26 < import uk.ac.ukc.iscream.componentmanager.*;
24 > import uk.org.iscream.cms.server.util.*;
25 > import uk.org.iscream.cms.server.core.*;
26 > import uk.org.iscream.cms.server.componentmanager.*;
27   import java.io.IOException;
28   import java.net.Socket;
29   import java.net.ServerSocket;
# Line 12 | Line 31 | import java.net.InetAddress;
31   import java.net.UnknownHostException;
32  
33   /**
34 < * Listener for incoming clients.
35 < * Creates a local implementation of the ClientHandler interface
17 < * and registers this with the ClientInterfaceServant. It then
18 < * returns a "reference" to this ClientHandler back to the client.
34 > * Listener for incoming TCP clients, and startup a Handler
35 > * a connection is received.
36   *
37   * @author  $Author$
38   * @version $Id$
39   */
40 < class ClientListener extends Thread {
40 > class TCPClientListener extends Thread {
41  
42   //---FINAL ATTRIBUTES---
43  
# Line 29 | Line 46 | class ClientListener extends Thread {
46       */
47      public final String REVISION = "$Revision$";
48      
49 +    public static final int DEFPORT = 4510;
50 +    
51   //---STATIC METHODS---
52  
53   //---CONSTRUCTORS---
54  
55          /**
56 <     * Constructs a new ClientListener
56 >     * Constructs a new TCPClientListener
57       *
58 <         * @param port The port that the server will listen on.
40 <         * @param clit A reference to the ClientInterfaceServant.
58 >         * @param packetSorter A reference to the PacketSorter
59           */
60 <    public ClientListener(int port, ClientInterfaceServant cli) {
61 <        _port = port;
62 <        _cli = cli;
60 >    public TCPClientListener(PacketSorter packetSorter) {
61 >        // set the Thread name
62 >        setName("clientinterface.TCPClientListener");
63 >        
64 >        _packetSorter = packetSorter;
65          _logger.write(toString(), Logger.SYSINIT, "started");
66      }
67  
# Line 52 | Line 72 | class ClientListener extends Thread {
72           * will remain in here until such a point as something goes
73           * wrong with the listening. After initially setting up the
74           * ServerSocket we go round a while loop receiving connections
75 <         * and then passing them off to other processes to deal with.
75 >         * and then passing them off to handler processes to deal with.
76           */
77      public void run(){
78 +        // setup an empty ACL defaulting to ALLOW
79 +        ACL acl = new ACL(ACL.ALLOW);
80 +        
81 +        // get our port
82 +        int portNum;
83 +        try {
84 +            String port = ConfigurationProxy.getInstance().getProperty("ClientInterface", "ClientInterface.listenPort");
85 +            portNum = Integer.parseInt(port);
86 +        } catch (PropertyNotFoundException e) {
87 +            portNum = DEFPORT;
88 +            _logger.write(toString(), Logger.WARNING, "Configuration not found, using default of "+portNum+" : "+e);
89 +        } catch (NumberFormatException e) {
90 +            portNum = DEFPORT;
91 +            _logger.write(toString(), Logger.WARNING, "Bad configuration found, using default of "+portNum+" : "+e);
92 +        }
93 +        
94          ServerSocket listenPort=null;
95                  // We use this boolean so we can break out of the while loop if we want
96          boolean run = true;
97          try{
98                          // Setup the ServerSocket so that clients can connect
99 <            listenPort = new ServerSocket(_port);
99 >                        listenPort = new ACLServerSocket(acl, portNum);
100          }
101          catch(IOException e){
102          }
# Line 76 | Line 112 | class ClientListener extends Thread {
112                                                                                  +"port "+listenPort.getLocalPort());
113                  }
114                  // Loop round constantly until we decide to stop
115 +                ConfigurationProxy cp = ConfigurationProxy.getInstance();
116 +        String stringACL = "";
117 +        String newStringACL = "";
118          while(run){
119 +            // get hold of the ACL in the configuration
120 +            try {
121 +                newStringACL = cp.getProperty("ClientInterface", "ClientInterface.TCPControlChannelACL");
122 +            }
123 +            catch(PropertyNotFoundException e) {
124 +                // if we can't find it, we'll just use a null ACL
125 +                newStringACL = "";
126 +                _logger.write(toString(), Logger.WARNING, "No ACL found for ClientInterface (control channel listener), using empty ACL instead: " + e);
127 +            }
128 +            // check to see if the ACL has changed
129 +            if(!newStringACL.equals(stringACL)) {
130 +                _logger.write(toString(), Logger.SYSMSG, "Reloading Access Control List");
131 +                // clear the ACL
132 +                acl.clear();
133 +                // set the default to something sane
134 +                acl.setDefaultMode(ACL.ALLOW);
135 +                // add the new ACL (this may change the default)
136 +                acl.add(newStringACL);
137 +                stringACL = newStringACL;
138 +            }
139              Socket hostSocket=null;
140              try{
141                  _logger.write(toString(), Logger.SYSMSG, "Waiting for Connection");
# Line 91 | Line 150 | class ClientListener extends Thread {
150                          // If we've stopped on the line above we won't want to try this !
151              if(run){
152                                  try {
153 <                                    // Setup the HostInit so it can carry on communications with the host
154 <                                    ClientHandler handler = new TCPClientHandler(hostSocket, _cli);
155 <                                    // register it
97 <                                    _cli.register(handler);
98 <                                    // then we can leave here.... I trust handler won't go out of scope !
153 >                                    // start up a ControlHandler to chat to the new Client
154 >                                    TCPControlHandler ctl = new TCPControlHandler(hostSocket, _packetSorter);
155 >                                    ctl.start();
156                  } catch (IOException e) {
157                      _logger.write(toString(), Logger.ERROR, e.toString());
158                  }
# Line 109 | Line 166 | class ClientListener extends Thread {
166       * Overrides the {@link java.lang.Object#toString() Object.toString()}
167       * method to provide clean logging (every class should have this).
168       *
169 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
169 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
170       * to format the toString()
171       *
172       * @return the name of this class and its CVS revision
# Line 143 | Line 200 | class ClientListener extends Thread {
200       * system logger that is being used.
201       */
202      private Logger _logger = ReferenceManager.getInstance().getLogger();
146
147    /**
148         * The port on which the server should listen.
149         */
150    private int _port;
203      
204      /**
205 <         * A reference to the ClientInterfaceServant.
205 >         * A reference to the PacketSorter.
206           */
207 <    private ClientInterfaceServant _cli;
208 <
207 >    private PacketSorter _packetSorter;
208 >    
209   //---STATIC ATTRIBUTES---
210  
211   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines