Save This Page
Home » jboss-5.0.0.CR1-src » org.jboss.ha » jndi » [javadoc | source]
    1   /*
    2     * JBoss, Home of Professional Open Source
    3     * Copyright 2005, JBoss Inc., and individual contributors as indicated
    4     * by the @authors tag. See the copyright.txt in the distribution for a
    5     * full listing of individual contributors.
    6     *
    7     * This is free software; you can redistribute it and/or modify it
    8     * under the terms of the GNU Lesser General Public License as
    9     * published by the Free Software Foundation; either version 2.1 of
   10     * the License, or (at your option) any later version.
   11     *
   12     * This software is distributed in the hope that it will be useful,
   13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   15     * Lesser General Public License for more details.
   16     *
   17     * You should have received a copy of the GNU Lesser General Public
   18     * License along with this software; if not, write to the Free
   19     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   20     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   21     */
   22   package org.jboss.ha.jndi;
   23   
   24   import java.rmi.server.RMIClientSocketFactory;
   25   import java.rmi.server.RMIServerSocketFactory;
   26   
   27   import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
   28   import org.jboss.ha.framework.interfaces.RoundRobin;
   29   import org.jboss.ha.framework.server.HARMIServerImpl;
   30   import org.jnp.interfaces.Naming;
   31   
   32   /** Management Bean for HA-JNDI service for the legacy version that is coupled
   33    * to the RMI/JRMP protocol. The DetachedHANamingService should be used with
   34    * the appropriate detached invoker service.
   35    *
   36    * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
   37    * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>
   38    * @author Scott.Stark@jboss.org
   39    * @version $Revision: 74736 $
   40    */
   41   public class HANamingService
   42      extends DetachedHANamingService
   43      implements HANamingServiceMBean
   44   {
   45      // Constants -----------------------------------------------------
   46      
   47      // Attributes ----------------------------------------------------
   48      /** An optional custom client socket factory */
   49      private RMIClientSocketFactory clientSocketFactory;
   50      /** An optional custom server socket factory */
   51      private RMIServerSocketFactory serverSocketFactory;
   52      /** The class name of the optional custom client socket factory */
   53      private String clientSocketFactoryName;
   54      /** The class name of the optional custom server socket factory */
   55      private String serverSocketFactoryName;
   56      /** The class name of the load balancing policy */
   57      private String loadBalancePolicy = RoundRobin.class.getName();
   58      /** The RMI port on which the Naming implementation will be exported. The
   59       default is 0 which means use any available port. */
   60      private int rmiPort = 0;
   61      protected String replicantName = "HAJNDI";
   62      private HARMIServerImpl rmiserver;
   63   
   64      // Public --------------------------------------------------------
   65   
   66      public HANamingService()
   67      {
   68         // for JMX
   69      }
   70   
   71      public void setRmiPort(int p)
   72      {
   73         this.rmiPort = p;
   74      }
   75      public int getRmiPort()
   76      {
   77         return this.rmiPort;
   78      }
   79      
   80      public String getClientSocketFactory()
   81      {
   82         return this.serverSocketFactoryName;
   83      }
   84      
   85      public void setClientSocketFactory(String factoryClassName)
   86         throws ClassNotFoundException, InstantiationException, IllegalAccessException
   87      {
   88         this.clientSocketFactoryName = factoryClassName;
   89         ClassLoader loader = Thread.currentThread().getContextClassLoader();
   90         Class<?> clazz = loader.loadClass(this.clientSocketFactoryName);
   91         this.clientSocketFactory = (RMIClientSocketFactory) clazz.newInstance();
   92      }
   93      
   94      public String getServerSocketFactory()
   95      {
   96         return this.serverSocketFactoryName;
   97      }
   98      public void setServerSocketFactory(String factoryClassName)
   99         throws ClassNotFoundException, InstantiationException, IllegalAccessException
  100      {
  101         this.serverSocketFactoryName = factoryClassName;
  102         ClassLoader loader = Thread.currentThread().getContextClassLoader();
  103         Class<?> clazz = loader.loadClass(this.serverSocketFactoryName);
  104         this.serverSocketFactory = (RMIServerSocketFactory) clazz.newInstance();
  105      }
  106   
  107      public String getLoadBalancePolicy()
  108      {
  109         return this.loadBalancePolicy;
  110      }
  111      public void setLoadBalancePolicy(String policyClassName)
  112      {
  113         this.loadBalancePolicy = policyClassName;
  114      }
  115      
  116      @Override
  117      protected void stopService() throws Exception
  118      {
  119         super.stopService();
  120         // Unexport server
  121         this.log.debug("destroy ha rmiserver");
  122         this.rmiserver.destroy ();
  123      }
  124   
  125      @Override
  126      protected Naming getNamingProxy() throws Exception
  127      {
  128         this.rmiserver = new HARMIServerImpl(this.clusterPartition, this.replicantName, Naming.class,
  129            this.theServer, this.rmiPort, this.clientSocketFactory, this.serverSocketFactory, this.bindAddress);
  130   
  131         ClassLoader cl = Thread.currentThread().getContextClassLoader();
  132         Class<?> clazz = cl.loadClass(this.loadBalancePolicy);
  133         LoadBalancePolicy policy = (LoadBalancePolicy)clazz.newInstance();
  134   
  135         Naming proxy = (Naming) this.rmiserver.createHAStub(policy);
  136         return proxy;
  137      }
  138   }

Save This Page
Home » jboss-5.0.0.CR1-src » org.jboss.ha » jndi » [javadoc | source]