Source code: juju/reattore/Reattore.java
1 /* Reattore HTTP Server
2
3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 $Id: Reattore.java,v 1.14 2003/03/05 04:31:56 michaelh Exp $
20 */
21
22 package juju.reattore;
23
24 import java.io.*;
25
26 import java.io.*;
27 import java.net.URL;
28
29 import org.apache.commons.digester.xmlrules.*;
30 import org.apache.commons.digester.*;
31 import org.apache.commons.logging.*;
32
33 import juju.reattore.server.http.HttpServer;
34 import juju.reattore.core.reactor.impl.CombinedReactor;
35
36 /** Main entry point for the HTTP server. Creates the server tree
37 from a configuration file and runs it.
38
39 @group Top
40 @tag server
41 @children Reactor
42 */
43 public class Reattore {
44
45 private static Log log = LogFactory.getLog(Reattore.class);
46
47 private static final String RULES = "juju/reattore/rules.xml";
48
49 private CombinedReactor reactor;
50
51 /** Sets the top level reactor that will be run after
52 configuration.
53
54 @param reactor The reactor to use.
55 */
56 public void setReactor(CombinedReactor reactor) {
57 this.reactor = reactor;
58 }
59
60 /** Creates and starts the server.
61
62 @throws IOException passed up from lower levels.
63 */
64 public void go()
65 throws IOException {
66
67 reactor.go();
68 }
69
70 private static Reattore load(String fname)
71 throws Exception {
72
73 URL rules = Reattore.class.getClassLoader().getResource(RULES);
74
75 if (rules == null) {
76 throw new RuntimeException("Unable to locate " + RULES);
77 }
78
79 Digester dig = DigesterLoader.createDigester(rules);
80
81 return (Reattore)dig.parse(new File(fname));
82 }
83
84 /** Entry point.
85
86 @param args First - optional config file name.
87 @throws Exception passed up from lower levels.
88 */
89 public static void main(String[] args)
90 throws Exception {
91
92 String config = args.length > 0 ? args[0] : "etc/default-config.xml";
93
94 log.info("Loading configuration from " + config);
95
96 Reattore re = load(config);
97
98 log.info("All servers started");
99 re.go();
100 }
101 }