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

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.filter;
3
4 //---IMPORTS---
5 import uk.org.iscream.util.*;
6 import uk.org.iscream.core.*;
7 import uk.org.iscream.componentmanager.*;
8 import uk.org.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.29 2001/03/14 23:25:29 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.29 $";
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;
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
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
98 // Start a filter thread
99 _logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer");
100 FilterThread filterThread = new FilterThread(queue);
101 filterThread.start();
102
103 // FilterServant start (for inbound child filter data)
104 _logger.write(toString(), Logger.DEBUG, "starting Servant to listen for downstream filters");
105 FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue);
106 _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
107
108 // UDL Reader start (for inbound host data)
109 _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
110 UDPReader udpReader = new UDPReader(UDPListenPort, queue);
111 udpReader.start();
112
113 // TCP Reader start (for heartbeats)
114 _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
115 TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
116 tcpReader.start();
117
118 _logger.write(toString(), Logger.SYSINIT, "started");
119 }
120
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 System.err.println(toString() + ": Dependency Failure: "+e);
140 return false;
141 } catch(PropertyNotFoundException e) {
142 System.err.println(toString() + ": Unable to obtain configuration: "+e);
143 return false;
144 }
145 // dependency check suceeded
146 return true;
147 }
148
149 /**
150 * Overrides the {@link java.lang.Object#toString() Object.toString()}
151 * method to provide clean logging (every class should have this).
152 *
153 * This uses the uk.org.iscream.util.NameFormat class
154 * 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 NAME,
161 getClass().getName(),
162 REVISION);
163 }
164
165 //---PRIVATE METHODS---
166
167 //---ACCESSOR/MUTATOR METHODS---
168
169 //---ATTRIBUTES---
170
171 /**
172 * This holds a reference to the
173 * system logger that is being used.
174 */
175 private Logger _logger;
176
177 /**
178 * A reference to the reference manager in use
179 */
180 private ReferenceManager _refman = ReferenceManager.getInstance();
181
182 //---STATIC ATTRIBUTES---
183
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
191 }