KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty > JettyContainerImpl


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.jetty;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.geronimo.gbean.GBeanInfo;
24 import org.apache.geronimo.gbean.GBeanInfoBuilder;
25 import org.apache.geronimo.gbean.GBeanLifecycle;
26 import org.apache.geronimo.webservices.SoapHandler;
27 import org.apache.geronimo.webservices.WebServiceContainer;
28 import org.mortbay.http.*;
29 import org.mortbay.jetty.Server;
30
31 /**
32  * @version $Rev: 156623 $ $Date: 2005-03-08 22:31:52 -0800 (Tue, 08 Mar 2005) $
33  */

34 public class JettyContainerImpl implements JettyContainer, SoapHandler, GBeanLifecycle {
35     private final Server server;
36     private final Map JavaDoc webServices = new HashMap JavaDoc();
37
38
39     public JettyContainerImpl() {
40         server = new JettyServer();
41     }
42
43     public void resetStatistics() {
44         server.statsReset();
45     }
46
47     public void setCollectStatistics(boolean on) {
48         server.setStatsOn(on);
49     }
50
51     public boolean getCollectStatistics() {
52         return server.getStatsOn();
53     }
54
55     public long getCollectStatisticsStarted() {
56         return server.getStatsOnMs();
57     }
58
59     public int getConnections() {
60         return server.getConnections();
61     }
62
63     public int getConnectionsOpen() {
64         return server.getConnectionsOpen();
65     }
66
67     public int getConnectionsOpenMax() {
68         return server.getConnectionsOpenMax();
69     }
70
71     public long getConnectionsDurationAve() {
72         return server.getConnectionsDurationAve();
73     }
74
75     public long getConnectionsDurationMax() {
76         return server.getConnectionsDurationMax();
77     }
78
79     public int getConnectionsRequestsAve() {
80         return server.getConnectionsRequestsAve();
81     }
82
83     public int getConnectionsRequestsMax() {
84         return server.getConnectionsRequestsMax();
85     }
86
87     public int getErrors() {
88         return server.getErrors();
89     }
90
91     public int getRequests() {
92         return server.getRequests();
93     }
94
95     public int getRequestsActive() {
96         return server.getRequestsActive();
97     }
98
99     public int getRequestsActiveMax() {
100         return server.getRequestsActiveMax();
101     }
102
103     public long getRequestsDurationAve() {
104         return server.getRequestsDurationAve();
105     }
106
107     public long getRequestsDurationMax() {
108         return server.getRequestsDurationMax();
109     }
110
111     public void addListener(HttpListener listener) {
112         server.addListener(listener);
113     }
114
115     public void removeListener(HttpListener listener) {
116         server.removeListener(listener);
117     }
118
119     public void addContext(HttpContext context) {
120         server.addContext(context);
121     }
122
123     public void removeContext(HttpContext context) {
124         server.removeContext(context);
125     }
126
127     public void addRealm(UserRealm realm) {
128         server.addRealm(realm);
129     }
130
131     public void removeRealm(UserRealm realm) {
132         server.removeRealm(realm.getName());
133     }
134
135     public void addWebService(String JavaDoc contextPath, WebServiceContainer webServiceContainer) throws Exception JavaDoc {
136         JettyEJBWebServiceContext webServiceContext = new JettyEJBWebServiceContext(contextPath, webServiceContainer);
137         addContext(webServiceContext);
138         webServiceContext.start();
139         webServices.put(contextPath, webServiceContext);
140     }
141
142     public void removeWebService(String JavaDoc contextPath) {
143         JettyEJBWebServiceContext webServiceContext = (JettyEJBWebServiceContext) webServices.get(contextPath);
144         removeContext(webServiceContext);
145     }
146
147     public void setRequestLog(RequestLog log) {
148         server.setRequestLog(log);
149     }
150
151     /* ------------------------------------------------------------ */
152     public RequestLog getRequestLog() {
153         return server.getRequestLog();
154     }
155
156     public void doStart() throws Exception JavaDoc {
157         server.start();
158     }
159
160     public void doStop() {
161         try {
162             server.stop(true);
163         } catch (InterruptedException JavaDoc e) {
164         }
165     }
166
167     public void doFail() {
168         try {
169             server.stop(false);
170         } catch (InterruptedException JavaDoc e) {
171             // continue
172
}
173     }
174
175     public static final GBeanInfo GBEAN_INFO;
176
177     static {
178         GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder("Jetty Web Container", JettyContainerImpl.class);
179         infoBuilder.addAttribute("collectStatistics", Boolean.TYPE, true);
180         infoBuilder.addAttribute("collectStatisticsStarted", Long.TYPE, false);
181         infoBuilder.addAttribute("connections", Integer.TYPE, false);
182         infoBuilder.addAttribute("connectionsOpen", Integer.TYPE, false);
183         infoBuilder.addAttribute("connectionsOpenMax", Integer.TYPE, false);
184         infoBuilder.addAttribute("connectionsDurationAve", Long.TYPE, false);
185         infoBuilder.addAttribute("connectionsDurationMax", Long.TYPE, false);
186         infoBuilder.addAttribute("connectionsRequestsAve", Integer.TYPE, false);
187         infoBuilder.addAttribute("connectionsRequestsMax", Integer.TYPE, false);
188         infoBuilder.addAttribute("errors", Integer.TYPE, false);
189         infoBuilder.addAttribute("requests", Integer.TYPE, false);
190         infoBuilder.addAttribute("requestsActive", Integer.TYPE, false);
191         infoBuilder.addAttribute("requestsActiveMax", Integer.TYPE, false);
192         infoBuilder.addAttribute("requestsDurationAve", Long.TYPE, false);
193         infoBuilder.addAttribute("requestsDurationMax", Long.TYPE, false);
194         infoBuilder.addOperation("resetStatistics");
195
196         infoBuilder.addAttribute("requestLog", RequestLog.class, false);
197
198         infoBuilder.addOperation("addListener", new Class JavaDoc[]{HttpListener.class});
199         infoBuilder.addOperation("removeListener", new Class JavaDoc[]{HttpListener.class});
200         infoBuilder.addOperation("addContext", new Class JavaDoc[]{HttpContext.class});
201         infoBuilder.addOperation("removeContext", new Class JavaDoc[]{HttpContext.class});
202         infoBuilder.addOperation("addRealm", new Class JavaDoc[]{UserRealm.class});
203         infoBuilder.addOperation("removeRealm", new Class JavaDoc[]{UserRealm.class});
204
205         infoBuilder.addInterface(SoapHandler.class);
206
207         GBEAN_INFO = infoBuilder.getBeanInfo();
208     }
209
210     public static GBeanInfo getGBeanInfo() {
211         return GBEAN_INFO;
212     }
213
214 }
215
Popular Tags