1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
//---PACKAGE DECLARATION--- |
21 |
< |
package uk.ac.ukc.iscream.filter; |
21 |
> |
package uk.org.iscream.cms.server.filter; |
22 |
|
|
23 |
|
//---IMPORTS--- |
24 |
|
import java.io.*; |
25 |
|
import java.net.*; |
26 |
|
import java.util.*; |
27 |
< |
import uk.ac.ukc.iscream.core.*; |
28 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
29 |
< |
import uk.ac.ukc.iscream.filter.*; |
30 |
< |
import uk.ac.ukc.iscream.util.*; |
27 |
> |
import uk.org.iscream.cms.server.core.*; |
28 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
29 |
> |
import uk.org.iscream.cms.server.filter.*; |
30 |
> |
import uk.org.iscream.cms.server.util.*; |
31 |
|
|
32 |
|
/** |
33 |
|
* This class contains the main method to be run by |
61 |
|
* @param queue The queue which we are using |
62 |
|
*/ |
63 |
|
public UDPReader(int port, Queue queue){ |
64 |
+ |
// set the Thread name |
65 |
+ |
setName("filter.UDPReader"); |
66 |
+ |
|
67 |
|
_port = port; |
68 |
|
_queue = queue; |
69 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
76 |
|
* over UDP. |
77 |
|
*/ |
78 |
|
public void run() { |
79 |
+ |
// setup an empty ACL defaulting to ALLOW |
80 |
+ |
ACL acl = new ACL(ACL.ALLOW); |
81 |
|
|
82 |
|
// setup a Datagram socket |
83 |
|
DatagramSocket socket = null; |
84 |
|
try { |
85 |
< |
socket = new DatagramSocket(_port); |
85 |
> |
socket = new ACLDatagramSocket(acl, _port); |
86 |
|
} |
87 |
|
catch (BindException e){ |
88 |
|
_logger.write(this.toString(), Logger.FATAL, "Could not start the UDPReader thread on port "+_port+" as this port was already in use."); |
97 |
|
|
98 |
|
byte[] buf; |
99 |
|
|
100 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
101 |
+ |
String stringACL = ""; |
102 |
+ |
String newStringACL = ""; |
103 |
+ |
|
104 |
|
// read UDP packets and queue them |
105 |
|
boolean running = true; |
106 |
|
while (running){ |
107 |
+ |
// get hold of the ACL in the configuration |
108 |
|
try { |
109 |
+ |
newStringACL = cp.getProperty("Filter." + FilterMain.NAME, "Filter.UDPACL"); |
110 |
+ |
} |
111 |
+ |
catch(PropertyNotFoundException e) { |
112 |
+ |
// if we can't find it, we'll just use a null ACL |
113 |
+ |
newStringACL = ""; |
114 |
+ |
_logger.write(toString(), Logger.WARNING, "No ACL found for UDPReader, using empty ACL instead: " + e); |
115 |
+ |
} |
116 |
+ |
// check to see if the ACL has changed |
117 |
+ |
if(!newStringACL.equals(stringACL)) { |
118 |
+ |
_logger.write(toString(), Logger.SYSMSG, "Reloading Access Control List"); |
119 |
+ |
// clear the ACL |
120 |
+ |
acl.clear(); |
121 |
+ |
// set the default to something sane |
122 |
+ |
acl.setDefaultMode(ACL.ALLOW); |
123 |
+ |
// add the new ACL (this may change the default) |
124 |
+ |
acl.add(newStringACL); |
125 |
+ |
stringACL = newStringACL; |
126 |
+ |
} |
127 |
+ |
try { |
128 |
|
|
129 |
|
// receive request and put it in the Queue |
130 |
|
buf = new byte[packetSizeLimit]; |
145 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
146 |
|
* method to provide clean logging (every class should have this). |
147 |
|
* |
148 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
148 |
> |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
149 |
|
* to format the toString() |
150 |
|
* |
151 |
|
* @return the name of this class and its CVS revision |