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

StatefulRemoteProxy

public class StatefulRemoteProxy extends org.jboss.ejb3.session.BaseSessionRemoteProxy
Comment
author
Bill Burke
version
$Revision: 60233 $

Fields Summary
private static final long
serialVersionUID
private static final Logger
log
protected org.jboss.remoting.InvokerLocator
uri
org.jboss.aspects.asynch.AsynchProvider
provider
private javax.ejb.Handle
handle
private javax.ejb.HomeHandle
homeHandle
private javax.ejb.EJBMetaData
ejbMetaData
Constructors Summary
public StatefulRemoteProxy(Object containerId, org.jboss.aop.advice.Interceptor[] interceptors, org.jboss.remoting.InvokerLocator uri)


         
   
      super(containerId, interceptors);
      this.uri = uri;
   
public StatefulRemoteProxy(Object containerId, org.jboss.aop.advice.Interceptor[] interceptors, org.jboss.remoting.InvokerLocator uri, Object id)

      super(containerId, interceptors);
      this.uri = uri;
      this.id = id;
   
public StatefulRemoteProxy(org.jboss.aspects.asynch.AsynchProvider provider, Object containerId, org.jboss.aop.advice.Interceptor[] interceptors, org.jboss.remoting.InvokerLocator uri)

      super(containerId, interceptors);
      this.uri = uri;
      this.provider = provider;
   
protected StatefulRemoteProxy()

   
Methods Summary
public java.lang.ObjectgetAsynchronousProxy(java.lang.Object proxy)

      Class[] infs = proxy.getClass().getInterfaces();
      if (!ProxyUtils.isAsynchronous(infs))
      {
         Class[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
         AsynchMixin mixin = new AsynchMixin();
         Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors);
         StatefulRemoteProxy handler = new StatefulRemoteProxy(mixin, containerId, newInterceptors, uri);
         return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
      }

      //I was already asynchronous
      return proxy;
   
private java.lang.ObjecthandleEjb21CallLocally(java.lang.reflect.Method method, java.lang.Object[] args)

      if (method.equals(ProxyUtils.GET_HOME_HANDLE))
      {
         return homeHandle;
      } else if (method.equals(ProxyUtils.GET_EJB_METADATA))
      {
         return ejbMetaData;
      } else if (method.equals(ProxyUtils.GET_HANDLE))
      {
         return handle;
      } 
      
      return null;
   
public java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)

      if (method.getDeclaringClass() == AsynchProvider.class)
      {
         return provider.getFuture();
      }

      long hash = MethodHashing.calculateHash(method);
      Object ret = ProxyUtils.handleCallLocally(hash, proxy, this, method, args);
      if (ret != null)
      {
         return ret;
      }
      
      ret = handleEjb21CallLocally(method, args);
      if (ret != null)
      {
         return ret;
      }

      StatefulRemoteInvocation sri = new StatefulRemoteInvocation(interceptors, hash, method, method, null, id);
      sri.setArguments(args);
      sri.setInstanceResolver(metadata);
      sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS);
      sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS);
      sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);

      if (provider != null)
      {
         sri.getMetaData().addMetaData(AsynchronousInterceptor.ASYNCH, AsynchronousInterceptor.INVOKE_ASYNCH, "YES", PayloadKey.AS_IS);
      }
      try
      {
         Object rtn = sri.invokeNext();
         // if this is first invocation then container passes back actual ID
         if (id == null)
         {
            id = sri.getResponseAttachment(StatefulConstants.NEW_ID);
         }
         return rtn;
      }
      catch (ForwardId forward)
      {
         // if this is first invocation then container passes back actual ID
         // The ForwardId exception is needed if 1st operation throws an exception
         id = forward.getId();
         throw forward.getCause();
      }
   
public voidsetEjbMetaData(javax.ejb.EJBMetaData ejbMetaData)

      this.ejbMetaData = ejbMetaData;
   
public voidsetHandle(StatefulHandleImpl handle)

      this.handle = handle;
      handle.id = id;
   
public voidsetHomeHandle(javax.ejb.HomeHandle homeHandle)

      this.homeHandle = homeHandle;
   
public java.lang.StringtoString()

      if (id != null)
      {
         return containerId.toString() + ":" + id.toString();
      }
      else
      {
         //If the proxy has not been used yet, create a temporary id 
         GUID guid = new GUID();
         return containerId.toString() + ":" + guid.toString();
      }