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.17 by ajm, Wed Dec 13 15:47:26 2000 UTC

# Line 8 | Line 8 | import uk.ac.ukc.iscream.filter.*;
8  
9   /**
10   * A Filter Startup Class
11 + * A filter is an iscream component.
12   *
13   * @author  $Author$
14   * @version $Id$
15   */
16 < class FilterMain {
16 > public class FilterMain implements uk.ac.ukc.iscream.util.Component {
17  
18   //---FINAL ATTRIBUTES---
19  
# Line 23 | Line 24 | class FilterMain {
24      
25   //---STATIC METHODS---
26  
27 <    public static void main(String[] args) {
28 <        // ***************************************
29 <        // VERY TEMPORARY - will find a better way
30 <        System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
31 <        System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
32 <        // ***************************************
27 > //---CONSTRUCTORS---
28 >    
29 >    /**
30 >     * Constructs a Filter with the name given
31 >     *
32 >     * @param givenName the name
33 >     */
34 >    public FilterMain(String givenName) {
35 >        NAME = givenName;
36 >    }
37  
38 <        // get our name from the command line
39 <        String ourName = "";
40 <        if (args.length == 1) {
41 <            ourName = args[0];
42 <        }
43 <        else {
44 <            usage();
45 <        }
41 <        
42 <        // 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);
46 <        
47 <        refman.getLogger().write(toString, Logger.SYSINIT, "coming up");
38 > //---PUBLIC METHODS---
39 >
40 >    /**
41 >     * Starts the Filter component
42 >     */
43 >    public void start() throws ComponentStartException {
44 >              
45 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
46              
47          // configuration variables we require
48          int UDPListenPort = 0;
49          int TCPListenPort = 0;
50          String parentFilterName = null;
51  
52 <        Configuration config = refman.getCM().getConfiguration(refman.getName());
52 >        Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME);
53          if (config == null) {
54 <            throw new RuntimeException ("CRITICAL:Unable to obtain configuration" +
55 <                                        "         Advise you check the i-scream log for more information.");
54 >            System.err.println("CRITICAL:Unable to obtain configuration" +
55 >                               "\n         Advise you check the i-scream log for more information.");
56 >            _logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration");
57 >            System.exit(1);
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 <
64 >                System.err.println ("CRITICAL:Unable to obtain required configuration property" +
65 >                                    "\n         Advise you check the i-scream log for more information.");
66 >                _logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present");
67 >                System.exit(1);
68              }
69          }
70 <        refman.getLogger().write(toString, Logger.SYSINIT, "configured");
70 >        _logger.write(toString(), Logger.SYSINIT, "configured");
71 >        
72          // get parent
73 <        Filter parentFilter = FilterHelper.narrow(refman.getCORBARef("iscream.Filter." + parentFilterName));
73 >        Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName));
74          
74                
75        
75          // FilterServant start (for inbound child filter data)
76 <        refman.getLogger().write(toString, Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName);
76 >        _logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName);
77          FilterServant filterServant = new FilterServant(parentFilter, TCPListenPort, UDPListenPort);
78 <        refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName());
78 >        _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
79  
80          // UDL Reader start (for inbound host data)
81 <        refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter UDP listener");
81 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
82          UDPReader udpReader = new UDPReader(UDPListenPort, parentFilter);
83          udpReader.start();
84  
85          // TCP Reader start (for heartbeats)
86 <        refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter TCP listener");
86 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
87          TCPReader tcpReader = new TCPReader(TCPListenPort, parentFilter);
88          tcpReader.start();
89          
90 <        // 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();
90 >        _logger.write(toString(), Logger.SYSINIT, "started");
91      }
92  
93 <    /**
94 <     * A simple method to print the usage of this class.
95 <     * It never returns, but instead exits to the system
96 <     * with a value 1, to indicate the system did not start
97 <     * properly.
93 >    /**
94 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
95 >     * method to provide clean logging (every class should have this).
96 >     *
97 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
98 >     * to format the toString()
99 >     *
100 >     * @return the name of this class and its CVS revision
101       */
102 <    public static void usage() {
103 <        System.out.println("USAGE: java FilterMain <name>");
104 <        System.out.println("WHERE <name>:");
105 <        System.out.println("      The unique identifier for the Filter in the system.");
106 <        System.exit(1);
102 >    public String toString() {
103 >        return FormatName.getName(
104 >            NAME,
105 >            getClass().getName(),
106 >            REVISION);
107      }
108  
112 //---CONSTRUCTORS---
113
114 //---PUBLIC METHODS---
115
109   //---PRIVATE METHODS---
110  
111   //---ACCESSOR/MUTATOR METHODS---
112  
113   //---ATTRIBUTES---
114  
115 +    /**
116 +     * This holds a reference to the
117 +     * system logger that is being used.
118 +     */
119 +    private Logger _logger = ReferenceManager.getInstance().getLogger();
120 +
121 +    /**
122 +     * A reference to the reference manager in use
123 +     */
124 +    private ReferenceManager _refman = ReferenceManager.getInstance();
125 +
126   //---STATIC ATTRIBUTES---
127 +
128 +    /**
129 +     * The friendly name for this component, used by
130 +     * all related classes.
131 +     * This is set from the configuration.
132 +     */
133 +    public static String NAME;
134  
135   }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines