KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty > connector > JettyConnector


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.connector;
19
20 import org.apache.geronimo.gbean.GBeanInfo;
21 import org.apache.geronimo.gbean.GBeanInfoBuilder;
22 import org.apache.geronimo.gbean.GBeanLifecycle;
23 import org.apache.geronimo.jetty.JettyContainer;
24 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
25 import org.mortbay.http.HttpListener;
26 import org.mortbay.util.ThreadedServer;
27
28 /**
29  * @version $Rev: 158582 $ $Date: 2005-03-22 01:17:09 -0800 (Tue, 22 Mar 2005) $
30  */

31 public abstract class JettyConnector implements GBeanLifecycle {
32     private final JettyContainer container;
33     protected final HttpListener listener;
34
35     /**
36      * Only used to allow declaration as a reference.
37      */

38     public JettyConnector() {
39         container = null;
40         listener = null;
41     }
42
43     public JettyConnector(JettyContainer container) {
44         this.container = container;
45         this.listener = null;
46     }
47
48     public JettyConnector(JettyContainer container, HttpListener listener) {
49         this.container = container;
50         this.listener = listener;
51     }
52
53     public String JavaDoc getDefaultScheme() {
54         return listener.getDefaultScheme();
55     }
56
57     public String JavaDoc getHost() {
58         return listener.getHost();
59     }
60     
61     public int getPort() {
62         return listener.getPort();
63     }
64
65     public void setPort(int port) {
66         listener.setPort(port);
67     }
68
69     public void doStart() throws Exception JavaDoc {
70         container.addListener(listener);
71         ((ThreadedServer) listener).open();
72         listener.start();
73     }
74
75     public void doStop() {
76         while (true) {
77             try {
78                 listener.stop();
79                 container.removeListener(listener);
80                 return;
81             } catch (InterruptedException JavaDoc e) {
82                 continue;
83             }
84         }
85     }
86
87     public void doFail() {
88         while (true) {
89             try {
90                 listener.stop();
91                 container.removeListener(listener);
92                 return;
93             } catch (InterruptedException JavaDoc e) {
94                 continue;
95             }
96         }
97     }
98     public static final GBeanInfo GBEAN_INFO;
99
100     static {
101         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Jetty HTTP Connector", JettyConnector.class);
102         infoFactory.addAttribute("defaultScheme", String JavaDoc.class, false);
103         infoFactory.addAttribute("host", String JavaDoc.class, false);
104         infoFactory.addAttribute("port", int.class, true);
105         infoFactory.addReference("JettyContainer", JettyContainer.class, NameFactory.GERONIMO_SERVICE);
106         infoFactory.setConstructor(new String JavaDoc[] {"JettyContainer"});
107         GBEAN_INFO = infoFactory.getBeanInfo();
108     }
109 }
110
Popular Tags