1 17 package org.apache.geronimo.derby; 18 19 import java.net.InetAddress ; 20 import java.net.InetSocketAddress ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.derby.drda.NetworkServerControl; 25 import org.apache.geronimo.gbean.GBeanInfo; 26 import org.apache.geronimo.gbean.GBeanInfoBuilder; 27 import org.apache.geronimo.gbean.GBeanLifecycle; 28 29 35 public class DerbyNetworkGBean implements GBeanLifecycle { 36 private static final Log log = LogFactory.getLog("DerbyNetwork"); 37 38 private NetworkServerControl network; 39 private String host = "localhost"; 40 private int port = 1527; 41 42 public DerbyNetworkGBean(DerbySystem system) { 43 } 44 45 public String getHost() { 46 return host; 47 } 48 49 public void setHost(String host) { 50 this.host = host; 51 } 52 53 public int getPort() { 54 return port; 55 } 56 57 public void setPort(int port) { 58 this.port = port; 59 } 60 61 public InetSocketAddress getAddress() { 62 return new InetSocketAddress (getHost(), getPort()); 63 } 64 65 public void doStart() throws Exception { 66 InetAddress address = InetAddress.getByName(host); 67 network = new NetworkServerControl(address, port); 68 network.start(null); log.debug("Started on host " + host + ':' + port); 70 } 71 72 public void doStop() throws Exception { 73 if (network != null) { 74 try { 75 network.shutdown(); 76 } finally { 77 network = null; 78 } 79 } 80 log.debug("Stopped"); 81 } 82 83 public void doFail() { 84 } 85 86 public static final GBeanInfo GBEAN_INFO; 87 88 public static GBeanInfo getGBeanInfo() { 89 return GBEAN_INFO; 90 } 91 92 static { 93 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Derby Connector", DerbyNetworkGBean.class); 94 infoFactory.addAttribute("host", String .class, true, true); 95 infoFactory.addAttribute("port", Integer.TYPE, true, true); 96 infoFactory.addAttribute("address", InetSocketAddress .class, false); 97 infoFactory.addReference("derbySystem", DerbySystem.class, "GBean"); 98 infoFactory.setConstructor(new String []{"derbySystem"}); 99 GBEAN_INFO = infoFactory.getBeanInfo(); 100 } 101 } 102 | Popular Tags |