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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/FilterMain.java (file contents):
Revision 1.15 by ajm, Thu Nov 30 03:05:47 2000 UTC vs.
Revision 1.31 by tdb, Tue May 29 17:02:35 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.filter;
2 > package uk.org.iscream.cms.server.filter;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.util.*;
6 < import uk.ac.ukc.iscream.core.*;
7 < import uk.ac.ukc.iscream.filter.*;
5 > import uk.org.iscream.cms.server.util.*;
6 > import uk.org.iscream.cms.server.core.*;
7 > import uk.org.iscream.cms.server.componentmanager.*;
8 > import uk.org.iscream.cms.server.filter.*;
9  
10   /**
11   * A Filter Startup Class
12 + * A filter is an iscream component.
13   *
14   * @author  $Author$
15   * @version $Id$
16   */
17 < class FilterMain {
17 > public class FilterMain implements Component {
18  
19   //---FINAL ATTRIBUTES---
20  
# Line 23 | Line 25 | class FilterMain {
25      
26   //---STATIC METHODS---
27  
28 <    public static void main(String[] args) {
29 <        // ***************************************
30 <        // VERY TEMPORARY - will find a better way
31 <        System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
32 <        System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
33 <        // ***************************************
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 <        // get our name from the command line
40 <        String ourName = "";
41 <        if (args.length == 1) {
42 <            ourName = args[0];
43 <        }
44 <        else {
45 <            usage();
46 <        }
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 <        // can't have a real toString() :)
43 <        String toString = "Filter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
44 <                
45 <        ReferenceManager refman = ReferenceManager.init(null, ourName);
48 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
49          
50 <        refman.getLogger().write(toString, Logger.SYSINIT, "coming up");
51 <            
52 <        // configuration variables we require
53 <        int UDPListenPort = 0;
54 <        int TCPListenPort = 0;
55 <        String parentFilterName = null;
56 <
57 <        Configuration config = refman.getCM().getConfiguration(refman.getName());
58 <        if (config == null) {
59 <            throw new RuntimeException ("CRITICAL:Unable to obtain configuration" +
60 <                                        "         Advise you check the i-scream log for more information.");
61 <        } else {
62 <            try {
63 <                UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort"));
64 <                TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort"));
65 <                parentFilterName = config.getProperty("Filter.parentFilter");
66 <            } catch (org.omg.CORBA.MARSHAL e) {
67 <                refman.getLogger().write(toString, Logger.FATAL, "required config property not present");
68 <                throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" +
69 <                                            "         Advise you check the i-scream log for more information.");
70 <
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          }
70        refman.getLogger().write(toString, Logger.SYSINIT, "configured");
71        // get parent
72        Filter parentFilter = FilterHelper.narrow(refman.getCORBARef("iscream.Filter." + parentFilterName));
87          
88 <                
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 <        refman.getLogger().write(toString, Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName);
105 <        FilterServant filterServant = new FilterServant(parentFilter, TCPListenPort, UDPListenPort);
106 <        refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName());
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 <        refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter UDP listener");
110 <        UDPReader udpReader = new UDPReader(UDPListenPort, parentFilter);
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 <        refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter TCP listener");
115 <        TCPReader tcpReader = new TCPReader(TCPListenPort, parentFilter);
114 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
115 >        TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
116          tcpReader.start();
117          
118 <        // start the POA off
92 <        // now we are running, we just need to serve
93 <        // so we ask the orb to block for us until it has finished
94 <        refman.activatePOA();
95 <        refman.getLogger().write(toString, Logger.SYSINIT, "started");
96 <        refman.getORB().run();
118 >        _logger.write(toString(), Logger.SYSINIT, "started");
119      }
120 <
121 <    /**
122 <     * A simple method to print the usage of this class.
123 <     * It never returns, but instead exits to the system
124 <     * with a value 1, to indicate the system did not start
125 <     * properly.
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 static void usage() {
129 <        System.out.println("USAGE: java FilterMain <name>");
130 <        System.out.println("WHERE <name>:");
131 <        System.out.println("      The unique identifier for the Filter in the system.");
132 <        System.exit(1);
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.cms.server.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  
112 //---CONSTRUCTORS---
113
114 //---PUBLIC METHODS---
115
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 < }            
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 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines