User: fleury  
  Date: 00/08/17 13:13:16

  Modified:    src/main/org/jboss/ejb/plugins/jrmp/interfaces
                        EntityProxy.java HomeProxy.java
  Log:
  Support for fastCache
  
  DOESN'T FULLY WORK YET..
  
  I NEED TO GO TO THE OFFICE THOUGH!!!!!!!! (dies in one of the TestBeans test)
  
  Revision  Changes    Path
  1.15      +61 -59    
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/EntityProxy.java
  
  Index: EntityProxy.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/EntityProxy.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- EntityProxy.java  2000/08/16 18:09:47     1.14
  +++ EntityProxy.java  2000/08/17 20:13:15     1.15
  @@ -13,6 +13,7 @@
   import javax.ejb.EJBObject;
   
   import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
  +import org.jboss.util.FastKey;
   
   /**
    *      <description> 
  @@ -20,7 +21,7 @@
    *      @see <related>
    *      @author Rickard �berg ([EMAIL PROTECTED])
    *           @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  - *      @version $Revision: 1.14 $
  + *      @version $Revision: 1.15 $
    */
   public class EntityProxy
      extends GenericProxy
  @@ -28,7 +29,7 @@
      // Constants -----------------------------------------------------
       
      // Attributes ----------------------------------------------------
  -   protected Object id;
  +   protected FastKey fastKey;  
      
      // Static --------------------------------------------------------
    
  @@ -43,15 +44,15 @@
      {
         try
         {
  -              // EJB methods
  +        // EJB methods
            getPrimaryKey = EJBObject.class.getMethod("getPrimaryKey", new Class[0]);
            getHandle = EJBObject.class.getMethod("getHandle", new Class[0]);
            isIdentical = EJBObject.class.getMethod("isIdentical", new Class[] { 
EJBObject.class });
            
  -              // Object methods
  -              toStr = Object.class.getMethod("toString", new Class[0]);
  +        // Object methods
  +        toStr = Object.class.getMethod("toString", new Class[0]);
            eq = Object.class.getMethod("equals", new Class[] { Object.class });
  -          hash = Object.class.getMethod("hashCode", new Class[0]);
  +         hash = Object.class.getMethod("hashCode", new Class[0]);
         } catch (Exception e)
         {
            e.printStackTrace();
  @@ -64,14 +65,14 @@
         // For externalization to work
      }
      
  -   public EntityProxy(String name, ContainerRemote container, Object id, boolean 
optimize)
  +   public EntityProxy(String name, ContainerRemote container, FastKey fastKey, 
boolean optimize)
      {
  -             super(name, container, optimize);
  +       super(name, container, optimize);
   
  -             if (id == null)
  -                     throw new NullPointerException("Id may not be null");
  -                     
  -             this.id = id;
  +       if (fastKey == null)
  +         throw new NullPointerException("Id may not be null");
  +         
  +        this.fastKey = fastKey;
      }
      
      // Public --------------------------------------------------------
  @@ -87,66 +88,67 @@
         
         // Implement local methods
         if (m.equals(toStr))
  -      {
  -         return name+":"+id.toString();
  +      { 
  +        return name+":"+fastKey.id.toString();
  +       
         }
         else if (m.equals(eq))
         {
            return invoke(proxy, isIdentical, args);
         }
         
  -       else if (m.equals(hash))
  +      else if (m.equals(hash))
         {
  -             return new Integer(id.hashCode());
  +         return new Integer(fastKey.id.hashCode());
         }
         
  -       // Implement local EJB calls
  -        else if (m.equals(getHandle))
  +      // Implement local EJB calls
  +       else if (m.equals(getHandle))
         {
  -         return new EntityHandleImpl(name, id);
  +         return new EntityHandleImpl(name, fastKey.id);
         }
        
  -       else if (m.equals(getPrimaryKey))
  -      {
  -         return id;
  +      else if (m.equals(getPrimaryKey))
  +      { 
  +        return fastKey.id;
         }
  -       else if (m.equals(isIdentical))
  +      else if (m.equals(isIdentical))
         {
  -                     return new 
Boolean(((EJBObject)args[0]).getPrimaryKey().equals(id));
  +        return new Boolean(((EJBObject)args[0]).getPrimaryKey().equals(fastKey.id));
         }
         
  -       // If not taken care of, go on and call the container
  -       else
  +      // If not taken care of, go on and call the container
  +      else
         {
  -           // Delegate to container
  -           // Optimize if calling another bean in same EJB-application
  -           if (optimize && isLocal())
  -           {
  -              return container.invoke( // The entity id, method and arguments for 
the invocation
  -                                                                       id, m, args,
  -                                                                       // 
Transaction attributes
  -                                                                       tm != null ? 
tm.getTransaction() : null,
  -                                                                       // Security 
attributes
  -                                                                       
getPrincipal(), getCredential());
  -           } else
  -           {
  -                      // Create a new MethodInvocation for distribution
  -              RemoteMethodInvocation rmi = new RemoteMethodInvocation(id, m, args);
  -              
  -                      // Set the transaction context
  -                      rmi.setTransaction(tm != null? tm.getTransaction() : null);
  -              
  -                      // Set the security stuff
  -                      // MF fixme this will need to use "thread local" and 
therefore same construct as above
  -                      // rmi.setPrincipal(sm != null? sm.getPrincipal() : null);
  -              // rmi.setCredential(sm != null? sm.getCredential() : null);
  -              // is the credential thread local? (don't think so... but...)
  -                      rmi.setPrincipal( getPrincipal() );
  -              rmi.setCredential( getCredential() );
  -                      
  -                      // Invoke on the remote server, enforce marshalling
  -              return container.invoke(new MarshalledObject(rmi)).get();
  -           }
  +          // Delegate to container
  +          // Optimize if calling another bean in same EJB-application
  +          if (optimize && isLocal())
  +          {
  +             return container.invoke( // The entity id, method and arguments for 
the invocation
  +                             fastKey, m, args,
  +                          // Transaction attributes
  +                          tm != null ? tm.getTransaction() : null,
  +                          // Security attributes
  +                          getPrincipal(), getCredential());
  +          } else
  +          {
  +          // Create a new MethodInvocation for distribution
  +             RemoteMethodInvocation rmi = new RemoteMethodInvocation(fastKey, m, 
args);
  +             
  +          // Set the transaction context
  +          rmi.setTransaction(tm != null? tm.getTransaction() : null);
  +             
  +          // Set the security stuff
  +          // MF fixme this will need to use "thread local" and therefore same 
construct as above
  +          // rmi.setPrincipal(sm != null? sm.getPrincipal() : null);
  +             // rmi.setCredential(sm != null? sm.getCredential() : null);
  +             // is the credential thread local? (don't think so... but...)
  +          rmi.setPrincipal( getPrincipal() );
  +             rmi.setCredential( getCredential() );
  +          
  +          // Invoke on the remote server, enforce marshalling
  +             return container.invoke(new MarshalledObject(rmi)).get();
  +          }
         }
      }
   
  @@ -156,15 +158,15 @@
      public void writeExternal(java.io.ObjectOutput out)
         throws IOException
      {
  -             super.writeExternal(out);
  -     out.writeObject(id);
  +       super.writeExternal(out);
  +        out.writeObject(fastKey);
      }
      
      public void readExternal(java.io.ObjectInput in)
         throws IOException, ClassNotFoundException
      {
  -     super.readExternal(in);
  -     id = in.readObject();
  +        super.readExternal(in);
  +        fastKey = (FastKey) in.readObject();
      }
       
      // Private -------------------------------------------------------
  
  
  
  1.16      +230 -229  
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxy.java
  
  Index: HomeProxy.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxy.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- HomeProxy.java    2000/08/16 18:32:09     1.15
  +++ HomeProxy.java    2000/08/17 20:13:15     1.16
  @@ -1,9 +1,9 @@
   /*
  - * jBoss, the OpenSource EJB server
  - *
  - * Distributable under GPL license.
  - * See terms of license at gnu.org.
  - */
  +* jBoss, the OpenSource EJB server
  +*
  +* Distributable under GPL license.
  +* See terms of license at gnu.org.
  +*/
   package org.jboss.ejb.plugins.jrmp.interfaces;
   
   import java.io.IOException;
  @@ -18,238 +18,239 @@
   import javax.ejb.HomeHandle;
   import javax.ejb.EJBMetaData;
   
  +import org.jboss.util.FastKey;
   import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
   
   /**
  - *      <description> 
  - *      
  - *      @see <related>
  - *      @author Rickard �berg ([EMAIL PROTECTED])
  - *           @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  - *      @version $Revision: 1.15 $
  - */
  +*      <description> 
  +*      
  +*      @see <related>
  +*      @author Rickard �berg ([EMAIL PROTECTED])
  +*            @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  +*      @version $Revision: 1.16 $
  +*/
   public class HomeProxy
  -   extends GenericProxy
  +extends GenericProxy
   {
  -   // Constants -----------------------------------------------------
  +    // Constants -----------------------------------------------------
       
  -   // Attributes ----------------------------------------------------
  -   
  -   EJBMetaData ejbMetaData;
  -   // Static --------------------------------------------------------
  -   static Method getEJBMetaData;
  -   static Method getHomeHandle;
  -   static Method removeByHandle;
  -   static Method removeByPrimaryKey;
  -   static Method removeObject;
  -   static Method toStr;
  -   static Method eq;
  -   static Method hash;
  -   
  -   static
  -   {
  -      try
  -      {
  -         // EJB methods
  -        getEJBMetaData = EJBHome.class.getMethod("getEJBMetaData", new Class[0]);
  -         getHomeHandle = EJBHome.class.getMethod("getHomeHandle", new Class[0]);
  -         removeByHandle = EJBHome.class.getMethod("remove", new Class[] 
{Handle.class});
  -        removeByPrimaryKey = EJBHome.class.getMethod("remove", new Class[] 
{Object.class});
  -        // Get the "remove" method from the EJBObject
  -        removeObject = EJBObject.class.getMethod("remove", new Class[0]);
  -        
  -        // Object methods
  -         toStr = Object.class.getMethod("toString", new Class[0]);
  -         eq = Object.class.getMethod("equals", new Class[] { Object.class });
  -         hash = Object.class.getMethod("hashCode", new Class[0]);
  -      } catch (Exception e)
  -      {
  -         e.printStackTrace();
  -      }
  -   }
  -
  -
  -   // Constructors --------------------------------------------------
  -   public HomeProxy()
  -   {
  -      // For Externalizable to work
  -   }
  -   
  -   public HomeProxy(String name, EJBMetaData ejbMetaData, ContainerRemote 
container, boolean optimize)
  -   {
  -       super(name, container, optimize);
  -       
  +    // Attributes ----------------------------------------------------
  +    
  +    EJBMetaData ejbMetaData;
  +    // Static --------------------------------------------------------
  +    static Method getEJBMetaData;
  +    static Method getHomeHandle;
  +    static Method removeByHandle;
  +    static Method removeByPrimaryKey;
  +    static Method removeObject;
  +    static Method toStr;
  +    static Method eq;
  +    static Method hash;
  +    
  +    static
  +    {
  +        try
  +        {
  +            // EJB methods
  +            getEJBMetaData = EJBHome.class.getMethod("getEJBMetaData", new 
Class[0]);
  +            getHomeHandle = EJBHome.class.getMethod("getHomeHandle", new Class[0]);
  +            removeByHandle = EJBHome.class.getMethod("remove", new Class[] 
{Handle.class});
  +            removeByPrimaryKey = EJBHome.class.getMethod("remove", new Class[] 
{Object.class});
  +            // Get the "remove" method from the EJBObject
  +            removeObject = EJBObject.class.getMethod("remove", new Class[0]);
  +            
  +            // Object methods
  +            toStr = Object.class.getMethod("toString", new Class[0]);
  +            eq = Object.class.getMethod("equals", new Class[] { Object.class });
  +            hash = Object.class.getMethod("hashCode", new Class[0]);
  +        } catch (Exception e)
  +        {
  +            e.printStackTrace();
  +        }
  +    }
  +    
  +    
  +    // Constructors --------------------------------------------------
  +    public HomeProxy()
  +    {
  +        // For Externalizable to work
  +    }
  +    
  +    public HomeProxy(String name, EJBMetaData ejbMetaData, ContainerRemote 
container, boolean optimize)
  +    {
  +        super(name, container, optimize);
  +        
           this.ejbMetaData = ejbMetaData;
  -   }
  -   
  -   // Public --------------------------------------------------------
  -
  -   // InvocationHandler implementation ------------------------------
  -   public Object invoke(Object proxy, Method m, Object[] args)
  -      throws Throwable
  -   {
  -       
  -       
  -      // Normalize args to always be an array
  -      // Isn't this a bug in the proxy call??
  -      if (args == null)
  -         args = new Object[0];
  -      
  -      // Implement local methods
  -      if (m.equals(toStr))
  -      {
  -          System.out.println("HomeProxy:toStr");
  -         return name+"Home";
  -      }
  -      else if (m.equals(eq))
  -      {
  -         // equality of the proxy home is based on names...
  -         
  -          System.out.println("HomeProxy:eq");
  -         return new Boolean(invoke(proxy,toStr, args).equals(name+"Home"));
  -      }
  -      
  -      else if (m.equals(hash))
  -      {
  -          
  -          System.out.println("HomeProxy:hash");
  -        return new Integer(this.hashCode());
  -      }
  -      
  -      // Implement local EJB calls
  -       else if (m.equals(getHomeHandle))
  -      {
  -          
  -          System.out.println("HomeProxy:getHomeHandle");
  -         return new HomeHandleImpl(name);
  -      }
  -     
  -     
  -      else if (m.equals(getEJBMetaData))
  -      {
  -          
  -          System.out.println("HomeProxy:getEJBMetaData");
  -         return ejbMetaData;
  -      }
  -      
  -      
  -      else if (m.equals(removeByHandle))
  -      {
  -          
  -          System.out.println("HomeProxy:removeByHandle");
  -         // First get the EJBObject
  -         EJBObject object = ((Handle) args[0]).getEJBObject();
  -         
  -         // remove the object from here
  -         object.remove();
  -        
  -         // Return Void
  -         return Void.TYPE;
  -      }
  -      
  -      // The trick is simple we trick the container in believe it is a remove() on 
the instance
  -      else if (m.equals(removeByPrimaryKey))
  -      {
  -          
  -          System.out.println("HomeProxy:removeByPK");
  -         if (optimize && isLocal())
  -          {
  -             return container.invoke(
  -                           // The first argument is the id
  -                        args[0], 
  -                        // Pass the "removeMethod"
  -                        removeObject, 
  -                        // this is a remove() on the object
  -                        new Object[0],
  -                        // Tx stuff
  -                        tm != null ? tm.getTransaction() : null,
  -                        // Security attributes
  -                        getPrincipal(), getCredential());
  -          } else
  -          {
  -
  -         // Build a method invocation that carries the identity of the target object
  -             RemoteMethodInvocation rmi = new RemoteMethodInvocation(
  -                                              // The first argument is the id
  -                                        args[0], 
  -                                        // Pass the "removeMethod"
  -                                        removeObject, 
  -                                        // this is a remove() on the object
  -                                        new Object[0]);
  -
  -          // Set the transaction context
  -          rmi.setTransaction(tm != null? tm.getTransaction() : null);
  -             
  -          // Set the security stuff
  -          // MF fixme this will need to use "thread local" and therefore same 
construct as above
  -          // rmi.setPrincipal(sm != null? sm.getPrincipal() : null);
  -             // rmi.setCredential(sm != null? sm.getCredential() : null);
  -             // is the credential thread local? (don't think so... but...)
  -            rmi.setPrincipal( getPrincipal() );
  -             rmi.setCredential( getCredential() );
  -          
  -          // Invoke on the remote server, enforce marshalling
  -             return container.invoke(new MarshalledObject(rmi));
  -          }
  -      }
  -      
  -      // If not taken care of, go on and call the container
  -      else
  -      {
  -          
  -          System.out.println("HomeProxy:"+m.getName());
  -          // Delegate to container
  -          // Optimize if calling another bean in same EJB-application
  -          if (optimize && isLocal())
  -          {
  -             return container.invokeHome( // The method and arguments for the 
invocation
  -                                 m, args,
  -                              // Transaction attributes
  -                              tm != null ? tm.getTransaction() : null,
  -                              // Security attributes
  -                              getPrincipal(), getCredential());
  -          } else
  -          {
  -          // Create a new MethodInvocation for distribution
  -             RemoteMethodInvocation rmi = new RemoteMethodInvocation(null, m, args);
  -             
  -          // Set the transaction context
  -          rmi.setTransaction(tm != null? tm.getTransaction() : null);
  -             
  -          // Set the security stuff
  -          // MF fixme this will need to use "thread local" and therefore same 
construct as above
  -          // rmi.setPrincipal(sm != null? sm.getPrincipal() : null);
  -             // rmi.setCredential(sm != null? sm.getCredential() : null);
  -             // is the credential thread local? (don't think so... but...)
  -          rmi.setPrincipal( getPrincipal() );
  -             rmi.setCredential( getCredential() );
  -          
  -          // Invoke on the remote server, enforce marshalling
  -             return container.invokeHome(new MarshalledObject(rmi)).get();
  -          }
  -      }
  -   }
  -
  -   public void writeExternal(java.io.ObjectOutput out)
  -      throws IOException
  -   {
  -      super.writeExternal(out);
  -        
  -      out.writeObject(ejbMetaData);
  -   }
  -   
  -   public void readExternal(java.io.ObjectInput in)
  -      throws IOException, ClassNotFoundException
  -   {
  -      super.readExternal(in);
  -      
  -     ejbMetaData = (EJBMetaData)in.readObject();
  -   }
  -   // Package protected ---------------------------------------------
  +    }
       
  -   // Protected -----------------------------------------------------
  +    // Public --------------------------------------------------------
       
  -   // Private -------------------------------------------------------
  +    // InvocationHandler implementation ------------------------------
  +    public Object invoke(Object proxy, Method m, Object[] args)
  +    throws Throwable
  +    {
  +        
  +        
  +        // Normalize args to always be an array
  +        // Isn't this a bug in the proxy call??
  +        if (args == null)
  +            args = new Object[0];
  +        
  +        // Implement local methods
  +        if (m.equals(toStr))
  +        {
  +            System.out.println("HomeProxy:toStr");
  +            return name+"Home";
  +        }
  +        else if (m.equals(eq))
  +        {
  +            // equality of the proxy home is based on names...
  +            
  +            System.out.println("HomeProxy:eq");
  +            return new Boolean(invoke(proxy,toStr, args).equals(name+"Home"));
  +        }
           
  -   // Inner classes -------------------------------------------------
  +        else if (m.equals(hash))
  +        {
  +            
  +            System.out.println("HomeProxy:hash");
  +            return new Integer(this.hashCode());
  +        }
  +        
  +        // Implement local EJB calls
  +        else if (m.equals(getHomeHandle))
  +        {
  +            
  +            System.out.println("HomeProxy:getHomeHandle");
  +            return new HomeHandleImpl(name);
  +        }
  +        
  +        
  +        else if (m.equals(getEJBMetaData))
  +        {
  +            
  +            System.out.println("HomeProxy:getEJBMetaData");
  +            return ejbMetaData;
  +        }
  +        
  +        
  +        else if (m.equals(removeByHandle))
  +        {
  +            
  +            System.out.println("HomeProxy:removeByHandle");
  +            // First get the EJBObject
  +            EJBObject object = ((Handle) args[0]).getEJBObject();
  +            
  +            // remove the object from here
  +            object.remove();
  +            
  +            // Return Void
  +            return Void.TYPE;
  +        }
  +        
  +        // The trick is simple we trick the container in believe it is a remove() 
on the instance
  +        else if (m.equals(removeByPrimaryKey))
  +        {
  +            
  +            System.out.println("HomeProxy:removeByPK");
  +            if (optimize && isLocal())
  +            {
  +                return container.invoke(
  +                    // The first argument is the id
  +                    new FastKey(args[0]), 
  +                    // Pass the "removeMethod"
  +                    removeObject, 
  +                    // this is a remove() on the object
  +                    new Object[0],
  +                    // Tx stuff
  +                    tm != null ? tm.getTransaction() : null,
  +                    // Security attributes
  +                    getPrincipal(), getCredential());
  +            } else
  +            {
  +                
  +                // Build a method invocation that carries the identity of the 
target object
  +                RemoteMethodInvocation rmi = new RemoteMethodInvocation(
  +                    // The first argument is the id
  +                    new FastKey(args[0]), 
  +                    // Pass the "removeMethod"
  +                    removeObject, 
  +                    // this is a remove() on the object
  +                    new Object[0]);
  +                
  +                // Set the transaction context
  +                rmi.setTransaction(tm != null? tm.getTransaction() : null);
  +                
  +                // Set the security stuff
  +                // MF fixme this will need to use "thread local" and therefore same 
construct as above
  +                // rmi.setPrincipal(sm != null? sm.getPrincipal() : null);
  +                // rmi.setCredential(sm != null? sm.getCredential() : null);
  +                // is the credential thread local? (don't think so... but...)
  +                rmi.setPrincipal( getPrincipal() );
  +                rmi.setCredential( getCredential() );
  +                
  +                // Invoke on the remote server, enforce marshalling
  +                return container.invoke(new MarshalledObject(rmi));
  +            }
  +        }
  +        
  +        // If not taken care of, go on and call the container
  +        else
  +        {
  +            
  +            System.out.println("HomeProxy:"+m.getName());
  +            // Delegate to container
  +            // Optimize if calling another bean in same EJB-application
  +            if (optimize && isLocal())
  +            {
  +                return container.invokeHome( // The method and arguments for the 
invocation
  +                    m, args,
  +                    // Transaction attributes
  +                    tm != null ? tm.getTransaction() : null,
  +                    // Security attributes
  +                    getPrincipal(), getCredential());
  +            } else
  +            {
  +                // Create a new MethodInvocation for distribution 
  +                RemoteMethodInvocation rmi = new RemoteMethodInvocation(null, m, 
args);
  +                
  +                // Set the transaction context
  +                rmi.setTransaction(tm != null? tm.getTransaction() : null);
  +                
  +                // Set the security stuff
  +                // MF fixme this will need to use "thread local" and therefore same 
construct as above
  +                // rmi.setPrincipal(sm != null? sm.getPrincipal() : null);
  +                // rmi.setCredential(sm != null? sm.getCredential() : null);
  +                // is the credential thread local? (don't think so... but...)
  +                rmi.setPrincipal( getPrincipal() );
  +                rmi.setCredential( getCredential() );
  +                
  +                // Invoke on the remote server, enforce marshalling
  +                return container.invokeHome(new MarshalledObject(rmi)).get();
  +            }
  +        }
  +    }
  +    
  +    public void writeExternal(java.io.ObjectOutput out)
  +    throws IOException
  +    {
  +        super.writeExternal(out);
  +        
  +        out.writeObject(ejbMetaData);
  +    }
  +    
  +    public void readExternal(java.io.ObjectInput in)
  +    throws IOException, ClassNotFoundException
  +    {
  +        super.readExternal(in);
  +        
  +        ejbMetaData = (EJBMetaData)in.readObject();
  +    }
  +    // Package protected ---------------------------------------------
  +    
  +    // Protected -----------------------------------------------------
  +    
  +    // Private -------------------------------------------------------
  +    
  +    // Inner classes -------------------------------------------------
   }
  
  
  

Reply via email to