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.13 by tdb, Tue Mar 19 17:22:12 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.filter;
2 > package uk.org.iscream.cms.server.filter;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.core.*;
6 < import uk.ac.ukc.iscream.filter.*;
5 > import uk.org.iscream.cms.server.core.*;
6 > import uk.org.iscream.cms.server.componentmanager.*;
7 > import uk.org.iscream.cms.server.filter.*;
8   import java.net.Socket;
9   import java.net.ServerSocket;
10   import java.io.OutputStream;
11   import java.io.IOException;
12   import java.net.InetAddress;
13   import java.net.UnknownHostException;
14 < import org.omg.CORBA.*;
14 < import org.omg.CosNaming.*;
15 < import uk.ac.ukc.iscream.util.*;
14 > import uk.org.iscream.cms.server.util.*;
15  
16   /**
17 < * 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.
17 > * Reads TCP Heartbeats from the host applications.
18   *
19   * @author  $Author$
20   * @version $Id$
# Line 36 | Line 33 | class TCPReader extends Thread {
33   //---CONSTRUCTORS---
34  
35          /**
36 <     * Constructs a new listener
36 >     * Constructs a new TCPReader
37       *
38 <     * @param logger a reference to the logger we are using
39 <     * @param configManager a reference to the ConfigurationManager we are using
43 <         * @param port The port that the server will listen on.
38 >     * @param queue A reference to our Queue
39 >         * @param port The port that the TCPReader will listen on
40           */
41 <    public TCPReader(int port, Filter parent) {
41 >    public TCPReader(int port, Queue queue) {
42 >        // set the Thread name
43 >        setName("filter.TCPReader");
44 >        
45          _port = port;
46 <        _parent = parent;
46 >        _queue = queue;
47          _logger.write(toString(), Logger.SYSINIT, "started");
48      }
49  
# Line 60 | Line 59 | class TCPReader extends Thread {
59           * and then passing them off to other processes to deal with.
60           */
61      public void run(){
62 <        ServerSocket listenPort=null;
63 <                // We use this boolean so we can break out of the while loop if we want
64 <        boolean run = true;
62 >        // get our ACL from the configuration
63 >        ACL tcpACL = null;
64 >        try {
65 >            String stringACL = ConfigurationProxy.getInstance().getProperty(FilterMain.NAME, "Filter.TCPACL");
66 >            tcpACL = new ACL(stringACL);
67 >        }
68 >        catch(PropertyNotFoundException e) {
69 >            _logger.write(toString(), Logger.WARNING, "No ACL found for TCPReader: " + e);
70 >        }
71 >                
72 >                ServerSocket listenPort=null;
73          try{
74                          // Setup the ServerSocket so that clients can connect
75 <            listenPort = new ServerSocket(_port);
75 >                        // use an ACLServerSocket if we have an ACL
76 >                        if(tcpACL != null) {
77 >                            listenPort = new ACLServerSocket(tcpACL, _port);
78 >                        }
79 >                        else {
80 >                listenPort = new ServerSocket(_port);
81 >            }
82          }
83          catch(IOException e){
84          }
85 +        
86                  // Log what machine/port we're listening on
87                  try{
88                          _logger.write(toString(), Logger.SYSMSG, "TCPReader listening on "
# Line 80 | Line 94 | class TCPReader extends Thread {
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
99 +        boolean run = true;
100 +                
101                  // Loop round constantly until we decide to stop
102          while(run){
103              Socket hostSocket=null;
104              try{
105 <                _logger.write(toString(), Logger.SYSMSG, "Waiting for Connection");
105 >                _logger.write(toString(), Logger.DEBUG, "Waiting for Connection");
106                                  // This will block until a host connects - at which point we get a Socket
107                  hostSocket = listenPort.accept();
108 <                _logger.write(toString(), Logger.SYSMSG, "Connection accepted from: " + hostSocket.toString());
108 >                _logger.write(toString(), Logger.DEBUG, "Connection accepted from: " + hostSocket.toString());
109              }
110              catch(IOException e){
111                                  // Something went wrong with the ServerSocket, so we'll stop listening
# Line 96 | Line 114 | class TCPReader extends Thread {
114                          // If we've stopped on the line above we won't want to try this !
115              if(run){
116                                  try {
117 <                                    // Setup the HostInit so it can carry on communications with the host
118 <                    TCPReaderInit init = new TCPReaderInit(hostSocket, _parent);
117 >                                    // Setup the TCPReaderInit and start it
118 >                    TCPReaderInit init = new TCPReaderInit(hostSocket, _queue);
119                                      // and start it
120                      init.start();
121                  } catch (IOException e) {
# Line 113 | Line 131 | class TCPReader extends Thread {
131       * Overrides the {@link java.lang.Object#toString() Object.toString()}
132       * method to provide clean logging (every class should have this).
133       *
134 +     * This uses the uk.org.iscream.cms.server.util.NameFormat class
135 +     * to format the toString()
136 +     *
137       * @return the name of this class and its CVS revision
138       */
139      public String toString() {
140 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
140 >        return FormatName.getName(
141 >            _name,
142 >            getClass().getName(),
143 >            REVISION);
144      }
145  
146   //---PRIVATE METHODS---
# Line 126 | Line 150 | class TCPReader extends Thread {
150   //---ATTRIBUTES---
151      
152      /**
153 <     * A reference to the logger the system is using
153 >     * This is the friendly identifier of the
154 >     * component this class is running in.
155 >     * eg, a Filter may be called "filter1",
156 >     * If this class does not have an owning
157 >     * component,  a name from the configuration
158 >     * can be placed here.  This name could also
159 >     * be changed to null for utility classes.
160       */
161 <    Logger _logger = ReferenceManager.getInstance().getLogger();
161 >    private String _name = FilterMain.NAME;
162 >
163 >    /**
164 >     * This holds a reference to the
165 >     * system logger that is being used.
166 >     */
167 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
168      
169      /**
170           * The port on which the server should listen.
171           */
172      private int _port;
173      
174 <    private Filter _parent;
174 >    /**
175 >     * A reference to our Queue
176 >     */
177 >    private Queue _queue;
178      
179   //---STATIC ATTRIBUTES---
180  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines