KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > derby > DerbyNetworkGBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.geronimo.derby;
18
19 import java.net.InetAddress JavaDoc;
20 import java.net.InetSocketAddress JavaDoc;
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 /**
30  * A GBean that manages remote network access to the embedded Derby server.
31  *
32  * todo need to figure out how to configure this without using system properties
33  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
34  */

35 public class DerbyNetworkGBean implements GBeanLifecycle {
36     private static final Log log = LogFactory.getLog("DerbyNetwork");
37
38     private NetworkServerControl network;
39     private String JavaDoc host = "localhost";
40     private int port = 1527;
41
42     public DerbyNetworkGBean(DerbySystem system) {
43     }
44
45     public String JavaDoc getHost() {
46         return host;
47     }
48
49     public void setHost(String JavaDoc 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 JavaDoc getAddress() {
62         return new InetSocketAddress JavaDoc(getHost(), getPort());
63     }
64
65     public void doStart() throws Exception JavaDoc {
66         InetAddress JavaDoc address = InetAddress.getByName(host);
67         network = new NetworkServerControl(address, port);
68         network.start(null); // todo work out how to add this to our log stream
69
log.debug("Started on host " + host + ':' + port);
70     }
71
72     public void doStop() throws Exception JavaDoc {
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 JavaDoc.class, true, true);
95         infoFactory.addAttribute("port", Integer.TYPE, true, true);
96         infoFactory.addAttribute("address", InetSocketAddress JavaDoc.class, false);
97         infoFactory.addReference("derbySystem", DerbySystem.class, "GBean");
98         infoFactory.setConstructor(new String JavaDoc[]{"derbySystem"});
99         GBEAN_INFO = infoFactory.getBeanInfo();
100     }
101 }
102
Popular Tags