ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/FilterMain.java
Revision: 1.28
Committed: Wed Mar 14 01:54:28 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.27: +4 -4 lines
Log Message:
Of course, being my usual sensible self, I potentially had a situation where by
I would log to the Logger than the Logger isn't running. Clever eh ? :)

File Contents

# Content
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.componentmanager.*;
8 import uk.ac.ukc.iscream.filter.*;
9
10 /**
11 * A Filter Startup Class
12 * A filter is an iscream component.
13 *
14 * @author $Author: tdb1 $
15 * @version $Id: FilterMain.java,v 1.27 2001/03/14 01:43:52 tdb1 Exp $
16 */
17 public class FilterMain implements Component {
18
19 //---FINAL ATTRIBUTES---
20
21 /**
22 * The current CVS revision of this class
23 */
24 public static final String REVISION = "$Revision: 1.27 $";
25
26 //---STATIC METHODS---
27
28 //---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 // get references to key objects
46 _logger = _refman.getLogger();
47
48 _logger.write(toString(), Logger.SYSINIT, "coming up");
49
50 ConfigurationProxy cp = ConfigurationProxy.getInstance();
51
52 int UDPListenPort, TCPListenPort;
53 try {
54 UDPListenPort = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Filter.UDPListenPort"));
55 TCPListenPort = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Filter.TCPListenPort"));
56 } catch (PropertyNotFoundException e) {
57 throw new ComponentStartException("Unable to obtain requried configuration property for component: " + e);
58 }
59
60 // setup a queue
61 Queue queue = new Queue();
62
63 // startup a monitor on this queue
64 try {
65 // try to get the interval, if this fails, we won't start up the monitor
66 int queueMonitorInterval = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Queue.MonitorInterval"));
67 String queueName = NAME + " Filter";
68 queue.startMonitor(queueMonitorInterval*1000, queueName);
69 } catch (PropertyNotFoundException e) {
70 _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
71 }
72
73 // Start a filter thread
74 _logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer");
75 FilterThread filterThread = new FilterThread(queue);
76 filterThread.start();
77
78 // FilterServant start (for inbound child filter data)
79 _logger.write(toString(), Logger.DEBUG, "starting Servant to listen for downstream filters");
80 FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue);
81 _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
82
83 // UDL Reader start (for inbound host data)
84 _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
85 UDPReader udpReader = new UDPReader(UDPListenPort, queue);
86 udpReader.start();
87
88 // TCP Reader start (for heartbeats)
89 _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
90 TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
91 tcpReader.start();
92
93 _logger.write(toString(), Logger.SYSINIT, "started");
94 }
95
96 /**
97 * Does a dependency check. Used mainly at startup to
98 * see if the required dependencies (components) are up
99 * and running.
100 *
101 * @return a boolean value, true if the depdencies are satisfied
102 */
103 public boolean depCheck() {
104 try {
105 org.omg.CORBA.Object obj;
106 // first check the ConfigurationManager is alive
107 obj = _refman.getCORBARef("iscream.ConfigurationManager");
108 // then suss out our parent filter
109 ConfigurationProxy cp = ConfigurationProxy.getInstance();
110 String parentFilterName = cp.getProperty(NAME, "Filter.parentFilter");
111 // finally check the parent filter is alive
112 obj = _refman.getCORBARef("iscream.Filter." + parentFilterName);
113 } catch(ComponentCORBAException e) {
114 System.err.println(toString() + ": Dependency Failure: "+e);
115 return false;
116 } catch(PropertyNotFoundException e) {
117 System.err.println(toString() + ": Unable to obtain configuration: "+e);
118 return false;
119 }
120 // dependency check suceeded
121 return true;
122 }
123
124 /**
125 * Overrides the {@link java.lang.Object#toString() Object.toString()}
126 * method to provide clean logging (every class should have this).
127 *
128 * This uses the uk.ac.ukc.iscream.util.NameFormat class
129 * to format the toString()
130 *
131 * @return the name of this class and its CVS revision
132 */
133 public String toString() {
134 return FormatName.getName(
135 NAME,
136 getClass().getName(),
137 REVISION);
138 }
139
140 //---PRIVATE METHODS---
141
142 //---ACCESSOR/MUTATOR METHODS---
143
144 //---ATTRIBUTES---
145
146 /**
147 * This holds a reference to the
148 * system logger that is being used.
149 */
150 private Logger _logger;
151
152 /**
153 * A reference to the reference manager in use
154 */
155 private ReferenceManager _refman = ReferenceManager.getInstance();
156
157 //---STATIC ATTRIBUTES---
158
159 /**
160 * The friendly name for this component, used by
161 * all related classes.
162 * This is set from the configuration.
163 */
164 public static String NAME;
165
166 }