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

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/HostListener.java (file contents):
Revision 1.2 by tdb, Wed Nov 29 19:19:12 2000 UTC vs.
Revision 1.6 by tdb, Tue Mar 13 02:19:47 2001 UTC

# Line 3 | Line 3 | package uk.ac.ukc.iscream.filtermanager;
3  
4   //---IMPORTS---
5   import uk.ac.ukc.iscream.core.*;
6 + import uk.ac.ukc.iscream.componentmanager.*;
7   import uk.ac.ukc.iscream.filter.*;
8 < import java.net.Socket;
9 < import java.net.ServerSocket;
10 < import java.io.OutputStream;
10 < import java.io.IOException;
11 < import java.net.InetAddress;
12 < import java.net.UnknownHostException;
13 < import org.omg.CORBA.*;
14 < import org.omg.CosNaming.*;
8 > import uk.ac.ukc.iscream.util.*;
9 > import java.net.*;
10 > import java.io.*;
11  
12   /**
13   * A socket listener to listen for new hosts registering with the system.
# Line 37 | Line 33 | class HostListener extends Thread {
33          /**
34       * Constructs a new listener
35       *
36 <     * @param logger a reference to the logger we are using
41 <     * @param configManager a reference to the ConfigurationManager we are using
42 <         * @param port The port that the server will listen on.
36 >         * @param listenPort The port that the server will listen on.
37           */
38 <    public HostListener(Logger logger, ConfigurationManager configManager, int port, NamingContextExt ncRef) {
39 <        _logger = logger;
40 <        _ncRef = ncRef;
41 <        _configManager = configManager;
42 <        _port = port;
38 >    public HostListener(int listenPort) {
39 >        // set the Thread name
40 >        setName("filtermanager.HostListener");
41 >        
42 >        _listenPort = listenPort;
43          _logger.write(toString(), Logger.SYSINIT, "started");
44      }
45  
# Line 61 | Line 55 | class HostListener extends Thread {
55           * and then passing them off to other processes to deal with.
56           */
57      public void run(){
58 <        ServerSocket listenPort=null;
58 >        ServerSocket listenSocket=null;
59                  // We use this boolean so we can break out of the while loop if we want
60          boolean run = true;
61          try{
62                          // Setup the ServerSocket so that clients can connect
63 <            listenPort = new ServerSocket(_port);
63 >            listenSocket = new ServerSocket(_listenPort);
64          }
65          catch(IOException e){
66          }
# Line 75 | Line 69 | class HostListener extends Thread {
69                          _logger.write(toString(), Logger.SYSMSG, "Server listening on "
70                                                                                  +InetAddress.getLocalHost().getHostName()
71                                                                                  +"/"+InetAddress.getLocalHost().getHostAddress()
72 <                                                                                +" port "+listenPort.getLocalPort());
72 >                                                                                +" port "+listenSocket.getLocalPort());
73                  }
74                  catch(UnknownHostException e){
75                          _logger.write(toString(), Logger.SYSMSG, "Server listening on UnknownHost "
76 <                                                                                +"port "+listenPort.getLocalPort());
76 >                                                                                +"port "+listenSocket.getLocalPort());
77                  }
78                  // Loop round constantly until we decide to stop
79          while(run){
# Line 87 | Line 81 | class HostListener extends Thread {
81              try{
82                  _logger.write(toString(), Logger.SYSMSG, "Waiting for Connection");
83                                  // This will block until a host connects - at which point we get a Socket
84 <                hostSocket = listenPort.accept();
84 >                hostSocket = listenSocket.accept();
85                  _logger.write(toString(), Logger.SYSMSG, "Connection accepted from: " + hostSocket.toString());
86              }
87              catch(IOException e){
# Line 98 | Line 92 | class HostListener extends Thread {
92              if(run){
93                                  try {
94                                      // Setup the HostInit so it can carry on communications with the host
95 <                    HostInit init = new HostInit(hostSocket, _configManager, _logger, _ncRef);
95 >                    HostInit init = new HostInit(hostSocket);
96                                      // and start it
97                      init.start();
98                  } catch (IOException e) {
# Line 114 | Line 108 | class HostListener extends Thread {
108       * Overrides the {@link java.lang.Object#toString() Object.toString()}
109       * method to provide clean logging (every class should have this).
110       *
111 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
112 +     * to format the toString()
113 +     *
114       * @return the name of this class and its CVS revision
115       */
116      public String toString() {
117 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
117 >        return FormatName.getName(
118 >            _name,
119 >            this.getClass().getName(),
120 >            REVISION);
121      }
122  
123   //---PRIVATE METHODS---
# Line 127 | Line 127 | class HostListener extends Thread {
127   //---ATTRIBUTES---
128      
129      /**
130 <     * A reference to the logger the system is using
130 >     * This holds a reference to the
131 >     * system logger that is being used.
132       */
133 <    Logger _logger;
133 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
134      
135      /**
136 <     * A reference to the configurator the system is using
136 >     * This is the friendly identifier of the
137 >     * component this class is running in.
138 >     * eg, a Filter may be called "filter1",
139 >     * If this class does not have an owning
140 >     * component,  a name from the configuration
141 >     * can be placed here.  This name could also
142 >     * be changed to null for utility classes.
143       */
144 <    ConfigurationManager _configManager;
144 >    private String _name = FilterManager.NAME;
145      
146      /**
147           * The port on which the server should listen.
148           */
149 <    private int _port;
143 <    
144 <    private NamingContextExt _ncRef;
149 >    private int _listenPort;
150      
151   //---STATIC ATTRIBUTES---
152  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines