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.6 by tdb, Wed Nov 29 19:26:00 2000 UTC vs.
Revision 1.14 by tdb, Sun Jan 28 05:34:38 2001 UTC

# Line 6 | Line 6 | import java.io.*;
6   import java.net.*;
7   import java.util.*;
8   import uk.ac.ukc.iscream.core.*;
9 + import uk.ac.ukc.iscream.componentmanager.*;
10   import uk.ac.ukc.iscream.filter.*;
11 + import uk.ac.ukc.iscream.util.*;
12  
13   /**
14   * This class contains the main method to be run by
15 < * the filter children.  It harvests UDP traffic.
15 > * the filterd.  It harvests UDP traffic, and queues it.
16   *
17   * @author  $Author$
18   * @version $Id$
# Line 23 | Line 25 | public class UDPReader extends Thread{
25       * The current CVS revision of this class
26       */
27      public final String REVISION = "$Revision$";
28 +
29 +    /**
30 +     * The maximum size of a packet
31 +     */
32 +    private final int packetSizeLimit = 8192;  
33      
34   //---STATIC METHODS---
35  
36   //---CONSTRUCTORS---
37  
38 <    // It is normal to use this constructor in preference
39 <    // to any other in this class.
40 <    public UDPReader(int port, Filter parent, Logger logger){
41 <        this.logger = logger;
42 <        this.port = port;
43 <        this.parent = parent;
38 >    /**
39 >     * Constructs a new UDPReader.
40 >     *
41 >     * @param port The port on which we listen for UDP data
42 >     * @param queue The queue which we are using
43 >     */
44 >    public UDPReader(int port, Queue queue){
45 >        _port = port;
46 >        _queue = queue;
47      }
38    
39    public UDPReader(Filter parent, Logger logger){
40        this(4589, parent, logger);
41    }
48  
49   //---PUBLIC METHODS---
50 <
50 >    
51 >    /**
52 >     * The main method in the class. Reads and queues XML sent
53 >     * over UDP.
54 >     */
55      public void run() {
56 <
56 >        
57 >        // setup a Datagram socket
58          DatagramSocket socket = null;
59          try {
60 <            socket = new DatagramSocket(port);
60 >            socket = new DatagramSocket(_port);
61          }
62          catch (BindException e){
63 <            logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+port+" as this port was already in use.");
63 >            _logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+_port+" as this port was already in use.");
64              return;
65          }
66          catch (Exception e){
67 <            logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+port+".");
67 >            _logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+_port+".");
68              return;
69          }
70          
71 <        logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+port);
71 >        _logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+_port);
72  
73          byte[] buf;
74          
75 +        // read UDP packets and queue them
76          boolean running = true;
77          while (running){
78              try {
79  
80 <                    // receive request and pass on to the FilterThread.                
80 >                    // receive request and put it in the Queue              
81                  buf = new byte[packetSizeLimit];
82                  DatagramPacket packet = new DatagramPacket(buf, buf.length);
83                  socket.receive(packet);
84 <                FilterThread t = new FilterThread(packet, parent, logger);
85 <                t.start();
74 <
84 >                String xml = new String(packet.getData());
85 >                _queue.add(xml);
86              }
87              catch (IOException e) {
88 <                logger.write(this.toString(), Logger.WARNING, "This UDPReader thread has been shut down as an exception occured: "+e);
89 <                return;
88 >                _logger.write(this.toString(), Logger.WARNING, "This UDPReader thread has been shut down as an exception occured: "+e);
89 >                running = false;
90              }
91          }
92          socket.close();
# Line 85 | Line 96 | public class UDPReader extends Thread{
96       * Overrides the {@link java.lang.Object#toString() Object.toString()}
97       * method to provide clean logging (every class should have this).
98       *
99 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
100 +     * to format the toString()
101 +     *
102       * @return the name of this class and its CVS revision
103       */
104      public String toString() {
105 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
105 >        return FormatName.getName(
106 >            _name,
107 >            getClass().getName(),
108 >            REVISION);
109      }
110  
111   //---PRIVATE METHODS---
# Line 97 | Line 114 | public class UDPReader extends Thread{
114  
115   //---ATTRIBUTES---
116  
117 <    Logger logger;
118 <    int port;
119 <    Filter parent;    
117 >    /**
118 >     * This is the friendly identifier of the
119 >     * component this class is running in.
120 >     * eg, a Filter may be called "filter1",
121 >     * If this class does not have an owning
122 >     * component,  a name from the configuration
123 >     * can be placed here.  This name could also
124 >     * be changed to null for utility classes.
125 >     */
126 >    private String _name = FilterMain.NAME;
127  
128 <    final int packetSizeLimit = 8192;
128 >    /**
129 >     * This holds a reference to the
130 >     * system logger that is being used.
131 >     */
132 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
133 >    
134 >    /**
135 >     * The port that this reader is using
136 >     */
137 >    int _port;
138 >    
139 >    /**
140 >     * The Queue object
141 >     */
142 >    Queue _queue;    
143  
144   //---STATIC ATTRIBUTES---
145  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines