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

# User Rev Content
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.26 * @author $Author: tdb1 $
15     * @version $Id: FilterMain.java,v 1.25 2001/03/13 16:25:57 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 tdb 1.26 public static final String REVISION = "$Revision: 1.25 $";
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.20
51 tdb 1.25 ConfigurationProxy cp = ConfigurationProxy.getInstance();
52 ajm 1.16
53 tdb 1.25 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 ajm 1.13
61 tdb 1.18 // setup a queue
62     Queue queue = new Queue();
63 tdb 1.25
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 tdb 1.18
74     // Start a filter thread
75     _logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer");
76 tdb 1.25 FilterThread filterThread = new FilterThread(queue);
77 tdb 1.18 filterThread.start();
78    
79 ajm 1.13 // FilterServant start (for inbound child filter data)
80 tdb 1.25 _logger.write(toString(), Logger.DEBUG, "starting Servant to listen for downstream filters");
81 tdb 1.18 FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue);
82 ajm 1.16 _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
83 ajm 1.13
84     // UDL Reader start (for inbound host data)
85 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
86 tdb 1.18 UDPReader udpReader = new UDPReader(UDPListenPort, queue);
87 ajm 1.13 udpReader.start();
88    
89     // TCP Reader start (for heartbeats)
90 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
91 tdb 1.18 TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
92 ajm 1.13 tcpReader.start();
93    
94 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "started");
95 tdb 1.1 }
96 tdb 1.26
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 ajm 1.16 /**
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 ajm 1.17 NAME,
137 ajm 1.16 getClass().getName(),
138     REVISION);
139 tdb 1.1 }
140    
141     //---PRIVATE METHODS---
142    
143     //---ACCESSOR/MUTATOR METHODS---
144    
145     //---ATTRIBUTES---
146 ajm 1.16
147     /**
148     * This holds a reference to the
149     * system logger that is being used.
150     */
151 ajm 1.24 private Logger _logger;
152 ajm 1.16
153     /**
154     * A reference to the reference manager in use
155     */
156 ajm 1.24 private ReferenceManager _refman;
157 ajm 1.16
158 tdb 1.1 //---STATIC ATTRIBUTES---
159 ajm 1.16
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 tdb 1.1
167 tdb 1.21 }