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
Revision: 1.5
Committed: Thu Nov 23 09:21:48 2000 UTC (23 years, 5 months ago) by pjm2
Branch: MAIN
Changes since 1.4: +1 -1 lines
Log Message:
Altered both UDPReader and FilterThread such that a reference to a Logger
is passed to the FilterThread when it is constructed.

File Contents

# User Rev Content
1 pjm2 1.1 import java.io.*;
2     import java.net.*;
3     import java.util.*;
4 tdb 1.2 import uk.ac.ukc.iscream.core.*;
5     import uk.ac.ukc.iscream.filter.*;
6 pjm2 1.1
7     // This class contains the main method to be run by
8     // the filter children. It harvests UDP traffic.
9     //
10     public class UDPReader extends Thread{
11    
12     // It is normal to use this constructor in preference
13     // to any other in this class.
14 tdb 1.2 public UDPReader(int port, Filter parent, Logger logger){
15 pjm2 1.1 this.logger = logger;
16     this.port = port;
17 tdb 1.2 this.parent = parent;
18 pjm2 1.1 }
19    
20 tdb 1.2 public UDPReader(Filter parent, Logger logger){
21     this(4589, parent, logger);
22 pjm2 1.1 }
23    
24     public void run() {
25    
26     DatagramSocket socket = null;
27     try {
28     socket = new DatagramSocket(port);
29     }
30     catch (BindException e){
31 pjm2 1.4 logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+port+" as this port was already in use.");
32 pjm2 1.1 return;
33     }
34     catch (Exception e){
35 pjm2 1.4 logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+port+".");
36 pjm2 1.1 return;
37     }
38    
39     logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+port);
40    
41     byte[] buf;
42    
43     boolean running = true;
44     while (running){
45     try {
46 pjm2 1.3
47     // receive request and pass on to the FilterThread.
48 pjm2 1.1 buf = new byte[packetSizeLimit];
49     DatagramPacket packet = new DatagramPacket(buf, buf.length);
50     socket.receive(packet);
51 pjm2 1.5 FilterThread t = new FilterThread(packet, parent, logger);
52 pjm2 1.3 t.start();
53    
54 pjm2 1.1 }
55     catch (IOException e) {
56 pjm2 1.4 logger.write(this.toString(), Logger.WARNING, "This UDPReader thread has been shut down as an exception occured: "+e);
57 pjm2 1.1 return;
58     }
59     }
60     socket.close();
61     }
62    
63    
64     Logger logger;
65     int port;
66 tdb 1.2 Filter parent;
67    
68 pjm2 1.1 final int packetSizeLimit = 8192;
69    
70     }