1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
tdb |
1.11 |
package uk.ac.ukc.iscream.filter; |
3 |
tdb |
1.1 |
|
4 |
|
|
//---IMPORTS--- |
5 |
ajm |
1.14 |
import uk.ac.ukc.iscream.util.*; |
6 |
tdb |
1.1 |
import uk.ac.ukc.iscream.core.*; |
7 |
tdb |
1.19 |
import uk.ac.ukc.iscream.componentmanager.*; |
8 |
tdb |
1.1 |
import uk.ac.ukc.iscream.filter.*; |
9 |
|
|
|
10 |
|
|
/** |
11 |
|
|
* A Filter Startup Class |
12 |
ajm |
1.16 |
* A filter is an iscream component. |
13 |
tdb |
1.1 |
* |
14 |
tdb |
1.19 |
* @author $Author: tdb1 $ |
15 |
ajm |
1.24 |
* @version $Id: FilterMain.java,v 1.23 2001/02/21 19:11:30 tdb1 Exp $ |
16 |
tdb |
1.1 |
*/ |
17 |
tdb |
1.19 |
public class FilterMain implements Component { |
18 |
tdb |
1.1 |
|
19 |
|
|
//---FINAL ATTRIBUTES--- |
20 |
|
|
|
21 |
|
|
/** |
22 |
|
|
* The current CVS revision of this class |
23 |
|
|
*/ |
24 |
ajm |
1.24 |
public static final String REVISION = "$Revision: 1.23 $"; |
25 |
tdb |
1.1 |
|
26 |
|
|
//---STATIC METHODS--- |
27 |
|
|
|
28 |
ajm |
1.16 |
//---CONSTRUCTORS--- |
29 |
|
|
|
30 |
|
|
/** |
31 |
|
|
* Constructs a Filter with the name given |
32 |
|
|
* |
33 |
|
|
* @param givenName the name |
34 |
|
|
*/ |
35 |
|
|
public FilterMain(String givenName) { |
36 |
|
|
NAME = givenName; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
//---PUBLIC METHODS--- |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* Starts the Filter component |
43 |
|
|
*/ |
44 |
|
|
public void start() throws ComponentStartException { |
45 |
ajm |
1.24 |
// get references to key objects |
46 |
|
|
_refman = ReferenceManager.getInstance(); |
47 |
|
|
_logger = ReferenceManager.getInstance().getLogger(); |
48 |
|
|
|
49 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
50 |
tdb |
1.1 |
|
51 |
ajm |
1.13 |
// configuration variables we require |
52 |
|
|
int UDPListenPort = 0; |
53 |
|
|
int TCPListenPort = 0; |
54 |
|
|
String parentFilterName = null; |
55 |
tdb |
1.23 |
int queueMonitorInterval = 0; |
56 |
tdb |
1.20 |
|
57 |
ajm |
1.16 |
Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME); |
58 |
ajm |
1.13 |
if (config == null) { |
59 |
tdb |
1.20 |
throw new ComponentStartException("Unable to obtain configuration for component"); |
60 |
|
|
} |
61 |
|
|
else { |
62 |
ajm |
1.13 |
try { |
63 |
tdb |
1.20 |
// get the configuration properties we need |
64 |
ajm |
1.13 |
UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort")); |
65 |
|
|
TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort")); |
66 |
|
|
parentFilterName = config.getProperty("Filter.parentFilter"); |
67 |
tdb |
1.23 |
queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval")); |
68 |
ajm |
1.13 |
} catch (org.omg.CORBA.MARSHAL e) { |
69 |
tdb |
1.20 |
throw new ComponentStartException("Unable to obtain requried configuration property for component"); |
70 |
tdb |
1.2 |
} |
71 |
tdb |
1.1 |
} |
72 |
tdb |
1.20 |
|
73 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
74 |
|
|
|
75 |
ajm |
1.13 |
// get parent |
76 |
ajm |
1.16 |
Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
77 |
ajm |
1.13 |
|
78 |
tdb |
1.18 |
// setup a queue |
79 |
|
|
Queue queue = new Queue(); |
80 |
tdb |
1.22 |
// startup a monitor on this queue, every minute |
81 |
tdb |
1.23 |
String queueName = NAME + " Filter"; |
82 |
|
|
queue.startMonitor(queueMonitorInterval*1000, queueName); |
83 |
tdb |
1.18 |
|
84 |
|
|
// Start a filter thread |
85 |
|
|
_logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer"); |
86 |
|
|
FilterThread filterThread = new FilterThread(queue, parentFilter); |
87 |
|
|
filterThread.start(); |
88 |
|
|
|
89 |
ajm |
1.13 |
// FilterServant start (for inbound child filter data) |
90 |
ajm |
1.16 |
_logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
91 |
tdb |
1.18 |
FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue); |
92 |
ajm |
1.16 |
_refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME); |
93 |
ajm |
1.13 |
|
94 |
|
|
// UDL Reader start (for inbound host data) |
95 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener"); |
96 |
tdb |
1.18 |
UDPReader udpReader = new UDPReader(UDPListenPort, queue); |
97 |
ajm |
1.13 |
udpReader.start(); |
98 |
|
|
|
99 |
|
|
// TCP Reader start (for heartbeats) |
100 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener"); |
101 |
tdb |
1.18 |
TCPReader tcpReader = new TCPReader(TCPListenPort, queue); |
102 |
ajm |
1.13 |
tcpReader.start(); |
103 |
|
|
|
104 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "started"); |
105 |
tdb |
1.1 |
} |
106 |
|
|
|
107 |
ajm |
1.16 |
/** |
108 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
109 |
|
|
* method to provide clean logging (every class should have this). |
110 |
|
|
* |
111 |
|
|
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
112 |
|
|
* to format the toString() |
113 |
|
|
* |
114 |
|
|
* @return the name of this class and its CVS revision |
115 |
|
|
*/ |
116 |
|
|
public String toString() { |
117 |
|
|
return FormatName.getName( |
118 |
ajm |
1.17 |
NAME, |
119 |
ajm |
1.16 |
getClass().getName(), |
120 |
|
|
REVISION); |
121 |
tdb |
1.1 |
} |
122 |
|
|
|
123 |
|
|
//---PRIVATE METHODS--- |
124 |
|
|
|
125 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
126 |
|
|
|
127 |
|
|
//---ATTRIBUTES--- |
128 |
ajm |
1.16 |
|
129 |
|
|
/** |
130 |
|
|
* This holds a reference to the |
131 |
|
|
* system logger that is being used. |
132 |
|
|
*/ |
133 |
ajm |
1.24 |
private Logger _logger; |
134 |
ajm |
1.16 |
|
135 |
|
|
/** |
136 |
|
|
* A reference to the reference manager in use |
137 |
|
|
*/ |
138 |
ajm |
1.24 |
private ReferenceManager _refman; |
139 |
ajm |
1.16 |
|
140 |
tdb |
1.1 |
//---STATIC ATTRIBUTES--- |
141 |
ajm |
1.16 |
|
142 |
|
|
/** |
143 |
|
|
* The friendly name for this component, used by |
144 |
|
|
* all related classes. |
145 |
|
|
* This is set from the configuration. |
146 |
|
|
*/ |
147 |
|
|
public static String NAME; |
148 |
tdb |
1.1 |
|
149 |
tdb |
1.21 |
} |