1 |
tdb |
1.39 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
tdb |
1.40 |
* http://www.i-scream.org.uk |
4 |
tdb |
1.39 |
* Copyright (C) 2000-2002 i-scream |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
|
*/ |
20 |
|
|
|
21 |
ajm |
1.27 |
|
22 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
23 |
tdb |
1.38 |
package uk.org.iscream.cms.server.rootfilter; |
24 |
tdb |
1.1 |
|
25 |
|
|
//---IMPORTS--- |
26 |
tdb |
1.42 |
import uk.org.iscream.cms.util.*; |
27 |
tdb |
1.38 |
import uk.org.iscream.cms.server.core.*; |
28 |
|
|
import uk.org.iscream.cms.server.componentmanager.*; |
29 |
|
|
import uk.org.iscream.cms.server.clientinterface.*; |
30 |
tdb |
1.1 |
|
31 |
|
|
/** |
32 |
ajm |
1.10 |
* The root filter is what all filters talk to |
33 |
|
|
* Hosts cannot talk to this implementation of a filter. |
34 |
|
|
* It provides hooks to all data interfaces for the system |
35 |
|
|
* namely the client interface and the db interface. |
36 |
|
|
* This is an i-scream component that starts the |
37 |
|
|
* RootFilter services. |
38 |
tdb |
1.1 |
* |
39 |
tdb |
1.39 |
* @author $Author: tdb $ |
40 |
tdb |
1.43 |
* @version $Id: RootFilter.java,v 1.42 2003/02/05 16:43:48 tdb Exp $ |
41 |
tdb |
1.1 |
*/ |
42 |
tdb |
1.17 |
public class RootFilter implements Component { |
43 |
tdb |
1.1 |
|
44 |
|
|
//---FINAL ATTRIBUTES--- |
45 |
|
|
|
46 |
|
|
/** |
47 |
|
|
* The current CVS revision of this class |
48 |
|
|
*/ |
49 |
tdb |
1.43 |
public static final String REVISION = "$Revision: 1.42 $"; |
50 |
ajm |
1.10 |
|
51 |
tdb |
1.1 |
//---STATIC METHODS--- |
52 |
|
|
|
53 |
ajm |
1.10 |
//---CONSTRUCTORS--- |
54 |
|
|
|
55 |
|
|
//---PUBLIC METHODS--- |
56 |
ajm |
1.5 |
|
57 |
ajm |
1.10 |
/** |
58 |
|
|
* This starts the Root Filter for the system |
59 |
|
|
*/ |
60 |
|
|
public void start() throws ComponentStartException { |
61 |
ajm |
1.26 |
// get references to key objects |
62 |
tdb |
1.30 |
_logger = _refman.getLogger(); |
63 |
ajm |
1.26 |
|
64 |
ajm |
1.10 |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
65 |
tdb |
1.28 |
|
66 |
|
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
67 |
|
|
String configName = "RootFilter"; |
68 |
|
|
|
69 |
|
|
// set the name of the root filter |
70 |
|
|
try { |
71 |
|
|
NAME = cp.getProperty(configName, "RootFilter.name"); |
72 |
|
|
} catch (PropertyNotFoundException e) { |
73 |
|
|
NAME = null; |
74 |
|
|
_logger.write(toString(), Logger.WARNING, "RootFilter name not set: "+e); |
75 |
tdb |
1.23 |
} |
76 |
tdb |
1.28 |
|
77 |
|
|
// setup a queue |
78 |
tdb |
1.33 |
Queue queue; |
79 |
|
|
// see if this Queue needs a size limit |
80 |
|
|
try { |
81 |
|
|
int queueSizeLimit = Integer.parseInt(cp.getProperty(configName, "Queue.SizeLimit")); |
82 |
|
|
String queueRemoveAlgorithm = cp.getProperty(configName, "Queue.RemoveAlgorithm"); |
83 |
|
|
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
84 |
|
|
if(algorithm != -1) { |
85 |
tdb |
1.34 |
_logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
86 |
|
|
// we have valid values, so lets start it. |
87 |
tdb |
1.33 |
queue = new Queue(queueSizeLimit, algorithm); |
88 |
|
|
} |
89 |
|
|
else { |
90 |
|
|
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
91 |
|
|
// just don't activate a limit |
92 |
|
|
queue = new Queue(); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
} catch (PropertyNotFoundException e) { |
96 |
|
|
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
97 |
|
|
// just don't activate a limit |
98 |
|
|
queue = new Queue(); |
99 |
|
|
} catch (NumberFormatException e) { |
100 |
|
|
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
101 |
|
|
// just don't activate a limit |
102 |
|
|
queue = new Queue(); |
103 |
|
|
} |
104 |
tdb |
1.15 |
|
105 |
tdb |
1.28 |
// startup a monitor on this queue |
106 |
|
|
try { |
107 |
|
|
// try to get the interval, if this fails, we won't start up the monitor |
108 |
|
|
int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval")); |
109 |
|
|
String queueName = NAME + " RootFilter"; |
110 |
|
|
queue.startMonitor(queueMonitorInterval*1000, queueName); |
111 |
|
|
} catch (PropertyNotFoundException e) { |
112 |
|
|
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
113 |
|
|
} |
114 |
tdb |
1.15 |
|
115 |
ajm |
1.8 |
// RootFilterServant start (for inbound child filter data) |
116 |
ajm |
1.10 |
_logger.write(toString(), Logger.DEBUG, "starting Root Filter"); |
117 |
tdb |
1.15 |
RootFilterServant filterServant = new RootFilterServant(queue); |
118 |
ajm |
1.8 |
// bind to the naming service as a filter |
119 |
tdb |
1.41 |
_refman.bindToOrb(filterServant, "iscream.Filter\\." + RootFilter.NAME); |
120 |
tdb |
1.1 |
|
121 |
tdb |
1.43 |
// Startup the CORBA Listener |
122 |
|
|
_logger.write(toString(), Logger.DEBUG, "starting servant for inbound clients"); |
123 |
|
|
CorbaClientListenerServant corbaServant = new CorbaClientListenerServant(queue); |
124 |
|
|
_refman.bindToOrb(corbaServant, "iscream.ClientInterface\\." + RootFilter.NAME); |
125 |
|
|
|
126 |
ajm |
1.10 |
_logger.write(toString(), Logger.SYSINIT, "started"); |
127 |
tdb |
1.18 |
|
128 |
tdb |
1.29 |
} |
129 |
|
|
|
130 |
|
|
/** |
131 |
|
|
* Does a dependency check. Used mainly at startup to |
132 |
|
|
* see if the required dependencies (components) are up |
133 |
|
|
* and running. |
134 |
|
|
* |
135 |
|
|
* @return a boolean value, true if the depdencies are satisfied |
136 |
|
|
*/ |
137 |
|
|
public boolean depCheck() { |
138 |
tdb |
1.35 |
org.omg.CORBA.Object obj; |
139 |
|
|
|
140 |
|
|
// first we need to check the Configuration system is available |
141 |
tdb |
1.29 |
try { |
142 |
|
|
// first check the ConfigurationManager is alive |
143 |
|
|
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
144 |
tdb |
1.35 |
} catch(ComponentCORBAException e) { |
145 |
|
|
System.err.println(toString() + ": Dependency Failure: "+e); |
146 |
|
|
return false; |
147 |
|
|
} |
148 |
|
|
|
149 |
tdb |
1.29 |
// dependency check suceeded |
150 |
|
|
return true; |
151 |
tdb |
1.1 |
} |
152 |
ajm |
1.10 |
|
153 |
|
|
/** |
154 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
155 |
|
|
* method to provide clean logging (every class should have this). |
156 |
|
|
* |
157 |
tdb |
1.42 |
* This uses the uk.org.iscream.cms.util.NameFormat class |
158 |
ajm |
1.10 |
* to format the toString() |
159 |
|
|
* |
160 |
|
|
* @return the name of this class and its CVS revision |
161 |
|
|
*/ |
162 |
|
|
public String toString() { |
163 |
|
|
return FormatName.getName( |
164 |
ajm |
1.14 |
NAME, |
165 |
ajm |
1.10 |
getClass().getName(), |
166 |
|
|
REVISION); |
167 |
tdb |
1.1 |
} |
168 |
|
|
|
169 |
|
|
//---PRIVATE METHODS--- |
170 |
|
|
|
171 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
172 |
|
|
|
173 |
|
|
//---ATTRIBUTES--- |
174 |
ajm |
1.10 |
|
175 |
|
|
/** |
176 |
|
|
* This holds a reference to the |
177 |
|
|
* system logger that is being used. |
178 |
|
|
*/ |
179 |
ajm |
1.26 |
private Logger _logger; |
180 |
ajm |
1.10 |
|
181 |
|
|
/** |
182 |
|
|
* A reference to the reference manager in use |
183 |
|
|
*/ |
184 |
tdb |
1.30 |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
185 |
ajm |
1.10 |
|
186 |
tdb |
1.1 |
//---STATIC ATTRIBUTES--- |
187 |
ajm |
1.10 |
|
188 |
|
|
/** |
189 |
|
|
* The friendly name for this component, used by |
190 |
|
|
* all related classes. |
191 |
|
|
* This is set from the configuration. |
192 |
|
|
*/ |
193 |
|
|
public static String NAME; |
194 |
tdb |
1.1 |
|
195 |
tdb |
1.43 |
} |