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.18 by tdb, Tue May 29 17:02:35 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines