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.4 by ajm, Thu Nov 30 02:38:09 2000 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.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 org.omg.CORBA.*;
14 < import org.omg.CosNaming.*;
15 < import uk.ac.ukc.iscream.util.*;
33 > import uk.org.iscream.cms.server.util.*;
34  
35   /**
36 < * A socket listener to listen for new hosts registering with the system.
19 < * When a host makes a connection, the connecton is past to an instance
20 < * of the HostInit class, which handles further communication.
36 > * Reads TCP Heartbeats from the host applications.
37   *
38   * @author  $Author$
39   * @version $Id$
# Line 35 | Line 51 | class TCPReader extends Thread {
51  
52   //---CONSTRUCTORS---
53  
54 <        /**
55 <     * Constructs a new listener
54 >    /**
55 >     * Constructs a new TCPReader
56       *
57 <     * @param logger a reference to the logger we are using
58 <     * @param configManager a reference to the ConfigurationManager we are using
59 <         * @param port The port that the server will listen on.
60 <         */
61 <    public TCPReader(int port, Filter parent) {
57 >     * @param queue A reference to our Queue
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 <        _parent = parent;
65 >        _queue = queue;
66          _logger.write(toString(), Logger.SYSINIT, "started");
67      }
68  
# Line 52 | 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;
64                // We use this boolean so we can break out of the while loop if we want
65        boolean run = true;
86          try{
87 <                        // Setup the ServerSocket so that clients can connect
68 <            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.SYSMSG, "Waiting for Connection");
137 <                                // This will block until a host connects - at which point we get a Socket
136 >                _logger.write(toString(), Logger.DEBUG, "Waiting for Connection");
137 >                // This will block until a host connects - at which point we get a Socket
138                  hostSocket = listenPort.accept();
139 <                _logger.write(toString(), Logger.SYSMSG, "Connection accepted from: " + hostSocket.toString());
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 HostInit so it can carry on communications with the host
149 <                    TCPReaderInit init = new TCPReaderInit(hostSocket, _parent);
150 <                                    // and start it
147 >                try {
148 >                    // Setup the TCPReaderInit and start it
149 >                    TCPReaderInit init = new TCPReaderInit(hostSocket, _queue);
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 113 | 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.org.iscream.cms.server.util.NameFormat class
166 +     * to format the toString()
167 +     *
168       * @return the name of this class and its CVS revision
169       */
170      public String toString() {
171 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
171 >        return FormatName.getName(
172 >            _name,
173 >            getClass().getName(),
174 >            REVISION);
175      }
176  
177   //---PRIVATE METHODS---
# Line 126 | Line 181 | class TCPReader extends Thread {
181   //---ATTRIBUTES---
182      
183      /**
184 <     * A reference to the logger the system is using
184 >     * This is the friendly identifier of the
185 >     * component this class is running in.
186 >     * eg, a Filter may be called "filter1",
187 >     * If this class does not have an owning
188 >     * component,  a name from the configuration
189 >     * can be placed here.  This name could also
190 >     * be changed to null for utility classes.
191       */
192 <    Logger _logger = ReferenceManager.getInstance().getLogger();
192 >    private String _name = FilterMain.NAME;
193 >
194 >    /**
195 >     * This holds a reference to the
196 >     * system logger that is being used.
197 >     */
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 <    private Filter _parent;
205 >    /**
206 >     * A reference to our Queue
207 >     */
208 >    private Queue _queue;
209      
210   //---STATIC ATTRIBUTES---
211  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines