FileDocCategorySizeDatePackage
StatefulClusterProxyFactory.javaAPI DocJBoss 4.2.18877Fri Jul 13 20:53:50 BST 2007org.jboss.ejb3.stateful

StatefulClusterProxyFactory

public class StatefulClusterProxyFactory extends BaseStatefulProxyFactory implements org.jboss.ejb3.remoting.RemoteProxyFactory, DistributedReplicantManager.ReplicantListener
Comment
author
Bill Burke
author
Brian Stansberry
version
$Revision: 63663 $

Fields Summary
private static final Logger
log
private org.jboss.annotation.ejb.RemoteBinding
binding
private org.jboss.remoting.InvokerLocator
locator
private org.jboss.ha.framework.interfaces.DistributedReplicantManager
drm
private org.jboss.ha.framework.server.HATarget
hatarget
private String
proxyFamilyName
private org.jboss.ha.framework.interfaces.LoadBalancePolicy
lbPolicy
private org.jboss.aspects.remoting.FamilyWrapper
wrapper
Constructors Summary
Methods Summary
public java.lang.ObjectcreateProxy()

      try
      {
         Object containerId = container.getObjectName().getCanonicalName();
         String stackName = "ClusteredStatefulSessionClientInterceptors";
         if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
         {
            stackName = binding.interceptorStack();
         }
         AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
         String partitionName = ((StatefulContainer) container).getPartitionName();
         Object[] args = {new StatefulClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), 
                                                     wrapper, lbPolicy, partitionName)};
         
         return proxyConstructor.newInstance(args);
      }
      catch (InstantiationException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
      catch (IllegalAccessException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
      catch (IllegalArgumentException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
      catch (InvocationTargetException e)
      {
         throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
      }
   
public java.lang.ObjectcreateProxy(java.lang.Object id)

      throw new RuntimeException("NYI");
   
protected StatefulHandleImplgetHandle()

      StatefulHandleImpl handle = new StatefulHandleImpl();
      RemoteBinding remoteBinding = (RemoteBinding)advisor.resolveAnnotation(RemoteBinding.class);
      if (remoteBinding != null)
         handle.jndiName = remoteBinding.jndiBinding();
 
      return handle;
   
protected java.lang.Class[]getInterfaces()

      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
      Class[] interfaces = new Class[remoteInterfaces.length + 1];
      System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
      interfaces[remoteInterfaces.length] = JBossProxy.class;
      return interfaces;
   
protected java.lang.StringgetTargetId()

return
unique name for this proxy factory

      assert jndiName != null : "jndiName is null";      
      String partition = ((StatefulContainer) container).getPartitionName();
      return jndiName + PROXY_FACTORY_NAME + "@" + partition;
   
protected voidinitializeJndiName()

      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
   
public synchronized voidreplicantsChanged(java.lang.String key, java.util.List newReplicants, int newReplicantsViewId)

      try
      {
         // Update the FamilyClusterInfo with the new targets
         ArrayList targets = new ArrayList(newReplicants);
         wrapper.get().updateClusterInfo(targets, newReplicantsViewId); 
      }
      catch (Exception e)
      {
         log.error(e);
      }
   
public voidsetRemoteBinding(org.jboss.annotation.ejb.RemoteBinding binding)


      
   
      this.binding = binding;
   
public voidstart()

      String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
      locator = new InvokerLocator(clientBindUrl);
      Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
      if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation.  Cannot deploy.");
      String partitionName = ((StatefulContainer) container).getPartitionName();
      proxyFamilyName = ((StatefulContainer) container).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
      HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName);
      hatarget = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS);
      ClusteringTargetsRepository.initTarget(proxyFamilyName, hatarget.getReplicants());
      ((StatefulContainer) container).getClusterFamilies().put(proxyFamilyName, hatarget);
      if (clustered.loadBalancePolicy() == null || clustered.loadBalancePolicy().equals(LoadBalancePolicy.class))
      {
         lbPolicy = new FirstAvailable();
      }
      else
      {
         lbPolicy = (LoadBalancePolicy) clustered.loadBalancePolicy().newInstance();
      }
      wrapper = new FamilyWrapper(proxyFamilyName, hatarget.getReplicants());
      
      this.drm = partition.getDistributedReplicantManager();
      drm.registerListener(proxyFamilyName, this);
      
      super.start();
      
      Class[] interfaces = {ProxyFactory.class};
      String targetId = getTargetId();
      Object factoryProxy = Remoting.createPojiProxy(targetId, interfaces, ProxyFactoryHelper.getClientBindUrl(binding));
      try
      {
         Util.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
      } catch (NamingException e)
      {
         NamingException namingException = new NamingException("Could not bind stateful cluster proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
         namingException.setRootCause(e);
         throw namingException;
      }
      assert !Dispatcher.singleton.isRegistered(targetId) : targetId + " is already registered";
      Dispatcher.singleton.registerTarget(targetId, this);

   
public voidstop()

      Dispatcher.singleton.unregisterTarget(getTargetId());
      hatarget.destroy();
      drm.unregisterListener(proxyFamilyName, this);
      ((StatefulContainer) container).getClusterFamilies().remove(proxyFamilyName);
      Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
      super.stop();