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.8 by tdb, Thu Nov 30 02:00:55 2000 UTC vs.
Revision 1.15 by tdb, Thu Feb 1 00:18:42 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.refman.*;
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 25 | Line 26 | public class UDPReader extends Thread{
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){
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 <        _parent = parent;
46 >        _queue = queue;
47 >        _logger.write(toString(), Logger.SYSINIT, "started");
48      }
49  
50   //---PUBLIC METHODS---
51 <
51 >    
52 >    /**
53 >     * The main method in the class. Reads and queues XML sent
54 >     * over UDP.
55 >     */
56      public void run() {
57 <
57 >        
58 >        // setup a Datagram socket
59          DatagramSocket socket = null;
60          try {
61              socket = new DatagramSocket(_port);
# Line 54 | Line 70 | public class UDPReader extends Thread{
70          }
71          
72          _logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+_port);
73 <
73 >        
74          byte[] buf;
75          
76 +        // read UDP packets and queue them
77          boolean running = true;
78          while (running){
79              try {
80 <
81 <                    // receive request and pass on to the FilterThread.                
80 >                
81 >                // receive request and put it in the Queue              
82                  buf = new byte[packetSizeLimit];
83                  DatagramPacket packet = new DatagramPacket(buf, buf.length);
84                  socket.receive(packet);
85 <                FilterThread t = new FilterThread(packet, _parent);
86 <                t.start();
70 <
85 >                String xml = new String(packet.getData());
86 >                _queue.add(xml);
87              }
88              catch (IOException e) {
89                  _logger.write(this.toString(), Logger.WARNING, "This UDPReader thread has been shut down as an exception occured: "+e);
90 <                return;
90 >                running = false;
91              }
92          }
93          socket.close();
94      }
95 <
95 >    
96      /**
97       * Overrides the {@link java.lang.Object#toString() Object.toString()}
98       * method to provide clean logging (every class should have this).
99       *
100 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
101 +     * to format the toString()
102 +     *
103       * @return the name of this class and its CVS revision
104       */
105      public String toString() {
106 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
106 >        return FormatName.getName(
107 >            _name,
108 >            getClass().getName(),
109 >            REVISION);
110      }
111  
112   //---PRIVATE METHODS---
# Line 93 | Line 115 | public class UDPReader extends Thread{
115  
116   //---ATTRIBUTES---
117  
118 <    Logger _logger = ReferenceManager.getInstance().getLogger();
118 >    /**
119 >     * This is the friendly identifier of the
120 >     * component this class is running in.
121 >     * eg, a Filter may be called "filter1",
122 >     * If this class does not have an owning
123 >     * component,  a name from the configuration
124 >     * can be placed here.  This name could also
125 >     * be changed to null for utility classes.
126 >     */
127 >    private String _name = FilterMain.NAME;
128 >    
129 >    /**
130 >     * This holds a reference to the
131 >     * system logger that is being used.
132 >     */
133 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
134 >    
135 >    /**
136 >     * The port that this reader is using
137 >     */
138      int _port;
139 <    Filter _parent;    
140 <
141 <    final int packetSizeLimit = 8192;
139 >    
140 >    /**
141 >     * The Queue object
142 >     */
143 >    Queue _queue;
144  
145   //---STATIC ATTRIBUTES---
146  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines