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

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/TCPReader.java (file contents):
Revision 1.13 by tdb, Tue Mar 19 17:22:12 2002 UTC vs.
Revision 1.17 by tdb, Sat May 18 18:16:02 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.org.iscream.cms.server.filter;
22  
# Line 32 | Line 51 | class TCPReader extends Thread {
51  
52   //---CONSTRUCTORS---
53  
54 <        /**
54 >    /**
55       * Constructs a new TCPReader
56       *
57       * @param queue A reference to our Queue
58 <         * @param port The port that the TCPReader will listen on
59 <         */
58 >     * @param port The port that the TCPReader will listen on
59 >     */
60      public TCPReader(int port, Queue queue) {
61          // set the Thread name
62          setName("filter.TCPReader");
# Line 51 | Line 70 | class TCPReader extends Thread {
70  
71   //---PUBLIC METHODS---
72  
73 <        /**
74 <         * The run() method is the main loop for this thread, and we
75 <         * will remain in here until such a point as something goes
76 <         * wrong with the listening. After initially setting up the
77 <         * ServerSocket we go round a while loop receiving connections
78 <         * and then passing them off to other processes to deal with.
79 <         */
73 >    /**
74 >     * The run() method is the main loop for this thread, and we
75 >     * will remain in here until such a point as something goes
76 >     * wrong with the listening. After initially setting up the
77 >     * ServerSocket we go round a while loop receiving connections
78 >     * and then passing them off to other processes to deal with.
79 >     */
80      public void run(){
81 <        // get our ACL from the configuration
82 <        ACL tcpACL = null;
83 <        try {
84 <            String stringACL = ConfigurationProxy.getInstance().getProperty(FilterMain.NAME, "Filter.TCPACL");
85 <            tcpACL = new ACL(stringACL);
81 >        // setup an empty ACL defaulting to ALLOW
82 >        ACL acl = new ACL(ACL.ALLOW);
83 >        
84 >        // Setup the ServerSocket so that clients can connect
85 >        ServerSocket listenPort=null;
86 >        try{
87 >            listenPort = new ACLServerSocket(acl, _port);
88          }
89 <        catch(PropertyNotFoundException e) {
90 <            _logger.write(toString(), Logger.WARNING, "No ACL found for TCPReader: " + e);
89 >        catch(IOException e){
90 >            _logger.write(toString(), Logger.FATAL, "Failed to setup ServerSocket: " + e);
91 >            return;
92          }
93 <                
94 <                ServerSocket listenPort=null;
93 >        
94 >        // Log what machine/port we're listening on
95          try{
96 <                        // Setup the ServerSocket so that clients can connect
97 <                        // use an ACLServerSocket if we have an ACL
98 <                        if(tcpACL != null) {
99 <                            listenPort = new ACLServerSocket(tcpACL, _port);
78 <                        }
79 <                        else {
80 <                listenPort = new ServerSocket(_port);
81 <            }
96 >            _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on "
97 >                                        +InetAddress.getLocalHost().getHostName()
98 >                                        +"/"+InetAddress.getLocalHost().getHostAddress()
99 >                                        +" port "+listenPort.getLocalPort());
100          }
101 <        catch(IOException e){
101 >        catch(UnknownHostException e){
102 >            _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on UnknownHost "
103 >                                        +"port "+listenPort.getLocalPort());
104          }
105          
106 <                // Log what machine/port we're listening on
87 <                try{
88 <                        _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on "
89 <                                                                                +InetAddress.getLocalHost().getHostName()
90 <                                                                                +"/"+InetAddress.getLocalHost().getHostAddress()
91 <                                                                                +" port "+listenPort.getLocalPort());
92 <                }
93 <                catch(UnknownHostException e){
94 <                        _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on UnknownHost "
95 <                                                                                +"port "+listenPort.getLocalPort());
96 <                }
97 <                
98 <                // We use this boolean so we can break out of the while loop if we want
106 >        // We use this boolean so we can break out of the while loop if we want
107          boolean run = true;
108 <                
109 <                // Loop round constantly until we decide to stop
108 >        
109 >        // Loop round constantly until we decide to stop
110 >        ConfigurationProxy cp = ConfigurationProxy.getInstance();
111 >        String stringACL = "";
112 >        String newStringACL = "";
113          while(run){
114 <            Socket hostSocket=null;
114 >            // get hold of the ACL in the configuration
115 >            try {
116 >                newStringACL = cp.getProperty("Filter." + FilterMain.NAME, "Filter.TCPACL");
117 >            }
118 >            catch(PropertyNotFoundException e) {
119 >                // if we can't find it, we'll just use a null ACL
120 >                newStringACL = "";
121 >                _logger.write(toString(), Logger.WARNING, "No ACL found for TCPReader, using empty ACL instead: " + e);
122 >            }
123 >            // check to see if the ACL has changed
124 >            if(!newStringACL.equals(stringACL)) {
125 >                _logger.write(toString(), Logger.SYSMSG, "Reloading Access Control List");
126 >                // clear the ACL
127 >                acl.clear();
128 >                // set the default to something sane
129 >                acl.setDefaultMode(ACL.ALLOW);
130 >                // add the new ACL (this may change the default)
131 >                acl.add(newStringACL);
132 >                stringACL = newStringACL;
133 >            }
134 >            Socket hostSocket=null;
135              try{
136                  _logger.write(toString(), Logger.DEBUG, "Waiting for Connection");
137 <                                // This will block until a host connects - at which point we get a Socket
137 >                // This will block until a host connects - at which point we get a Socket
138                  hostSocket = listenPort.accept();
139                  _logger.write(toString(), Logger.DEBUG, "Connection accepted from: " + hostSocket.toString());
140              }
141              catch(IOException e){
142 <                                // Something went wrong with the ServerSocket, so we'll stop listening
142 >                // Something went wrong with the ServerSocket, so we'll stop listening
143                  run=false;
144              }
145 <                        // If we've stopped on the line above we won't want to try this !
145 >            // If we've stopped on the line above we won't want to try this !
146              if(run){
147 <                                try {
148 <                                    // Setup the TCPReaderInit and start it
147 >                try {
148 >                    // Setup the TCPReaderInit and start it
149                      TCPReaderInit init = new TCPReaderInit(hostSocket, _queue);
150 <                                    // and start it
150 >                    // and start it
151                      init.start();
152                  } catch (IOException e) {
153                      _logger.write(toString(), Logger.ERROR, e.toString());
154                  }
155              }
156          }
157 <                // Best log the fact that we're stopping
157 >        // Best log the fact that we're stopping
158          _logger.write(toString(), Logger.FATAL, "Fatal error, shutdown pending");
159      }
160  
# Line 167 | Line 198 | class TCPReader extends Thread {
198      private Logger _logger = ReferenceManager.getInstance().getLogger();
199      
200      /**
201 <         * The port on which the server should listen.
202 <         */
201 >     * The port on which the server should listen.
202 >     */
203      private int _port;
204      
205      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines