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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines