FileDocCategorySizeDatePackage
ProxyFactoryHA.javaAPI DocJBoss 4.2.18832Fri Jul 13 20:52:36 BST 2007org.jboss.proxy.ejb

ProxyFactoryHA

public class ProxyFactoryHA extends ProxyFactory implements DistributedReplicantManager.ReplicantListener, ClusterProxyFactory
ProxyFactory for Clustering
author
Bill Burke
author
Scott.Stark@jboss.org
version
$Revision: 57188 $

Fields Summary
protected static Logger
log
protected String
replicantName
protected org.jboss.invocation.InvokerHA
jrmp
protected org.jboss.ha.framework.server.HATarget
target
protected org.jboss.ha.framework.interfaces.DistributedReplicantManager
drm
Constructors Summary
Methods Summary
protected voidcontainerIsAboutToStop()

      if( target != null )
      {
         target.setInvocationsAuthorization (HATarget.DISABLE_INVOCATIONS);
         target.disable ();
      }
   
protected voidcontainerIsFullyStarted()

      if( target != null )
         target.setInvocationsAuthorization (HATarget.ENABLE_INVOCATIONS);
   
public voidcreate()

   
        
   
      super.create ();
      
      // we register our inner-class to retrieve STATE notifications from our container
      //
      AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter ();
      filter.enableAttribute ("State");
      
      // ************************************************************************
      // NOTE: We could also subscribe for the container service events instead of the
      // ejbModule service events. This problem comes from beans using other beans
      // in the same ejbModule: we may receive an IllegalStateException thrown
      // by the Container implementation. Using ejbModule events solve this
      // problem. 
      // ************************************************************************
      this.container.getServer ().
         addNotificationListener (this.container.getEjbModule ().getServiceName (), 
                                  new ProxyFactoryHA.StateChangeListener (), 
                                  filter, 
                                  null);
   
public voiddestroy()

      super.destroy ();
      
      try
      {
         jrmp.unregisterBean(jmxName);
         target.destroy();
      } 
      catch (Exception ignored)
      {
         // ignore.
      }
      try
      {
         InitialContext ctx = new InitialContext();
         String homeInvokerName = jndiBinding + "-HomeInvoker";
         ctx.unbind(homeInvokerName);
      }
      catch(Exception ignored)
      {
      }
      try
      {
         InitialContext ctx = new InitialContext();
         String beanInvokerName = jndiBinding + "-RemoteInvoker";
         ctx.unbind(beanInvokerName);
      }
      catch(Exception ignored)
      {
      }

      if( drm != null )
         drm.unregisterListener (replicantName, this);
   
public synchronized voidreplicantsChanged(java.lang.String key, java.util.List newReplicants, int newReplicantsViewId)

      try
      {
         if (homeInvoker instanceof InvokerProxyHA)
         {
            ((InvokerProxyHA)homeInvoker).updateClusterInfo (target.getReplicants(), target.getCurrentViewId ());
         }
         if (beanInvoker instanceof InvokerProxyHA)
         {
            ((InvokerProxyHA)beanInvoker).updateClusterInfo (target.getReplicants(), target.getCurrentViewId ());
         }

         log.debug ("Rebinding in JNDI... " + key);
         rebindHomeProxy ();
      }
      catch (Exception none)
      {
         log.debug (none);
      }
   
protected voidsetupInvokers()

      String partitionName = container.getBeanMetaData().getClusterConfigMetaData().getPartitionName();
      InitialContext ctx = new InitialContext();
      HAPartition partition = (HAPartition) ctx.lookup("/HAPartition/" + partitionName);
      this.drm = partition.getDistributedReplicantManager ();
      
      replicantName = jmxName.toString ();
      
      ObjectName oname = new ObjectName(invokerMetaData.getInvokerMBean());
      jrmp = (InvokerHA)Registry.lookup(oname);
      if (jrmp == null)
         throw new RuntimeException("home JRMPInvokerHA is null: " + oname);


      target = new HATarget(partition, replicantName, jrmp.getStub (), HATarget.MAKE_INVOCATIONS_WAIT);
      jrmp.registerBean(jmxName, target);

      String clusterFamilyName = partitionName + "/" + jmxName + "/";
      
      // make ABSOLUTLY sure we do register with the DRM AFTER the HATarget
      // otherwise we will refresh the *old* home in JNDI (ie before the proxy
      // is re-generated)
      //
      drm.registerListener (replicantName, this);
      
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      Class clazz;
      LoadBalancePolicy policy;
      
      clazz = cl.loadClass(container.getBeanMetaData().getClusterConfigMetaData().getHomeLoadBalancePolicy());
      policy = (LoadBalancePolicy)clazz.newInstance();
      homeInvoker = jrmp.createProxy(jmxName, policy, clusterFamilyName + "H");
      // (Re-)Bind the home invoker in the JNDI naming space
      String homeName = jndiBinding + "-HomeInvoker";
      log.debug("(re-)Binding Home invoker under: " + homeName);
      Util.rebind(ctx,
         // Jndi name
         homeName,
         // The home invoker
         homeInvoker
      );

      clazz = cl.loadClass(container.getBeanMetaData().getClusterConfigMetaData().getBeanLoadBalancePolicy());
      policy = (LoadBalancePolicy)clazz.newInstance();
      beanInvoker = jrmp.createProxy(jmxName, policy, clusterFamilyName + "R");
      // (Re-)Bind the remote invoker in the JNDI naming space
      String beanName = jndiBinding + "-RemoteInvoker";
      log.debug("(re-)Binding Remote invoker under: " + beanName);
      Util.rebind(ctx,
         // Jndi name
         beanName,
         // The bean invoker
         beanInvoker
      );
   
public voidstart()

      super.start ();