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

ProxyFactoryHA

public class ProxyFactoryHA extends org.jboss.invocation.jrmp.server.JRMPProxyFactory implements ProxyFactoryHAMBean, DistributedReplicantManager.ReplicantListener
ProxyFactory for Clustering
author
Adrian Brock
version
$Revision: 57188 $

Fields Summary
protected String
replicantName
protected org.jboss.invocation.InvokerHA
invokerHA
protected org.jboss.ha.framework.server.HATarget
target
protected org.jboss.invocation.Invoker
invoker
protected org.jboss.ha.framework.interfaces.DistributedReplicantManager
drm
protected ObjectName
partitionObjectName
protected String
loadBalancePolicy
protected NotificationListener
listener
protected int
state
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);
   
protected voidcreateProxy(java.lang.Object cacheID, java.lang.String proxyBindingName, java.lang.ClassLoader loader, java.lang.Class[] ifaces)

      GenericProxyFactory proxyFactory = new GenericProxyFactory();
      theProxy = proxyFactory.createProxy(cacheID, getTargetName(), invoker,
         getJndiName(), proxyBindingName, getInterceptorClasses(), loader, ifaces);
   
public voidcreateService()

      super.createService();
      
      // we register our inner-class to retrieve STATE notifications from our container
      AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
      filter.enableAttribute("State");
      listener = new StateChangeListener();
      getServer().addNotificationListener(getTargetName(), listener, filter, null);
   
public voiddestroyService()

      super.destroyService();
      getServer().removeNotificationListener(getTargetName(), listener);
   
public java.lang.StringgetLoadBalancePolicy()

      return loadBalancePolicy;
   
public javax.management.ObjectNamegetPartitionObjectName()


     
   
      return partitionObjectName;
   
public synchronized voidreplicantsChanged(java.lang.String key, java.util.List newReplicants, int newReplicantsViewId)

      try
      {
         if (invoker instanceof InvokerProxyHA)
            ((InvokerProxyHA) invoker).updateClusterInfo(target.getReplicants(), target.getCurrentViewId());

         log.debug ("Rebinding in JNDI... " + key);
         rebind();
      }
      catch (Exception none)
      {
         log.debug(none);
      }
   
public voidsetLoadBalancePolicy(java.lang.String loadBalancePolicy)

      this.loadBalancePolicy = loadBalancePolicy;
   
public voidsetPartitionObjectName(javax.management.ObjectName partitionObjectName)

      this.partitionObjectName = partitionObjectName;
   
protected voidstartService()

      String partitionName = (String) getServer().getAttribute(partitionObjectName, "PartitionName");
      HAPartition partition = (HAPartition) getServer().getAttribute(partitionObjectName, "HAPartition");
      if (partition == null)
         throw new RuntimeException("Partition is not registered: " + partitionObjectName);
      this.drm = partition.getDistributedReplicantManager ();
      
      replicantName = getTargetName().toString();
      
      invokerHA = (InvokerHA) Registry.lookup(getInvokerName());
      if (invokerHA == null)
         throw new RuntimeException("Invoker is not registered: " + getInvokerName());

      int mode = HATarget.MAKE_INVOCATIONS_WAIT;
      if (state == ServiceMBean.STARTED)
         mode = HATarget.ENABLE_INVOCATIONS;
      target = new HATarget(partition, replicantName, invokerHA.getStub(), mode);
      invokerHA.registerBean(getTargetName(), target);

      String clusterFamilyName = partitionName + "/" + getTargetName() + "/";
      
      // 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(loadBalancePolicy);
      policy = (LoadBalancePolicy)clazz.newInstance();
      invoker = invokerHA.createProxy(getTargetName(), policy, clusterFamilyName + "H");
      
      // JRMPInvokerProxyHA.colocation.add(new Integer(jmxNameHash));

      super.startService();
   
public voidstopService()

      super.stopService();
      
      try
      {
         // JRMPInvokerProxyHA.colocation.remove(new Integer(jmxNameHash));
         invokerHA.unregisterBean(getTargetName());
         target.destroy();
      } 
      catch (Exception ignored)
      {
         // ignore.
      }
      if (drm != null)
         drm.unregisterListener(replicantName, this);