FileDocCategorySizeDatePackage
StatelessClusterProxyFactory.javaAPI DocJBoss 4.2.17494Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.stateless

StatelessClusterProxyFactory

public class StatelessClusterProxyFactory extends BaseStatelessProxyFactory implements org.jboss.ejb3.remoting.RemoteProxyFactory, DistributedReplicantManager.ReplicantListener
Comment
author
Bill Burke
version
$Revision: 62714 $

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
private Object
proxy
Constructors Summary
Methods Summary
public java.lang.ObjectcreateProxy()

//      try
      {
         Object containerId = container.getObjectName().getCanonicalName();
         String stackName = "ClusteredStatelessSessionClientInterceptors";
         if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
         {
            stackName = binding.interceptorStack();
         }
         AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
         /*
         Object[] args = {new StatelessClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), wrapper, lbPolicy)};
         return proxyConstructor.newInstance(args);
         */
         String partitionName = ((StatelessContainer) container).getPartitionName();
         
         proxy = constructProxy(new StatelessClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), 
                                                            wrapper, lbPolicy, partitionName));
         return proxy;
      }
      /*
      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.
      }
      */
   
protected StatelessHandleImplgetHandle()

      StatelessHandleImpl handle = new StatelessHandleImpl();
      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 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);
         
         // Rebind the proxy as the old one has been serialized
         if (proxy != null)
            bindProxy(proxy);
      }
      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 = ((StatelessContainer) container).getPartitionName();
      proxyFamilyName = ((StatelessContainer) 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());
      ((StatelessContainer) container).getClusterFamilies().put(proxyFamilyName, hatarget);
      if (clustered.loadBalancePolicy() == null || clustered.loadBalancePolicy().equals(LoadBalancePolicy.class))
      {
         lbPolicy = new RandomRobin();
      }
      else
      {
         lbPolicy = (LoadBalancePolicy) clustered.loadBalancePolicy().newInstance();
      }
      wrapper = new FamilyWrapper(proxyFamilyName, hatarget.getReplicants());
      
      this.drm = partition.getDistributedReplicantManager();
      drm.registerListener(proxyFamilyName, this);
      
      super.start();
   
public voidstop()

      super.stop();
      proxy = null;
      hatarget.destroy();
      drm.unregisterListener(proxyFamilyName, this);
      ((StatelessContainer) container).getClusterFamilies().remove(proxyFamilyName);