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.25 by tdb, Tue Mar 13 16:25:57 2001 UTC

# Line 4 | Line 4 | package uk.ac.ukc.iscream.filter;
4   //---IMPORTS---
5   import uk.ac.ukc.iscream.util.*;
6   import uk.ac.ukc.iscream.core.*;
7 + import uk.ac.ukc.iscream.componentmanager.*;
8   import uk.ac.ukc.iscream.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];
39 > //---PUBLIC METHODS---
40 >
41 >    /**
42 >     * Starts the Filter component
43 >     */
44 >    public void start() throws ComponentStartException {
45 >        // get references to key objects
46 >        _refman = ReferenceManager.getInstance();
47 >        _logger = ReferenceManager.getInstance().getLogger();
48 >        
49 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
50 >        
51 >        ConfigurationProxy cp = ConfigurationProxy.getInstance();
52 >        
53 >        int UDPListenPort, TCPListenPort;
54 >        try {
55 >            UDPListenPort = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Filter.UDPListenPort"));
56 >            TCPListenPort = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Filter.TCPListenPort"));
57 >        } catch (PropertyNotFoundException e) {
58 >            throw new ComponentStartException("Unable to obtain requried configuration property for component: " + e);
59          }
38        else {
39            usage();
40        }
60          
61 <        // can't have a real toString() :)
62 <        String toString = "Filter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
44 <                
45 <        ReferenceManager refman = ReferenceManager.init(null, ourName);
61 >        // setup a queue
62 >        Queue queue = new Queue();
63          
64 <        refman.getLogger().write(toString, Logger.SYSINIT, "coming up");
65 <            
66 <        // configuration variables we require
67 <        int UDPListenPort = 0;
68 <        int TCPListenPort = 0;
69 <        String parentFilterName = null;
70 <
71 <        Configuration config = refman.getCM().getConfiguration(refman.getName());
55 <        if (config == null) {
56 <            throw new RuntimeException ("CRITICAL:Unable to obtain configuration" +
57 <                                        "         Advise you check the i-scream log for more information.");
58 <        } else {
59 <            try {
60 <                UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort"));
61 <                TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort"));
62 <                parentFilterName = config.getProperty("Filter.parentFilter");
63 <            } catch (org.omg.CORBA.MARSHAL e) {
64 <                refman.getLogger().write(toString, Logger.FATAL, "required config property not present");
65 <                throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" +
66 <                                            "         Advise you check the i-scream log for more information.");
67 <
68 <            }
64 >        // startup a monitor on this queue
65 >        try {
66 >            // try to get the interval, if this fails, we won't start up the monitor
67 >            int queueMonitorInterval = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Queue.MonitorInterval"));
68 >            String queueName = NAME + " Filter";
69 >            queue.startMonitor(queueMonitorInterval*1000, queueName);
70 >        } catch (PropertyNotFoundException e) {
71 >            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
72          }
70        refman.getLogger().write(toString, Logger.SYSINIT, "configured");
71        // get parent
72        Filter parentFilter = FilterHelper.narrow(refman.getCORBARef("iscream.Filter." + parentFilterName));
73          
74 <                
74 >        // Start a filter thread
75 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer");
76 >        FilterThread filterThread = new FilterThread(queue);
77 >        filterThread.start();
78          
79          // FilterServant start (for inbound child filter data)
80 <        refman.getLogger().write(toString, Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName);
81 <        FilterServant filterServant = new FilterServant(parentFilter, TCPListenPort, UDPListenPort);
82 <        refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName());
80 >        _logger.write(toString(), Logger.DEBUG, "starting Servant to listen for downstream filters");
81 >        FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue);
82 >        _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
83  
84          // UDL Reader start (for inbound host data)
85 <        refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter UDP listener");
86 <        UDPReader udpReader = new UDPReader(UDPListenPort, parentFilter);
85 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
86 >        UDPReader udpReader = new UDPReader(UDPListenPort, queue);
87          udpReader.start();
88  
89          // TCP Reader start (for heartbeats)
90 <        refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter TCP listener");
91 <        TCPReader tcpReader = new TCPReader(TCPListenPort, parentFilter);
90 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
91 >        TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
92          tcpReader.start();
93          
94 <        // 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();
94 >        _logger.write(toString(), Logger.SYSINIT, "started");
95      }
96  
97 <    /**
98 <     * A simple method to print the usage of this class.
99 <     * It never returns, but instead exits to the system
100 <     * with a value 1, to indicate the system did not start
101 <     * properly.
97 >    /**
98 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
99 >     * method to provide clean logging (every class should have this).
100 >     *
101 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
102 >     * to format the toString()
103 >     *
104 >     * @return the name of this class and its CVS revision
105       */
106 <    public static void usage() {
107 <        System.out.println("USAGE: java FilterMain <name>");
108 <        System.out.println("WHERE <name>:");
109 <        System.out.println("      The unique identifier for the Filter in the system.");
110 <        System.exit(1);
106 >    public String toString() {
107 >        return FormatName.getName(
108 >            NAME,
109 >            getClass().getName(),
110 >            REVISION);
111      }
112  
112 //---CONSTRUCTORS---
113
114 //---PUBLIC METHODS---
115
113   //---PRIVATE METHODS---
114  
115   //---ACCESSOR/MUTATOR METHODS---
116  
117   //---ATTRIBUTES---
118  
119 +    /**
120 +     * This holds a reference to the
121 +     * system logger that is being used.
122 +     */
123 +    private Logger _logger;
124 +
125 +    /**
126 +     * A reference to the reference manager in use
127 +     */
128 +    private ReferenceManager _refman;
129 +
130   //---STATIC ATTRIBUTES---
131  
132 < }            
132 >    /**
133 >     * The friendly name for this component, used by
134 >     * all related classes.
135 >     * This is set from the configuration.
136 >     */
137 >    public static String NAME;
138 >
139 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines