KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > httpd > HttpDaemon


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 /**
37  * The class responsible for controlling the http interface into Coadunation.
38  *
39  * @author Brett Chaldecott
40  */

41 public class HttpDaemon {
42     
43     // Global Constants
44
public final static String JavaDoc USERNAME_KEY = "daemon_username";
45     public final static int DEFAULT_PORT = 8085;
46     
47     // the class log variable
48
protected Logger log =
49         Logger.getLogger(HttpDaemon.class.getName());
50     
51     
52     // the java variables
53
private CoadunationThreadGroup threadGroup = null;
54     private Configuration configuration = null;
55     private HttpRequestManager httpRequestManager = null;
56     
57     
58     /**
59      *
60      * Creates a new instance of HttpDaemon
61      *
62      *
63      * @param threadGroup A grouping of threads.
64      * @param threadPermissions The object containing the permissions for all
65      * threads.
66      * @exception HHttpdException
67      */

68     public HttpDaemon(CoadunationThreadGroup threadGroup) throws HttpdException {
69         try {
70             // retrieve the configuration
71
configuration = ConfigurationFactory.getInstance().getConfig(
72                     this.getClass());
73             
74             // set the references
75
this.threadGroup = threadGroup.createThreadGroup();
76             
77             // init the request manager
78
httpRequestManager = new HttpRequestManager(threadGroup);
79             
80             // instanciate the request listener
81
RequestListenerThread requestListenerThread =
82                     new RequestListenerThread(httpRequestManager);
83             this.threadGroup.addThread(requestListenerThread,
84                     configuration.getString(HttpDaemon.USERNAME_KEY));
85             requestListenerThread.start();
86             
87         } catch (Exception JavaDoc ex) {
88             throw new HttpdException("Failed to instanciate the HttpDaemon :" +
89                     ex.getMessage(),ex);
90         }
91     }
92     
93     
94     
95     /**
96      * This method shuts down the http daemon.
97      */

98     public void shutdown() {
99         log.info("Shutting down the web services interface.");
100         threadGroup.terminate();
101         httpRequestManager.shutdown();
102     }
103 }
104
Popular Tags