User: fleury  
  Date: 00/09/26 11:55:50

  Modified:    src/main/org/jboss/ejb/plugins
                        NoPassivationStatefulSessionInstanceCache.java
  Log:
  The new cache does not worry about locking.  Passivating algo go here.
  
  Revision  Changes    Path
  1.9       +138 -204  
jboss/src/main/org/jboss/ejb/plugins/NoPassivationStatefulSessionInstanceCache.java
  
  Index: NoPassivationStatefulSessionInstanceCache.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/NoPassivationStatefulSessionInstanceCache.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- NoPassivationStatefulSessionInstanceCache.java    2000/08/18 03:20:56     1.8
  +++ NoPassivationStatefulSessionInstanceCache.java    2000/09/26 18:55:50     1.9
  @@ -1,204 +1,138 @@
  -/*
  -* jBoss, the OpenSource EJB server
  -*
  -* Distributable under GPL license.
  -* See terms of license at gnu.org.
  -*/
  -package org.jboss.ejb.plugins;
  -
  -import java.rmi.RemoteException;
  -import java.rmi.ServerException;
  -import java.util.Map;
  -import java.util.HashMap;
  -import java.util.Stack;
  -import java.util.Collections;
  -
  -import javax.transaction.SystemException;
  -
  -import org.jboss.ejb.Container;
  -import org.jboss.ejb.StatefulSessionContainer;
  -import org.jboss.ejb.InstanceCache;
  -import org.jboss.ejb.InstancePool;
  -import org.jboss.ejb.InstancePoolContainer;
  -import org.jboss.ejb.StatefulSessionPersistenceManager;
  -import org.jboss.ejb.EnterpriseContext;
  -import org.jboss.ejb.StatefulSessionEnterpriseContext;
  -import org.jboss.logging.Logger;
  -
  -
  -/**
  -*    <description> 
  -*      
  -*    @see <related>
  -*    @author Rickard �berg ([EMAIL PROTECTED])
  -*   @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
  -*    @version $Revision: 1.8 $
  -*/
  -public class NoPassivationStatefulSessionInstanceCache
  -implements InstanceCache
  -{
  -    // Constants -----------------------------------------------------
  -    
  -    // Attributes ----------------------------------------------------
  -    Container con;
  -    
  -    Map active = new HashMap();
  -    
  -    // Static --------------------------------------------------------
  -    
  -    // Constructors --------------------------------------------------
  -    
  -    // Public --------------------------------------------------------
  -    
  -    /**
  -    *   Set the callback to the container. This is for initialization.
  -    *   The IM may extract the configuration from the container.
  -    *
  -    * @param   c  
  -    */
  -    public void setContainer(Container c)
  -    {
  -       this.con = c;
  -    }
  -    
  -    public void init()
  -    throws Exception
  -    {
  -    }
  -    
  -    public void start()
  -    throws Exception
  -    {
  -    }
  -    
  -    public void stop()
  -    {
  -    }
  -    
  -    public void destroy()
  -    {
  -    }
  -    
  -    public synchronized EnterpriseContext get(Object id)
  -    throws RemoteException
  -    {
  -       InstanceInfo info = null;
  -       
  -        Logger.log("I AM LOOKING FOR THE ID "+id);
  -       // Do we have the context in cache?
  -       StatefulSessionEnterpriseContext ctx = 
  -         (StatefulSessionEnterpriseContext)active.get(id);
  -       
  -       // We have it in cache
  -       if (ctx != null) {
  -         
  -         info = (InstanceInfo)ctx.getCacheContext();
  -         
  -         if (info.isLocked()) {
  -         
  -          //MF DESIGN: talk about this one... I know it is spec compliant but it 
sucks
  -          throw new RemoteException("Concurrent call to stateful session is not 
allowed");
  -         }
  -         
  -         else {
  -          
  -          info.lock();
  -         }
  -       }
  -         
  -        // We don't have it in cache
  -       if (ctx == null) {
  -         
  -         // Get new instance from pool (bogus in our case)
  -         ctx = 
(StatefulSessionEnterpriseContext)((InstancePoolContainer)con).getInstancePool().get();
  -         
  -         // Activate
  -         ctx.setId(id);
  -         
  -            try {
  -         
  -                
((StatefulSessionContainer)con).getPersistenceManager().activateSession(ctx);
  -            }
  -            catch (Exception e) {
  -                
  -                throw new RemoteException("Object was not found");
  -            }
  -         insert(ctx);
  -       }
  -       // The context has the instance as well and the right id
  -       return ctx;
  -    }
  -    
  -    public synchronized void insert(EnterpriseContext ctx)
  -    {
  -       InstanceInfo info = 
createInstanceInfo((StatefulSessionEnterpriseContext)ctx);
  -       ((StatefulSessionEnterpriseContext)ctx).setCacheContext(info);
  -       info.lock();
  -       active.put(ctx.getId(), ctx) ;
  -    }
  -    
  -    public void release(EnterpriseContext ctx)
  -    {
  -       // This context is now available for other threads
  -       
((InstanceInfo)((StatefulSessionEnterpriseContext)ctx).getCacheContext()).unlock();
  -       
  -       // The following code makes sense if we put threads to sleep (not the case 
anymore)
  -       //if 
(!((InstanceInfo)((StatefulSessionEnterpriseContext)ctx).getCacheContext()).isLocked())
  -       //            ctx.notify();
  -       
  -    }
  -    
  -    public synchronized void remove(Object id)
  -    {
  -       Object ctx = active.remove(id);
  -       synchronized(ctx)
  -       {
  -         ctx.notifyAll();
  -       }
  -    }
  -    
  -    // Z implementation ----------------------------------------------
  -    
  -    // Package protected ---------------------------------------------
  -    
  -    // Protected -----------------------------------------------------
  -    protected InstanceInfo createInstanceInfo(StatefulSessionEnterpriseContext ctx)
  -    {
  -       return new InstanceInfo(ctx);
  -    }
  -    
  -    // Private -------------------------------------------------------
  -    
  -    // Inner classes -------------------------------------------------
  -    class InstanceInfo
  -    {
  -       int locked = 0; // 0 == unlocked, >0 == locked
  -       
  -       StatefulSessionEnterpriseContext ctx;
  -       
  -       InstanceInfo(StatefulSessionEnterpriseContext ctx)
  -       {
  -         this.ctx = ctx;
  -       }
  -       
  -       public void lock()
  -       {
  -         locked++;
  -       }
  -       
  -       public void unlock()
  -       {
  -         locked--;
  -       }
  -       
  -       public boolean isLocked()
  -       {
  -         return locked > 0;
  -       }
  -       
  -       public StatefulSessionEnterpriseContext getContext()
  -       {
  -         return ctx;
  -       }
  -    }
  -}
  +/*
  +* jBoss, the OpenSource EJB server
  +*
  +* Distributable under GPL license.
  +* See terms of license at gnu.org.
  +*/
  +package org.jboss.ejb.plugins;
  +
  +import java.rmi.RemoteException;
  +import java.rmi.ServerException;
  +import java.util.Map;
  +import java.util.HashMap;
  +import java.util.Stack;
  +import java.util.Collections;
  +
  +import javax.transaction.SystemException;
  +
  +import org.jboss.ejb.Container;
  +import org.jboss.ejb.StatefulSessionContainer;
  +import org.jboss.ejb.InstanceCache;
  +import org.jboss.ejb.InstancePool;
  +import org.jboss.ejb.InstancePoolContainer;
  +import org.jboss.ejb.StatefulSessionPersistenceManager;
  +import org.jboss.ejb.EnterpriseContext;
  +import org.jboss.ejb.StatefulSessionEnterpriseContext;
  +import org.jboss.logging.Logger;
  +
  +
  +/**
  +*    <description> 
  +*      
  +*    @see <related>
  +*    @author Rickard �berg ([EMAIL PROTECTED])
  +*   @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
  +*    @version $Revision: 1.9 $
  +*/
  +public class NoPassivationStatefulSessionInstanceCache
  +implements InstanceCache
  +{
  +    // Constants -----------------------------------------------------
  +    
  +    // Attributes ----------------------------------------------------
  +    Container con;
  +    
  +    Map active = new HashMap();
  +    
  +    // Static --------------------------------------------------------
  +    
  +    // Constructors --------------------------------------------------
  +    
  +    // Public --------------------------------------------------------
  +    
  +    /**
  +    *   Set the callback to the container. This is for initialization.
  +    *   The IM may extract the configuration from the container.
  +    *
  +    * @param   c  
  +    */
  +    public void setContainer(Container c)
  +    {
  +       this.con = c;
  +    }
  +    
  +    public void init()
  +    throws Exception
  +    {
  +    }
  +    
  +    public void start()
  +    throws Exception
  +    {
  +    }
  +    
  +    public void stop()
  +    {
  +    }
  +    
  +    public void destroy()
  +    {
  +    }
  +    
  +    public synchronized EnterpriseContext get(Object id)
  +    throws RemoteException
  +    {
  +       
  +        //DEBUG Logger.log("Stateful cache looking for ID "+id);
  +        Logger.log("Stateful cache looking for ID "+id);
  +     
  +       // Do we have the context in cache?
  +       StatefulSessionEnterpriseContext ctx = 
  +         (StatefulSessionEnterpriseContext)active.get(id);
  +         
  +        // We don't have it in cache
  +        if (ctx == null) {
  +            
  +            // Get new instance from pool (bogus in our case)
  +            ctx = 
(StatefulSessionEnterpriseContext)((InstancePoolContainer)con).getInstancePool().get();
  +            
  +            // Activate
  +            ctx.setId(id);
  +            
  +            try {
  +                
  +                
((StatefulSessionContainer)con).getPersistenceManager().activateSession(ctx);
  +            }
  +            catch (Exception e) {
  +                
  +                throw new RemoteException("Object was not found");
  +            }
  +            
  +            insert(ctx);
  +        }
  +       // The context has the instance as well and the right id
  +       return ctx;
  +    }
  +    
  +    public synchronized void insert(EnterpriseContext ctx)
  +    {
  +       active.put(ctx.getId(), ctx) ;
  +    }
  +    
  +    
  +    
  +    public synchronized void remove(Object id)
  +    {
  +       Object ctx = active.remove(id);
  +    }
  +    
  +    // Z implementation ----------------------------------------------
  +    
  +    // Package protected ---------------------------------------------
  +    
  +    // Protected -----------------------------------------------------
  +    
  +    // Private -------------------------------------------------------
  +    
  +    // Inner classes -------------------------------------------------
  +}
  
  
  

Reply via email to