01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2006 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library 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 GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * HttpDaemon.java
20: *
21: * The class responsible for controlling the http interface into Coadunation.
22: */
23:
24: package com.rift.coad.lib.httpd;
25:
26: // logging import
27: import org.apache.log4j.Logger;
28:
29: // coadunation imports
30: import com.rift.coad.lib.thread.CoadunationThreadGroup;
31: import com.rift.coad.lib.security.ThreadsPermissionContainer;
32: import com.rift.coad.lib.configuration.Configuration;
33: import com.rift.coad.lib.configuration.ConfigurationFactory;
34:
35: /**
36: * The class responsible for controlling the http interface into Coadunation.
37: *
38: * @author Brett Chaldecott
39: */
40: public class HttpDaemon {
41:
42: // Global Constants
43: public final static String USERNAME_KEY = "daemon_username";
44: public final static int DEFAULT_PORT = 8085;
45:
46: // the class log variable
47: protected Logger log = Logger.getLogger(HttpDaemon.class.getName());
48:
49: // the java variables
50: private CoadunationThreadGroup threadGroup = null;
51: private Configuration configuration = null;
52: private HttpRequestManager httpRequestManager = null;
53:
54: /**
55: *
56: * Creates a new instance of HttpDaemon
57: *
58: *
59: * @param threadGroup A grouping of threads.
60: * @param threadPermissions The object containing the permissions for all
61: * threads.
62: * @exception HHttpdException
63: */
64: public HttpDaemon(CoadunationThreadGroup threadGroup)
65: throws HttpdException {
66: try {
67: // retrieve the configuration
68: configuration = ConfigurationFactory.getInstance()
69: .getConfig(this .getClass());
70:
71: // set the references
72: this .threadGroup = threadGroup.createThreadGroup();
73:
74: // init the request manager
75: httpRequestManager = new HttpRequestManager(threadGroup);
76:
77: // instanciate the request listener
78: RequestListenerThread requestListenerThread = new RequestListenerThread(
79: httpRequestManager);
80: this .threadGroup.addThread(requestListenerThread,
81: configuration.getString(HttpDaemon.USERNAME_KEY));
82: requestListenerThread.start();
83:
84: } catch (Exception ex) {
85: throw new HttpdException(
86: "Failed to instanciate the HttpDaemon :"
87: + ex.getMessage(), ex);
88: }
89: }
90:
91: /**
92: * This method shuts down the http daemon.
93: */
94: public void shutdown() {
95: log.info("Shutting down the web services interface.");
96: threadGroup.terminate();
97: httpRequestManager.shutdown();
98: }
99: }
|