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

StatefulRemoteProxyFactory

public class StatefulRemoteProxyFactory extends BaseStatefulProxyFactory implements org.jboss.ejb3.remoting.RemoteProxyFactory
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
Constructors Summary
Methods Summary
protected booleanbindHomeAndBusinessTogether(StatefulContainer container)

      return ProxyFactoryHelper.getHomeJndiName(container).equals(ProxyFactoryHelper.getRemoteJndiName(container));
   
public java.lang.ObjectcreateHomeProxy(java.lang.Class homeInterface)

      try
      {
         Object containerId = container.getObjectName().getCanonicalName();
         String stackName = "StatefulSessionClientInterceptors";
         if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
         {
            stackName = binding.interceptorStack();
         }
         AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
         if (stack == null) throw new RuntimeException("unable to find interceptor stack: " + stackName);
         StatefulHomeRemoteProxy proxy = new StatefulHomeRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator);


         setEjb21Objects(proxy);
         Class[] intfs = {homeInterface};
         return java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(), intfs, proxy);
      }
      catch (IllegalArgumentException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
   
protected java.lang.ObjectcreatePojiProxy(java.lang.Object oid, java.lang.Class[] interfaces, java.lang.String uri)

      InvokerLocator locator = new InvokerLocator(uri);
      Interceptor[] interceptors = {IsLocalProxyFactoryInterceptor.singleton, InvokeRemoteInterceptor.singleton};
      PojiProxy proxy = new PojiProxy(oid, locator, interceptors);
      return Proxy.newProxyInstance(interfaces[0].getClassLoader(), interfaces, proxy);

   
public java.lang.ObjectcreateProxy(java.lang.Object id)

      try
      {
         Object containerId = container.getObjectName().getCanonicalName();
         String stackName = "StatefulSessionClientInterceptors";
         if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
         {
            stackName = binding.interceptorStack();
         }
         AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
         StatefulRemoteProxy proxy = new StatefulRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator, id);
         setEjb21Objects(proxy);
         Object[] args = {proxy};
         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()

      try
      {
         Object containerId = container.getObjectName().getCanonicalName();
         String stackName = "StatefulSessionClientInterceptors";
         if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
         {
            stackName = binding.interceptorStack();
         }
         AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
         if (stack == null) throw new RuntimeException("unable to find interceptor stack: " + stackName);
         StatefulRemoteProxy proxy = new StatefulRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator);


         setEjb21Objects(proxy);
         Object[] args = {proxy};
         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.
      }
   
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[] interfaces;
      
      StatefulContainer statefulContainer = (StatefulContainer) container;
      RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
      
      boolean bindTogether = false;
      
      if (remoteHome != null && bindHomeAndBusinessTogether(statefulContainer))
         bindTogether = true;
      
      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
      if (bindTogether)
         interfaces = new Class[remoteInterfaces.length + 3];
      else
         interfaces = new Class[remoteInterfaces.length + 2];

      System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
      interfaces[remoteInterfaces.length] = JBossProxy.class;
      interfaces[remoteInterfaces.length + 1] = javax.ejb.EJBObject.class;
      if (bindTogether)
         interfaces[remoteInterfaces.length + 2] = remoteHome.value();
         
      return interfaces;
   
protected java.lang.StringgetTargetId()

return
unique name for this proxy factory

  
      assert jndiName != null : "jndiName is null"; 
      return jndiName + PROXY_FACTORY_NAME;
   
public voidinit()

      super.init();
      String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
      locator = new InvokerLocator(clientBindUrl);
   
protected voidinitializeJndiName()

      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
   
public voidsetRemoteBinding(org.jboss.annotation.ejb.RemoteBinding binding)


      
   
      this.binding = binding;
   
public voidstart()

      init();

      super.start();
      Class[] interfaces = {ProxyFactory.class};
      String targetId = getTargetId();
      Object factoryProxy = 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 remote 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);

      StatefulContainer statefulContainer = (StatefulContainer) container;
      RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
      if (remoteHome != null && !bindHomeAndBusinessTogether(statefulContainer))
      {
         Object homeProxy = createHomeProxy(remoteHome.value());
         Util.rebind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container), homeProxy);
      }
   
public voidstop()

      Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
      Dispatcher.singleton.unregisterTarget(getTargetId());
      
      StatefulContainer statefulContainer = (StatefulContainer) container;
      RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
      if (remoteHome != null && !bindHomeAndBusinessTogether(statefulContainer))
      {
         Util.unbind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container));
      }
      super.stop();