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 |
|
|
import uk.ac.ukc.iscream.filter.*; |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* A Filter Startup Class |
11 |
ajm |
1.16 |
* A filter is an iscream component. |
12 |
tdb |
1.1 |
* |
13 |
ajm |
1.13 |
* @author $Author: ajm4 $ |
14 |
ajm |
1.17 |
* @version $Id: FilterMain.java,v 1.16 2000/12/13 13:36:46 ajm4 Exp $ |
15 |
tdb |
1.1 |
*/ |
16 |
ajm |
1.16 |
public class FilterMain implements uk.ac.ukc.iscream.util.Component { |
17 |
tdb |
1.1 |
|
18 |
|
|
//---FINAL ATTRIBUTES--- |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* The current CVS revision of this class |
22 |
|
|
*/ |
23 |
ajm |
1.17 |
public static final String REVISION = "$Revision: 1.16 $"; |
24 |
tdb |
1.1 |
|
25 |
|
|
//---STATIC METHODS--- |
26 |
|
|
|
27 |
ajm |
1.16 |
//---CONSTRUCTORS--- |
28 |
|
|
|
29 |
|
|
/** |
30 |
|
|
* Constructs a Filter with the name given |
31 |
|
|
* |
32 |
|
|
* @param givenName the name |
33 |
|
|
*/ |
34 |
|
|
public FilterMain(String givenName) { |
35 |
|
|
NAME = givenName; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
//---PUBLIC METHODS--- |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* Starts the Filter component |
42 |
|
|
*/ |
43 |
|
|
public void start() throws ComponentStartException { |
44 |
|
|
|
45 |
|
|
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
46 |
tdb |
1.1 |
|
47 |
ajm |
1.13 |
// configuration variables we require |
48 |
|
|
int UDPListenPort = 0; |
49 |
|
|
int TCPListenPort = 0; |
50 |
|
|
String parentFilterName = null; |
51 |
|
|
|
52 |
ajm |
1.16 |
Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME); |
53 |
ajm |
1.13 |
if (config == null) { |
54 |
ajm |
1.16 |
System.err.println("CRITICAL:Unable to obtain configuration" + |
55 |
|
|
"\n Advise you check the i-scream log for more information."); |
56 |
|
|
_logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration"); |
57 |
|
|
System.exit(1); |
58 |
ajm |
1.13 |
} else { |
59 |
|
|
try { |
60 |
|
|
UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort")); |
61 |
|
|
TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort")); |
62 |
|
|
parentFilterName = config.getProperty("Filter.parentFilter"); |
63 |
|
|
} catch (org.omg.CORBA.MARSHAL e) { |
64 |
ajm |
1.16 |
System.err.println ("CRITICAL:Unable to obtain required configuration property" + |
65 |
|
|
"\n Advise you check the i-scream log for more information."); |
66 |
|
|
_logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present"); |
67 |
|
|
System.exit(1); |
68 |
tdb |
1.2 |
} |
69 |
tdb |
1.1 |
} |
70 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
71 |
|
|
|
72 |
ajm |
1.13 |
// get parent |
73 |
ajm |
1.16 |
Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
74 |
ajm |
1.13 |
|
75 |
|
|
// FilterServant start (for inbound child filter data) |
76 |
ajm |
1.16 |
_logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
77 |
ajm |
1.13 |
FilterServant filterServant = new FilterServant(parentFilter, TCPListenPort, UDPListenPort); |
78 |
ajm |
1.16 |
_refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME); |
79 |
ajm |
1.13 |
|
80 |
|
|
// UDL Reader start (for inbound host data) |
81 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener"); |
82 |
ajm |
1.13 |
UDPReader udpReader = new UDPReader(UDPListenPort, parentFilter); |
83 |
|
|
udpReader.start(); |
84 |
|
|
|
85 |
|
|
// TCP Reader start (for heartbeats) |
86 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener"); |
87 |
ajm |
1.13 |
TCPReader tcpReader = new TCPReader(TCPListenPort, parentFilter); |
88 |
|
|
tcpReader.start(); |
89 |
|
|
|
90 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "started"); |
91 |
tdb |
1.1 |
} |
92 |
|
|
|
93 |
ajm |
1.16 |
/** |
94 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
95 |
|
|
* method to provide clean logging (every class should have this). |
96 |
|
|
* |
97 |
|
|
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
98 |
|
|
* to format the toString() |
99 |
|
|
* |
100 |
|
|
* @return the name of this class and its CVS revision |
101 |
|
|
*/ |
102 |
|
|
public String toString() { |
103 |
|
|
return FormatName.getName( |
104 |
ajm |
1.17 |
NAME, |
105 |
ajm |
1.16 |
getClass().getName(), |
106 |
|
|
REVISION); |
107 |
tdb |
1.1 |
} |
108 |
|
|
|
109 |
|
|
//---PRIVATE METHODS--- |
110 |
|
|
|
111 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
112 |
|
|
|
113 |
|
|
//---ATTRIBUTES--- |
114 |
ajm |
1.16 |
|
115 |
|
|
/** |
116 |
|
|
* This holds a reference to the |
117 |
|
|
* system logger that is being used. |
118 |
|
|
*/ |
119 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
120 |
|
|
|
121 |
|
|
/** |
122 |
|
|
* A reference to the reference manager in use |
123 |
|
|
*/ |
124 |
|
|
private ReferenceManager _refman = ReferenceManager.getInstance(); |
125 |
|
|
|
126 |
tdb |
1.1 |
//---STATIC ATTRIBUTES--- |
127 |
ajm |
1.16 |
|
128 |
|
|
/** |
129 |
|
|
* The friendly name for this component, used by |
130 |
|
|
* all related classes. |
131 |
|
|
* This is set from the configuration. |
132 |
|
|
*/ |
133 |
|
|
public static String NAME; |
134 |
tdb |
1.1 |
|
135 |
pjm2 |
1.4 |
} |