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/UDPReader.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/UDPReader.java (file contents):
Revision 1.5 by pjm2, Thu Nov 23 09:21:48 2000 UTC vs.
Revision 1.8 by tdb, Thu Nov 30 02:00:55 2000 UTC

# Line 1 | Line 1
1 + //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.iscream.filter;
3 +
4 + //---IMPORTS---
5   import java.io.*;
6   import java.net.*;
7   import java.util.*;
8   import uk.ac.ukc.iscream.core.*;
9   import uk.ac.ukc.iscream.filter.*;
10 + import uk.ac.ukc.iscream.refman.*;
11  
12 < // This class contains the main method to be run by
13 < // the filter children.  It harvests UDP traffic.
14 < //
12 > /**
13 > * This class contains the main method to be run by
14 > * the filter children.  It harvests UDP traffic.
15 > *
16 > * @author  $Author$
17 > * @version $Id$
18 > */
19   public class UDPReader extends Thread{
20  
21 + //---FINAL ATTRIBUTES---
22 +
23 +    /**
24 +     * The current CVS revision of this class
25 +     */
26 +    public final String REVISION = "$Revision$";
27 +    
28 + //---STATIC METHODS---
29 +
30 + //---CONSTRUCTORS---
31 +
32      // It is normal to use this constructor in preference
33      // to any other in this class.
34 <    public UDPReader(int port, Filter parent, Logger logger){
35 <        this.logger = logger;
36 <        this.port = port;
17 <        this.parent = parent;
34 >    public UDPReader(int port, Filter parent){
35 >        _port = port;
36 >        _parent = parent;
37      }
19    
20    public UDPReader(Filter parent, Logger logger){
21        this(4589, parent, logger);
22    }
38  
39 + //---PUBLIC METHODS---
40 +
41      public void run() {
42  
43          DatagramSocket socket = null;
44          try {
45 <            socket = new DatagramSocket(port);
45 >            socket = new DatagramSocket(_port);
46          }
47          catch (BindException e){
48 <            logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+port+" as this port was already in use.");
48 >            _logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+_port+" as this port was already in use.");
49              return;
50          }
51          catch (Exception e){
52 <            logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+port+".");
52 >            _logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+_port+".");
53              return;
54          }
55          
56 <        logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+port);
56 >        _logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+_port);
57  
58          byte[] buf;
59          
# Line 48 | Line 65 | public class UDPReader extends Thread{
65                  buf = new byte[packetSizeLimit];
66                  DatagramPacket packet = new DatagramPacket(buf, buf.length);
67                  socket.receive(packet);
68 <                FilterThread t = new FilterThread(packet, parent, logger);
68 >                FilterThread t = new FilterThread(packet, _parent);
69                  t.start();
70  
71              }
72              catch (IOException e) {
73 <                logger.write(this.toString(), Logger.WARNING, "This UDPReader thread has been shut down as an exception occured: "+e);
73 >                _logger.write(this.toString(), Logger.WARNING, "This UDPReader thread has been shut down as an exception occured: "+e);
74                  return;
75              }
76          }
77          socket.close();
78      }
62    
63    
64    Logger logger;
65    int port;
66    Filter parent;    
79  
80 +    /**
81 +     * Overrides the {@link java.lang.Object#toString() Object.toString()}
82 +     * method to provide clean logging (every class should have this).
83 +     *
84 +     * @return the name of this class and its CVS revision
85 +     */
86 +    public String toString() {
87 +        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
88 +    }
89 +
90 + //---PRIVATE METHODS---
91 +
92 + //---ACCESSOR/MUTATOR METHODS---
93 +
94 + //---ATTRIBUTES---
95 +
96 +    Logger _logger = ReferenceManager.getInstance().getLogger();
97 +    int _port;
98 +    Filter _parent;    
99 +
100      final int packetSizeLimit = 8192;
101 <    
101 >
102 > //---STATIC ATTRIBUTES---
103 >
104   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines