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.26
Committed: Wed Mar 14 01:34:28 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.25: +32 -4 lines
Log Message:
New dependency checking. The old method was to attempt to start a Component, and
if it failed, it probably had a depdency problem. The approach now is to ask the
Component to perform a dependency check first, then if this suceeds, have a go
at actually starting it up.
The actual dependency check is a bit neater and more precise than before, and
should be much more fool proof. The order the components are specified in the
default.properties file is now irrelevant, although the "correct" order would
certainly increase booting time.

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