001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.derby;
017:
018: import java.net.InetAddress;
019: import java.net.InetSocketAddress;
020:
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023: import org.apache.derby.drda.NetworkServerControl;
024: import org.apache.geronimo.gbean.GBeanInfo;
025: import org.apache.geronimo.gbean.GBeanInfoBuilder;
026: import org.apache.geronimo.gbean.GBeanLifecycle;
027:
028: /**
029: * A GBean that manages remote network access to the embedded Derby server.
030: *
031: * todo need to figure out how to configure this without using system properties
032: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
033: */
034: public class DerbyNetworkGBean implements GBeanLifecycle {
035: private static final Log log = LogFactory.getLog("DerbyNetwork");
036:
037: private NetworkServerControl network;
038: private String host = "localhost";
039: private int port = 1527;
040:
041: public DerbyNetworkGBean(DerbySystem system) {
042: }
043:
044: public String getHost() {
045: return host;
046: }
047:
048: public void setHost(String host) {
049: this .host = host;
050: }
051:
052: public int getPort() {
053: return port;
054: }
055:
056: public void setPort(int port) {
057: this .port = port;
058: }
059:
060: public InetSocketAddress getAddress() {
061: return new InetSocketAddress(getHost(), getPort());
062: }
063:
064: public void doStart() throws Exception {
065: InetAddress address = InetAddress.getByName(host);
066: network = new NetworkServerControl(address, port);
067: network.start(null); // todo work out how to add this to our log stream
068: log.debug("Started on host " + host + ':' + port);
069: }
070:
071: public void doStop() throws Exception {
072: if (network != null) {
073: try {
074: network.shutdown();
075: } finally {
076: network = null;
077: }
078: }
079: log.debug("Stopped");
080: }
081:
082: public void doFail() {
083: }
084:
085: public static final GBeanInfo GBEAN_INFO;
086:
087: public static GBeanInfo getGBeanInfo() {
088: return GBEAN_INFO;
089: }
090:
091: static {
092: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
093: "Derby Connector", DerbyNetworkGBean.class);
094: infoFactory.addAttribute("host", String.class, true, true);
095: infoFactory.addAttribute("port", Integer.TYPE, true, true);
096: infoFactory.addAttribute("address", InetSocketAddress.class,
097: false);
098: infoFactory.addReference("derbySystem", DerbySystem.class,
099: "GBean");
100: infoFactory.setConstructor(new String[] { "derbySystem" });
101: GBEAN_INFO = infoFactory.getBeanInfo();
102: }
103: }
|