1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.filter; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.util.*; |
6 |
import uk.ac.ukc.iscream.core.*; |
7 |
import uk.ac.ukc.iscream.filter.*; |
8 |
|
9 |
/** |
10 |
* A Filter Startup Class |
11 |
* A filter is an iscream component. |
12 |
* |
13 |
* @author $Author: ajm4 $ |
14 |
* @version $Id: FilterMain.java,v 1.16 2000/12/13 13:36:46 ajm4 Exp $ |
15 |
*/ |
16 |
public class FilterMain implements uk.ac.ukc.iscream.util.Component { |
17 |
|
18 |
//---FINAL ATTRIBUTES--- |
19 |
|
20 |
/** |
21 |
* The current CVS revision of this class |
22 |
*/ |
23 |
public static final String REVISION = "$Revision: 1.16 $"; |
24 |
|
25 |
//---STATIC METHODS--- |
26 |
|
27 |
//---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 |
|
47 |
// configuration variables we require |
48 |
int UDPListenPort = 0; |
49 |
int TCPListenPort = 0; |
50 |
String parentFilterName = null; |
51 |
|
52 |
Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME); |
53 |
if (config == null) { |
54 |
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 |
} 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 |
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 |
} |
69 |
} |
70 |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
71 |
|
72 |
// get parent |
73 |
Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
74 |
|
75 |
// FilterServant start (for inbound child filter data) |
76 |
_logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
77 |
FilterServant filterServant = new FilterServant(parentFilter, TCPListenPort, UDPListenPort); |
78 |
_refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME); |
79 |
|
80 |
// UDL Reader start (for inbound host data) |
81 |
_logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener"); |
82 |
UDPReader udpReader = new UDPReader(UDPListenPort, parentFilter); |
83 |
udpReader.start(); |
84 |
|
85 |
// TCP Reader start (for heartbeats) |
86 |
_logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener"); |
87 |
TCPReader tcpReader = new TCPReader(TCPListenPort, parentFilter); |
88 |
tcpReader.start(); |
89 |
|
90 |
_logger.write(toString(), Logger.SYSINIT, "started"); |
91 |
} |
92 |
|
93 |
/** |
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 |
NAME, |
105 |
getClass().getName(), |
106 |
REVISION); |
107 |
} |
108 |
|
109 |
//---PRIVATE METHODS--- |
110 |
|
111 |
//---ACCESSOR/MUTATOR METHODS--- |
112 |
|
113 |
//---ATTRIBUTES--- |
114 |
|
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 |
//---STATIC ATTRIBUTES--- |
127 |
|
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 |
|
135 |
} |