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.29
Committed: Wed Mar 14 23:25:29 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.28: +8 -8 lines
Log Message:
The whole server package structure has been changed.
Old Package: uk.ac.ukc.iscream.*
New Package: uk.org.iscream.*

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2 tdb 1.29 package uk.org.iscream.filter;
3 tdb 1.1
4     //---IMPORTS---
5 tdb 1.29 import uk.org.iscream.util.*;
6     import uk.org.iscream.core.*;
7     import uk.org.iscream.componentmanager.*;
8     import uk.org.iscream.filter.*;
9 tdb 1.1
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 tdb 1.29 * @version $Id: FilterMain.java,v 1.28 2001/03/14 01:54:28 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.29 public static final String REVISION = "$Revision: 1.28 $";
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 tdb 1.27 _logger = _refman.getLogger();
47 ajm 1.24
48 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "coming up");
49 tdb 1.20
50 tdb 1.25 ConfigurationProxy cp = ConfigurationProxy.getInstance();
51 ajm 1.16
52 tdb 1.25 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 ajm 1.13
60 tdb 1.18 // setup a queue
61     Queue queue = new Queue();
62 tdb 1.25
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 tdb 1.18
73     // Start a filter thread
74     _logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer");
75 tdb 1.25 FilterThread filterThread = new FilterThread(queue);
76 tdb 1.18 filterThread.start();
77    
78 ajm 1.13 // FilterServant start (for inbound child filter data)
79 tdb 1.25 _logger.write(toString(), Logger.DEBUG, "starting Servant to listen for downstream filters");
80 tdb 1.18 FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue);
81 ajm 1.16 _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
82 ajm 1.13
83     // UDL Reader start (for inbound host data)
84 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
85 tdb 1.18 UDPReader udpReader = new UDPReader(UDPListenPort, queue);
86 ajm 1.13 udpReader.start();
87    
88     // TCP Reader start (for heartbeats)
89 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
90 tdb 1.18 TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
91 ajm 1.13 tcpReader.start();
92    
93 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "started");
94 tdb 1.1 }
95 tdb 1.26
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 tdb 1.28 System.err.println(toString() + ": Dependency Failure: "+e);
115 tdb 1.26 return false;
116     } catch(PropertyNotFoundException e) {
117 tdb 1.28 System.err.println(toString() + ": Unable to obtain configuration: "+e);
118 tdb 1.26 return false;
119     }
120     // dependency check suceeded
121     return true;
122     }
123    
124 ajm 1.16 /**
125     * Overrides the {@link java.lang.Object#toString() Object.toString()}
126     * method to provide clean logging (every class should have this).
127     *
128 tdb 1.29 * This uses the uk.org.iscream.util.NameFormat class
129 ajm 1.16 * 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 ajm 1.17 NAME,
136 ajm 1.16 getClass().getName(),
137     REVISION);
138 tdb 1.1 }
139    
140     //---PRIVATE METHODS---
141    
142     //---ACCESSOR/MUTATOR METHODS---
143    
144     //---ATTRIBUTES---
145 ajm 1.16
146     /**
147     * This holds a reference to the
148     * system logger that is being used.
149     */
150 ajm 1.24 private Logger _logger;
151 ajm 1.16
152     /**
153     * A reference to the reference manager in use
154     */
155 tdb 1.27 private ReferenceManager _refman = ReferenceManager.getInstance();
156 ajm 1.16
157 tdb 1.1 //---STATIC ATTRIBUTES---
158 ajm 1.16
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 tdb 1.1
166 tdb 1.21 }