User: patriot1burke
  Date: 02/01/13 17:55:46

  Added:       src/main/org/jboss/proxy/ejb ProxyFactoryHA.java
  Log:
  Heterogeneous Partitions.  Also fixed problem where you could get bogus failover 
targets
  if making calls when a server starts up.
  
  Revision  Changes    Path
  1.1                  jbossmx/src/main/org/jboss/proxy/ejb/ProxyFactoryHA.java
  
  Index: ProxyFactoryHA.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.proxy.ejb;
  
  import javax.management.ObjectName;
  import javax.naming.InitialContext;
  import org.jboss.ejb.Container;
  import org.jboss.ejb.ContainerInvoker;
  import org.jboss.ejb.ContainerInvokerContainer;
  import org.jboss.invocation.Invoker;
  import org.jboss.proxy.ejb.handle.HomeHandleImpl;
  import org.jboss.metadata.EntityMetaData;
  import org.jboss.metadata.SessionMetaData;
  import org.jboss.system.Registry;
  import org.jboss.util.FinderResults;
  import org.jboss.logging.Logger;
  import org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxyHA;
  import org.jboss.invocation.jrmp.server.JRMPInvokerHA;
  import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
  import org.jboss.ha.framework.interfaces.HAPartition;
  import org.jboss.ha.framework.server.HATarget;
  
  import java.util.HashMap;
  /**
   * ProxyFactory for Clustering
   *
   *  @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
   *  @version $Revision: 1.1 $
   *
   *  <p><b>Revisions:</b><br>
   *  <p><b>2002/01/13: billb</b>
   *  <ol>
   *   <li>Initial Revisition
   *  </ol>
   */
  public class ProxyFactoryHA extends ProxyFactory
  {
     protected JRMPInvokerHA homejrmp;
     protected JRMPInvokerHA beanjrmp;
     protected HATarget homeTarget;
     protected HATarget beanTarget;
  
     protected void initInvokers() throws Exception
     {
        if (container == null) System.out.println("container is null");
        if (container.getBeanMetaData() == null) System.out.println("is null");
        if (container.getBeanMetaData().getClusterConfigMetaData() == null) 
System.out.println("is null");
        if (container.getBeanMetaData().getClusterConfigMetaData().getPartitionName() 
== null) System.out.println("is null");
  
        String partitionName = 
container.getBeanMetaData().getClusterConfigMetaData().getPartitionName();
        HAPartition partition = (HAPartition)new 
InitialContext().lookup("/HAPartition/" + partitionName);
        String beanName = 
"jboss.j2ee:service=EJB,jndiName="+container.getBeanMetaData().getJndiName();
  
        ObjectName oname;
        
        // Get the local invoker
        oname = new ObjectName(container.getBeanMetaData().getHomeInvoker());
        homejrmp = (JRMPInvokerHA)Registry.lookup(oname);
        if (homejrmp == null)
         throw new RuntimeException("home JRMPInvokerHA is null: " + oname);
  
        oname = new ObjectName(container.getBeanMetaData().getBeanInvoker());
        beanjrmp = (JRMPInvokerHA)Registry.lookup(oname);
        if (beanjrmp == null)
         throw new RuntimeException("bean JRMPInvokerHA is null: " + oname);
  
        // If invokers are the same don't register twice.
        if (homejrmp == beanjrmp)
        {
         homeTarget = new HATarget(partition, beanName, homejrmp);
         beanTarget = homeTarget;
         homejrmp.registerBean(beanName, homeTarget);
        }
        else
        {
         homeTarget = new HATarget(partition, beanName + "/home", homejrmp);
         homejrmp.registerBean(beanName, homeTarget);
         beanTarget = new HATarget(partition, beanName + "/bean", beanjrmp);
         beanjrmp.registerBean(beanName, beanTarget);
        }
  
  
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Class clazz;
        LoadBalancePolicy policy;
  
        clazz = 
cl.loadClass(container.getBeanMetaData().getClusterConfigMetaData().getHomeLoadBalancePolicy());
        policy = (LoadBalancePolicy)clazz.newInstance();
        homeInvoker = homejrmp.createProxy(beanName, policy);
  
        clazz = 
cl.loadClass(container.getBeanMetaData().getClusterConfigMetaData().getBeanLoadBalancePolicy());
        policy = (LoadBalancePolicy)clazz.newInstance();
        beanInvoker = homejrmp.createProxy(beanName, policy);
  
        JRMPInvokerProxyHA.colocation.add(beanName);
     }
           
     public void stop()
     {
        super.stop();
        try
        {
         String beanName = 
"jboss.j2ee:service=EJB,jndiName="+container.getBeanMetaData().getJndiName();
         // If invokers are the same don't register twice.
         JRMPInvokerProxyHA.colocation.remove(beanName);
         if (homejrmp == beanjrmp)
         {
            homejrmp.unregisterBean(beanName);
            homeTarget.destroy();
         }
         else
         {
            homejrmp.unregisterBean(beanName);
            beanjrmp.unregisterBean(beanName);
            homeTarget.destroy();
            beanTarget.destroy();
         }
        } 
        catch (Exception e)
        {
           // ignore.
        }
     }
     
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to