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.9 by tdb, Thu Feb 1 00:18:42 2001 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.ac.ukc.iscream.filter;
21 > package uk.org.iscream.cms.server.filter;
22  
23   //---IMPORTS---
24 < import uk.ac.ukc.iscream.core.*;
25 < import uk.ac.ukc.iscream.componentmanager.*;
26 < import uk.ac.ukc.iscream.filter.*;
24 > import uk.org.iscream.cms.server.core.*;
25 > import uk.org.iscream.cms.server.componentmanager.*;
26 > import uk.org.iscream.cms.server.filter.*;
27   import java.net.Socket;
28   import java.net.ServerSocket;
29   import java.io.OutputStream;
30   import java.io.IOException;
31   import java.net.InetAddress;
32   import java.net.UnknownHostException;
33 < import uk.ac.ukc.iscream.util.*;
33 > import uk.org.iscream.cms.server.util.*;
34  
35   /**
36   * Reads TCP Heartbeats from the host applications.
# 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");
63 +        
64          _port = port;
65          _queue = queue;
66          _logger.write(toString(), Logger.SYSINIT, "started");
# Line 48 | 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 +        // 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;
60                // We use this boolean so we can break out of the while loop if we want
61        boolean run = true;
86          try{
87 <                        // Setup the ServerSocket so that clients can connect
64 <            listenPort = new ServerSocket(_port);
87 >            listenPort = new ACLServerSocket(acl, _port);
88          }
89          catch(IOException e){
90 +            _logger.write(toString(), Logger.FATAL, "Failed to setup ServerSocket: " + e);
91 +            return;
92          }
93 <                // Log what machine/port we're listening on
94 <                try{
95 <                        _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on "
96 <                                                                                +InetAddress.getLocalHost().getHostName()
97 <                                                                                +"/"+InetAddress.getLocalHost().getHostAddress()
98 <                                                                                +" port "+listenPort.getLocalPort());
99 <                }
100 <                catch(UnknownHostException e){
101 <                        _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on UnknownHost "
102 <                                                                                +"port "+listenPort.getLocalPort());
103 <                }
104 <                // Loop round constantly until we decide to stop
93 >        
94 >        // Log what machine/port we're listening on
95 >        try{
96 >            _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on "
97 >                                        +InetAddress.getLocalHost().getHostName()
98 >                                        +"/"+InetAddress.getLocalHost().getHostAddress()
99 >                                        +" port "+listenPort.getLocalPort());
100 >        }
101 >        catch(UnknownHostException e){
102 >            _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on UnknownHost "
103 >                                        +"port "+listenPort.getLocalPort());
104 >        }
105 >        
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
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 109 | Line 162 | class TCPReader extends Thread {
162       * Overrides the {@link java.lang.Object#toString() Object.toString()}
163       * method to provide clean logging (every class should have this).
164       *
165 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
165 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
166       * to format the toString()
167       *
168       * @return the name of this class and its CVS revision
# Line 145 | 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