1 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 31 public abstract class JettyConnector implements GBeanLifecycle { 32 private final JettyContainer container; 33 protected final HttpListener listener; 34 35 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 getDefaultScheme() { 54 return listener.getDefaultScheme(); 55 } 56 57 public String 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 { 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 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 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 .class, false); 103 infoFactory.addAttribute("host", String .class, false); 104 infoFactory.addAttribute("port", int.class, true); 105 infoFactory.addReference("JettyContainer", JettyContainer.class, NameFactory.GERONIMO_SERVICE); 106 infoFactory.setConstructor(new String [] {"JettyContainer"}); 107 GBEAN_INFO = infoFactory.getBeanInfo(); 108 } 109 } 110 | Popular Tags |