Home » geronimo-2.2-source-release » org.apache.geronimo.derby » [javadoc | source]

    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;
   20   import java.net.InetSocketAddress;
   21   
   22   import org.slf4j.Logger;
   23   import org.slf4j.LoggerFactory;
   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: 653782 $ $Date: 2008-05-06 07:10:14 -0700 (Tue, 06 May 2008) $
   34    */
   35   public class DerbyNetworkGBean implements GBeanLifecycle {
   36       private static final Logger log = LoggerFactory.getLogger(DerbyNetworkGBean.class);
   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); // 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 {
   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   }

Home » geronimo-2.2-source-release » org.apache.geronimo.derby » [javadoc | source]