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.8 by tdb, Sat Jan 27 23:30:40 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 27 | Line 46 | class TCPClientListener extends Thread {
46       */
47      public final String REVISION = "$Revision$";
48      
49 +    public static final int DEFPORT = 4510;
50 +    
51   //---STATIC METHODS---
52  
53   //---CONSTRUCTORS---
# Line 34 | Line 55 | class TCPClientListener extends Thread {
55          /**
56       * Constructs a new TCPClientListener
57       *
58 <         * @param port The port that the server will listen on.
38 <         * @param queue A Queue to utilise
58 >         * @param packetSorter A reference to the PacketSorter
59           */
60 <    public TCPClientListener(int port, PacketSorter packetSorter) {
61 <        _port = port;
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      }
# Line 53 | Line 75 | class TCPClientListener extends Thread {
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 74 | Line 112 | class TCPClientListener 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 105 | Line 166 | class TCPClientListener 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 139 | Line 200 | class TCPClientListener extends Thread {
200       * system logger that is being used.
201       */
202      private Logger _logger = ReferenceManager.getInstance().getLogger();
142
143    /**
144         * The port on which the server should listen.
145         */
146    private int _port;
203      
204      /**
205           * A reference to the PacketSorter.
206           */
207      private PacketSorter _packetSorter;
208 <
208 >    
209   //---STATIC ATTRIBUTES---
210  
211   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines