1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.org.iscream.filter; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.core.*; |
6 |
< |
import uk.ac.ukc.iscream.filter.*; |
5 |
> |
import uk.org.iscream.core.*; |
6 |
> |
import uk.org.iscream.componentmanager.*; |
7 |
> |
import uk.org.iscream.filter.*; |
8 |
> |
import uk.org.iscream.util.*; |
9 |
|
import java.net.InetAddress; |
10 |
|
|
11 |
|
/** |
12 |
< |
* A test FilterServant, just prints it out. |
12 |
> |
* Passes inbound data from other Filters to a FilterThread |
13 |
|
* |
14 |
|
* @author $Author$ |
15 |
|
* @version $Id$ |
28 |
|
//---CONSTRUCTORS--- |
29 |
|
|
30 |
|
/** |
31 |
< |
* Creates a new Filter. |
31 |
> |
* Creates a new FilterServant. |
32 |
|
* |
33 |
< |
* @param logger a Logger to use |
33 |
> |
* @param TCPListenPort the TCP port this filter is listening on |
34 |
> |
* @param UDPListenPort the UDP port this filter is listening on |
35 |
> |
* @param queue the Queue this filter is using |
36 |
|
*/ |
37 |
< |
public FilterServant(Logger logger, Filter parent, String name, String TCPPort, String UDPPort) { |
38 |
< |
_logRef = logger; |
39 |
< |
_name = name; |
40 |
< |
_parent = parent; |
41 |
< |
_TCPPort = TCPPort; |
37 |
< |
_UDPPort = UDPPort; |
38 |
< |
_logRef.write(this.toString(), Logger.SYSINIT, "created"); |
37 |
> |
public FilterServant(int TCPListenPort, int UDPListenPort, Queue queue) { |
38 |
> |
_TCPListenPort = TCPListenPort; |
39 |
> |
_UDPListenPort = UDPListenPort; |
40 |
> |
_queue = queue; |
41 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
42 |
|
} |
43 |
< |
|
43 |
> |
|
44 |
|
//---PUBLIC METHODS--- |
45 |
|
|
46 |
|
/** |
47 |
|
* Method to receive a string over corba. |
48 |
|
* |
49 |
< |
* @param xml the String of XML to print out |
49 |
> |
* @param xml the String of XML to queue |
50 |
|
*/ |
51 |
|
public void receiveXML(String xml) { |
52 |
< |
_logRef.write(this.toString(), Logger.SYSMSG, "received XML: "+xml); |
50 |
< |
FilterThread t = new FilterThread(xml, _parent, _logRef); |
51 |
< |
t.start(); |
52 |
> |
_queue.add(xml); |
53 |
|
} |
54 |
|
|
55 |
|
/** |
56 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
57 |
|
* method to provide clean logging (every class should have this). |
58 |
|
* |
59 |
+ |
* This uses the uk.org.iscream.util.NameFormat class |
60 |
+ |
* to format the toString() |
61 |
+ |
* |
62 |
|
* @return the name of this class and its CVS revision |
63 |
|
*/ |
64 |
|
public String toString() { |
65 |
< |
return this.getClass().getName() + "{" + _name + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
65 |
> |
return FormatName.getName( |
66 |
> |
_name, |
67 |
> |
getClass().getName(), |
68 |
> |
REVISION); |
69 |
|
} |
70 |
|
|
71 |
|
//---PRIVATE METHODS--- |
72 |
|
|
73 |
|
//---ACCESSOR/MUTATOR METHODS--- |
74 |
|
|
75 |
+ |
/** |
76 |
+ |
* Provides information to the FilterManager |
77 |
+ |
*/ |
78 |
|
public String getUDPPort() { |
79 |
< |
return _UDPPort; |
79 |
> |
return new Integer(_UDPListenPort).toString(); |
80 |
|
} |
81 |
|
|
82 |
+ |
/** |
83 |
+ |
* Provides information to the FilterManager |
84 |
+ |
*/ |
85 |
|
public String getTCPPort() { |
86 |
< |
return _TCPPort; |
86 |
> |
return new Integer(_TCPListenPort).toString(); |
87 |
|
} |
88 |
|
|
89 |
+ |
/** |
90 |
+ |
* Provides information to the FilterManager |
91 |
+ |
*/ |
92 |
|
public String getHostName() { |
93 |
|
try { |
94 |
|
return InetAddress.getLocalHost().getHostName(); |
95 |
|
} catch (java.net.UnknownHostException e) { |
96 |
< |
_logRef.write(toString(), Logger.ERROR, e.getMessage()); |
96 |
> |
_logger.write(toString(), Logger.ERROR, e.getMessage()); |
97 |
|
} |
98 |
|
return null; |
99 |
|
} |
102 |
|
//---ATTRIBUTES--- |
103 |
|
|
104 |
|
/** |
105 |
< |
* Reference to a Logger |
105 |
> |
* This is the friendly identifier of the |
106 |
> |
* component this class is running in. |
107 |
> |
* eg, a Filter may be called "filter1", |
108 |
> |
* If this class does not have an owning |
109 |
> |
* component, a name from the configuration |
110 |
> |
* can be placed here. This name could also |
111 |
> |
* be changed to null for utility classes. |
112 |
|
*/ |
113 |
< |
private Logger _logRef; |
114 |
< |
|
113 |
> |
private String _name = FilterMain.NAME; |
114 |
> |
|
115 |
|
/** |
116 |
< |
* Our name |
116 |
> |
* This holds a reference to the |
117 |
> |
* system logger that is being used. |
118 |
|
*/ |
119 |
< |
private String _name; |
119 |
> |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
120 |
|
|
121 |
|
/** |
122 |
< |
* Our parent filter |
122 |
> |
* Our Queue object |
123 |
|
*/ |
124 |
< |
private Filter _parent; |
124 |
> |
private Queue _queue; |
125 |
|
|
126 |
< |
private String _UDPPort; |
127 |
< |
private String _TCPPort; |
126 |
> |
/** |
127 |
> |
* The UDP port we're listening on |
128 |
> |
*/ |
129 |
> |
private int _UDPListenPort; |
130 |
> |
|
131 |
> |
/** |
132 |
> |
* The TCP port we're listening on |
133 |
> |
*/ |
134 |
> |
private int _TCPListenPort; |
135 |
|
|
136 |
|
//---STATIC ATTRIBUTES--- |
137 |
|
|