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.14 by tdb, Sun Jan 28 05:34:38 2001 UTC vs.
Revision 1.22 by tdb, Thu Mar 21 13:01:22 2002 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.componentmanager.*;
10 < import uk.ac.ukc.iscream.filter.*;
11 < import uk.ac.ukc.iscream.util.*;
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
# Line 25 | Line 25 | public class UDPReader extends Thread{
25       * The current CVS revision of this class
26       */
27      public final String REVISION = "$Revision$";
28 <
28 >    
29      /**
30       * The maximum size of a packet
31       */
# Line 42 | Line 42 | public class UDPReader extends Thread{
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          _queue = queue;
50 +        _logger.write(toString(), Logger.SYSINIT, "started");
51      }
52  
53   //---PUBLIC METHODS---
# Line 53 | Line 57 | public class UDPReader extends Thread{
57       * over UDP.
58       */
59      public void run() {
60 +        // setup an empty ACL defaulting to ALLOW
61 +        ACL acl = new ACL(ACL.ALLOW);
62          
63          // setup a Datagram socket
64          DatagramSocket socket = null;
65          try {
66 <            socket = new DatagramSocket(_port);
66 >            socket = new ACLDatagramSocket(acl, _port);
67          }
68          catch (BindException e){
69              _logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+_port+" as this port was already in use.");
# Line 69 | Line 75 | public class UDPReader extends Thread{
75          }
76          
77          _logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+_port);
78 <
78 >        
79          byte[] buf;
80          
81 +        ConfigurationProxy cp = ConfigurationProxy.getInstance();
82 +        String stringACL = "";
83 +        String newStringACL = "";
84 +        
85          // read UDP packets and queue them
86          boolean running = true;
87          while (running){
88 +            // get hold of the ACL in the configuration
89              try {
90 <
91 <                    // receive request and put it in the Queue              
90 >                newStringACL = cp.getProperty("Filter." + FilterMain.NAME, "Filter.UDPACL");
91 >            }
92 >            catch(PropertyNotFoundException e) {
93 >                // if we can't find it, we'll just use a null ACL
94 >                newStringACL = "";
95 >                _logger.write(toString(), Logger.WARNING, "No ACL found for UDPReader, using empty ACL instead: " + e);
96 >            }
97 >            // check to see if the ACL has changed
98 >            if(!newStringACL.equals(stringACL)) {
99 >                _logger.write(toString(), Logger.SYSMSG, "Reloading Access Control List");
100 >                // clear the ACL
101 >                acl.clear();
102 >                // set the default to something sane
103 >                acl.setDefaultMode(ACL.ALLOW);
104 >                // add the new ACL (this may change the default)
105 >                acl.add(newStringACL);
106 >                stringACL = newStringACL;
107 >            }
108 >            try {
109 >                
110 >                // receive request and put it in the Queue              
111                  buf = new byte[packetSizeLimit];
112                  DatagramPacket packet = new DatagramPacket(buf, buf.length);
113                  socket.receive(packet);
# Line 91 | Line 121 | public class UDPReader extends Thread{
121          }
122          socket.close();
123      }
124 <
124 >    
125      /**
126       * Overrides the {@link java.lang.Object#toString() Object.toString()}
127       * method to provide clean logging (every class should have this).
128       *
129 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
129 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
130       * to format the toString()
131       *
132       * @return the name of this class and its CVS revision
# Line 124 | Line 154 | public class UDPReader extends Thread{
154       * be changed to null for utility classes.
155       */
156      private String _name = FilterMain.NAME;
157 <
157 >    
158      /**
159       * This holds a reference to the
160       * system logger that is being used.
# Line 139 | Line 169 | public class UDPReader extends Thread{
169      /**
170       * The Queue object
171       */
172 <    Queue _queue;    
172 >    Queue _queue;
173  
174   //---STATIC ATTRIBUTES---
175  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines