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.30
Committed: Fri Mar 16 16:11:32 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Changes since 1.29: +28 -3 lines
Log Message:
Implemented Queue size limiting.

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.30 * @version $Id: FilterMain.java,v 1.29 2001/03/14 23:25:29 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.30 public static final String REVISION = "$Revision: 1.29 $";
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 tdb 1.30 Queue queue;
62     // see if this Queue needs a size limit
63     try {
64     int queueSizeLimit = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Queue.SizeLimit"));
65     String queueRemoveAlgorithm = cp.getProperty(FilterMain.NAME, "Queue.RemoveAlgorithm");
66     int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms);
67     if(algorithm != -1) {
68     _logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm);
69     // we have valid values, so lets start it.
70     queue = new Queue(queueSizeLimit, algorithm);
71     }
72     else {
73     _logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm);
74     // just don't activate a limit
75     queue = new Queue();
76     }
77    
78     } catch (PropertyNotFoundException e) {
79     _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
80     // just don't activate a limit
81     queue = new Queue();
82     } catch (NumberFormatException e) {
83     _logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e);
84     // just don't activate a limit
85     queue = new Queue();
86     }
87 tdb 1.25
88     // startup a monitor on this queue
89     try {
90     // try to get the interval, if this fails, we won't start up the monitor
91     int queueMonitorInterval = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Queue.MonitorInterval"));
92     String queueName = NAME + " Filter";
93     queue.startMonitor(queueMonitorInterval*1000, queueName);
94     } catch (PropertyNotFoundException e) {
95     _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
96     }
97 tdb 1.18
98     // Start a filter thread
99     _logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer");
100 tdb 1.25 FilterThread filterThread = new FilterThread(queue);
101 tdb 1.18 filterThread.start();
102    
103 ajm 1.13 // FilterServant start (for inbound child filter data)
104 tdb 1.25 _logger.write(toString(), Logger.DEBUG, "starting Servant to listen for downstream filters");
105 tdb 1.18 FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue);
106 ajm 1.16 _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
107 ajm 1.13
108     // UDL Reader start (for inbound host data)
109 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
110 tdb 1.18 UDPReader udpReader = new UDPReader(UDPListenPort, queue);
111 ajm 1.13 udpReader.start();
112    
113     // TCP Reader start (for heartbeats)
114 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
115 tdb 1.18 TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
116 ajm 1.13 tcpReader.start();
117    
118 ajm 1.16 _logger.write(toString(), Logger.SYSINIT, "started");
119 tdb 1.1 }
120 tdb 1.26
121     /**
122     * Does a dependency check. Used mainly at startup to
123     * see if the required dependencies (components) are up
124     * and running.
125     *
126     * @return a boolean value, true if the depdencies are satisfied
127     */
128     public boolean depCheck() {
129     try {
130     org.omg.CORBA.Object obj;
131     // first check the ConfigurationManager is alive
132     obj = _refman.getCORBARef("iscream.ConfigurationManager");
133     // then suss out our parent filter
134     ConfigurationProxy cp = ConfigurationProxy.getInstance();
135     String parentFilterName = cp.getProperty(NAME, "Filter.parentFilter");
136     // finally check the parent filter is alive
137     obj = _refman.getCORBARef("iscream.Filter." + parentFilterName);
138     } catch(ComponentCORBAException e) {
139 tdb 1.28 System.err.println(toString() + ": Dependency Failure: "+e);
140 tdb 1.26 return false;
141     } catch(PropertyNotFoundException e) {
142 tdb 1.28 System.err.println(toString() + ": Unable to obtain configuration: "+e);
143 tdb 1.26 return false;
144     }
145     // dependency check suceeded
146     return true;
147     }
148    
149 ajm 1.16 /**
150     * Overrides the {@link java.lang.Object#toString() Object.toString()}
151     * method to provide clean logging (every class should have this).
152     *
153 tdb 1.29 * This uses the uk.org.iscream.util.NameFormat class
154 ajm 1.16 * to format the toString()
155     *
156     * @return the name of this class and its CVS revision
157     */
158     public String toString() {
159     return FormatName.getName(
160 ajm 1.17 NAME,
161 ajm 1.16 getClass().getName(),
162     REVISION);
163 tdb 1.1 }
164    
165     //---PRIVATE METHODS---
166    
167     //---ACCESSOR/MUTATOR METHODS---
168    
169     //---ATTRIBUTES---
170 ajm 1.16
171     /**
172     * This holds a reference to the
173     * system logger that is being used.
174     */
175 ajm 1.24 private Logger _logger;
176 ajm 1.16
177     /**
178     * A reference to the reference manager in use
179     */
180 tdb 1.27 private ReferenceManager _refman = ReferenceManager.getInstance();
181 ajm 1.16
182 tdb 1.1 //---STATIC ATTRIBUTES---
183 ajm 1.16
184     /**
185     * The friendly name for this component, used by
186     * all related classes.
187     * This is set from the configuration.
188     */
189     public static String NAME;
190 tdb 1.1
191 tdb 1.21 }