User: vharcq  
  Date: 01/12/23 11:53:01

  Modified:    src/main/org/jboss/ejb/plugins Tag: Branch_2_4
                        AbstractInstancePool.java EntityInstancePool.java
                        SingletonStatelessSessionInstancePool.java
  Added:       src/main/org/jboss/ejb/plugins Tag: Branch_2_4
                        InstancePoolFeeder.java
                        TimedInstancePoolFeeder.java
  Log:
  Add a pool feeder to create asynchronously instances of beans and push them in the 
pool stack.
  This is off by default on 2.4.
  Look at standardjboss.xml and jboss.dtd of 3.0 for information on parameters and how 
to configure it
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.9.6.4   +132 -74   jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java
  
  Index: AbstractInstancePool.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java,v
  retrieving revision 1.9.6.3
  retrieving revision 1.9.6.4
  diff -u -r1.9.6.3 -r1.9.6.4
  --- AbstractInstancePool.java 2001/11/02 08:42:33     1.9.6.3
  +++ AbstractInstancePool.java 2001/12/23 19:53:00     1.9.6.4
  @@ -8,12 +8,10 @@
   
   import java.rmi.RemoteException;
   import java.rmi.ServerException;
  -import java.util.Map;
  -import java.util.HashMap;
   import java.util.Stack;
  +import java.util.Iterator;
  +import java.lang.reflect.Constructor;
   
  -import javax.ejb.EJBHome;
  -
   import org.jboss.ejb.Container;
   import org.jboss.ejb.InstancePool;
   import org.jboss.ejb.EnterpriseContext;
  @@ -25,47 +23,57 @@
   import org.jboss.logging.Logger;
   
   /**
  -*  <review>
  -*    Abstract Instance Pool class containing the basic logic to create
  -*  an EJB Instance Pool.
  -*  </review>
  -*
  -*    @see <related>
  -*    @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  -*    @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  -*  @author <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>
  -*  @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
  -*
  -*  @version $Revision: 1.9.6.3 $
  -*
  -*  <p><b>Revisions:</b>
  -*  <p><b>20010704 marcf:</b>
  -*  <ul>
  -*  <li>- Pools if used, do not reuse but restock the pile with fresh instances
  -*  </ul>
  -*  <p><b>20010709 andreas schaefer:</b>
  -*  <ul>
  -*  <li>- Added statistics gathering
  -*  </ul>
  -*  <p><b>20010920 Sacha Labourey:</b>
  -*  <ul>
  -*  <li>- Pooling made optional and only activated in concrete subclasses for SLSB 
and MDB
  -*  </ul>
  -*/
  + *  <review>
  + *   Abstract Instance Pool class containing the basic logic to create
  + *  an EJB Instance Pool.
  + *  </review>
  + *
  + *   @see <related>
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  + *  @author <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>
  + *  @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
  + *
  + *  @version $Revision: 1.9.6.4 $
  + *
  + *  <p><b>Revisions:</b>
  + *  <p><b>20010704 marcf:</b>
  + *  <ul>
  + *  <li>- Pools if used, do not reuse but restock the pile with fresh instances
  + *  </ul>
  + *  <p><b>20010709 andreas schaefer:</b>
  + *  <ul>
  + *  <li>- Added statistics gathering
  + *  </ul>
  + *  <p><b>20010920 Sacha Labourey:</b>
  + *  <ul>
  + *  <li>- Pooling made optional and only activated in concrete subclasses for SLSB 
and MDB
  + *  </ul>
  + *  <p><b>20011208 Vincent Harcq:</b>
  + *  <ul>
  + *  <li>- A TimedInstancePoolFeeder thread is started at first use of the pool
  + *        and will populate the pool with new instances at a regular period.
  + *  </ul>
  + */
   public abstract class AbstractInstancePool
      implements InstancePool, XmlLoadable
   {
      // Constants -----------------------------------------------------
   
      // Attributes ----------------------------------------------------
  -   private Container container;
  +
  +   protected Logger log = Logger.getLogger(AbstractInstancePool.class);
   
  -   Stack pool = new Stack();
  -   int maxSize = 30;
  +   protected Container container;
   
  -   // determine if we reuse EnterpriseContext objects i.e. if we actually do pooling
  +   protected Stack pool = new Stack();
  +
  +   /** determine if we reuse EnterpriseContext objects i.e. if we actually do 
pooling */
      protected boolean reclaim = false;
   
  +   protected InstancePoolFeeder poolFeeder;
  +   protected boolean useFeeder = false;
  +
      // Static --------------------------------------------------------
   
        // Constructors --------------------------------------------------
  @@ -105,23 +113,39 @@
   
      public void stop()
      {
  +      if (useFeeder && poolFeeder.isStarted()) poolFeeder.stop();
  +      freeAll();
      }
   
      public void destroy()
      {
  +      if (useFeeder && poolFeeder.isStarted()) poolFeeder.stop();
  +      freeAll();
      }
   
  -    public boolean getReclaim()
  -    {
  -       return reclaim;
  -    }
  -
  -    public void setReclaim(boolean reclaim)
  -    {
  -       this.reclaim = reclaim;
  -    }
  +   /**
  +    * A pool is reclaim if it push back its dirty instances in its stack.
  +    */
  +   public boolean getReclaim()
  +   {
  +      return reclaim;
  +   }
  +
  +   public void setReclaim(boolean reclaim)
  +   {
  +      this.reclaim = reclaim;
  +   }
   
      /**
  +    * Add a instance in the pool
  +    */
  +   public void add()
  +      throws Exception
  +   {
  +      this.pool.push(create(container.createBeanClassInstance()));
  +   }
  +
  +   /**
       *   Get an instance without identity.
       *   Can be used by finders,create-methods, and activation
       *
  @@ -131,15 +155,21 @@
      public synchronized EnterpriseContext get()
         throws Exception
      {
  -      //DEBUG      Logger.debug("Get instance "+this);
  +      //Logger.debug("Get instance 
"+this+"#"+pool.empty()+"#"+getContainer().getBeanClass());
   
         if (!pool.empty())
         {
            return (EnterpriseContext)pool.pop();
  -      } else
  +
  +      }
  +      // The Pool feeder should avoid this
  +      else
         {
  +         if (useFeeder && poolFeeder.isStarted() && log.isDebugEnabled()) 
log.debug("The Pool for " + container.getBeanClass().getName()
  +               + " has been overloaded.  You should change pool parameters.");
            try
            {
  +            if (useFeeder && ! poolFeeder.isStarted()) poolFeeder.start();
               return create(container.createBeanClassInstance());
            } catch (InstantiationException e)
            {
  @@ -163,34 +193,25 @@
      public synchronized void free(EnterpriseContext ctx)
      {
         // Pool it
  -      //DEBUG      Logger.debug("Free 
instance:"+ctx.getId()+"#"+ctx.getTransaction());
  +      //Logger.debug(maxSize+" Free 
instance:"+this+"#"+ctx.getId()+"#"+ctx.getTransaction()+"#"+reclaim+"#"+getContainer().getBeanClass());
         ctx.clear();
   
  -      if (pool.size() < maxSize)
  -      {
  -
  -         // If (!reclaim), we do not reuse but create a brand new instance 
simplifies the design
  -         try {
  -            if (this.reclaim)
  -            {
  -               pool.push(ctx);
  -            }
  -            else
  -            {
  -               discard (ctx);
  -               pool.push(create(container.createBeanClassInstance()));
  -            }
  -         } catch (Exception ignored) {}
  -         //pool.push(ctx);
  -      } else
  -      {
  -         discard(ctx);
  -      }
  +      // If (!reclaim), we do not reuse but create a brand new instance simplifies 
the design
  +      try {
  +         if ( this.reclaim )
  +         {
  +            pool.push(ctx);
  +         }
  +         else
  +         {
  +            discard(ctx);
  +         }
  +      } catch (Exception ignored) {}
      }
   
      public void discard(EnterpriseContext ctx)
      {
  -      // Throw away
  +      // Throw away, unsetContext()
         try
         {
            ctx.discard();
  @@ -200,16 +221,38 @@
         }
      }
   
  +   public int getCurrentSize()
  +   {
  +      return this.pool.size();
  +   }
  +
      // Z implementation ----------------------------------------------
   
  -     // XmlLoadable implementation
  +     /**
  +    * XmlLoadable implementation
  +    */
      public void importXml(Element element) throws DeploymentException {
  -      String maximumSize = 
MetaData.getElementContent(MetaData.getUniqueChild(element, "MaximumSize"));
  -      try {
  -         maxSize = Integer.parseInt(maximumSize);
  -      } catch (NumberFormatException e) {
  -         throw new DeploymentException("Invalid MaximumSize value for instance pool 
configuration");
  +      String feederPolicy = 
MetaData.getElementContent(MetaData.getOptionalChild(element, "feeder-policy"));
  +      if (feederPolicy != null)
  +      {
  +         useFeeder = true;
  +         try
  +         {
  +            Class cls = 
Thread.currentThread().getContextClassLoader().loadClass(feederPolicy);
  +            Constructor ctor = cls.getConstructor(new Class[] {});
  +            this.poolFeeder = (InstancePoolFeeder)ctor.newInstance(new Class[] {});
  +            this.poolFeeder.setInstancePool(this);
  +            this.poolFeeder.importXml(element);
  +         }
  +         catch (Exception x)
  +         {
  +            throw new DeploymentException("Can't create instance pool feeder", x);
  +         }
         }
  +      else
  +      {
  +         useFeeder = false;
  +      }
      }
   
      // Package protected ---------------------------------------------
  @@ -219,6 +262,21 @@
         throws Exception;
   
      // Private -------------------------------------------------------
  +
  +   /**
  +    * At undeployment we want to free completely the pool.
  +    */
  +   private void freeAll()
  +   {
  +      Iterator i = this.pool.iterator();
  +      while (i.hasNext())
  +      {
  +         EnterpriseContext ec = (EnterpriseContext)i.next();
  +         // Clear TX so that still TX entity pools get killed as well
  +         ec.clear();
  +         discard(ec);
  +      }
  +   }
   
      // Inner classes -------------------------------------------------
   
  
  
  
  1.9.6.3   +13 -9     jboss/src/main/org/jboss/ejb/plugins/EntityInstancePool.java
  
  Index: EntityInstancePool.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstancePool.java,v
  retrieving revision 1.9.6.2
  retrieving revision 1.9.6.3
  diff -u -r1.9.6.2 -r1.9.6.3
  --- EntityInstancePool.java   2001/09/20 22:19:00     1.9.6.2
  +++ EntityInstancePool.java   2001/12/23 19:53:00     1.9.6.3
  @@ -13,6 +13,7 @@
   import org.jboss.ejb.Container;
   import org.jboss.ejb.EnterpriseContext;
   import org.jboss.ejb.EntityEnterpriseContext;
  +import org.jboss.logging.Logger;
   
   /**
    *   <description>
  @@ -22,18 +23,18 @@
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
  - *   @version $Revision: 1.9.6.2 $
  + *   @version $Revision: 1.9.6.3 $
    *
    * <p><b>Revisions:</b>
    * <p><b>20010718 andreas schaefer:</b>
    * <ul>
    * <li>- Added statistics gathering
    * </ul>
  -*  <p><b>20010920 Sacha Labourey:</b>
  -*  <ul>
  -*  <li>- Moved "reclaim" flag (set by Bill Burke) to the AbstractInstancePool level.
  -*        It can now be used for SLSB and MDB (pooling activated)
  -*  </ul>
  + *  <p><b>20010920 Sacha Labourey:</b>
  + *  <ul>
  + *  <li>- Moved "reclaim" flag (set by Bill Burke) to the AbstractInstancePool 
level.
  + *        It can now be used for SLSB and MDB (pooling activated)
  + *  </ul>
    */
   public class EntityInstancePool
      extends AbstractInstancePool
  @@ -60,10 +61,13 @@
      public synchronized void free(EnterpriseContext ctx)
      {
          // If transaction still present don't do anything (let the instance be GC)
  -       if (ctx.getTransaction() != null) return ;
  +       if (ctx.getTransaction() != null)
  +       {
  +          // log.debug("Can Not FREE Entity Context because a Transaction exists.");
  +          return ;
  +       }
   
  -       // To simplify design we don't reuse the ctx.
  -       if (reclaim) super.free(ctx);
  +       super.free(ctx);
      }
   
      // Z implementation ----------------------------------------------
  
  
  
  1.6.6.2   +16 -2     
jboss/src/main/org/jboss/ejb/plugins/SingletonStatelessSessionInstancePool.java
  
  Index: SingletonStatelessSessionInstancePool.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/SingletonStatelessSessionInstancePool.java,v
  retrieving revision 1.6.6.1
  retrieving revision 1.6.6.2
  diff -u -r1.6.6.1 -r1.6.6.2
  --- SingletonStatelessSessionInstancePool.java        2001/11/02 08:42:33     1.6.6.1
  +++ SingletonStatelessSessionInstancePool.java        2001/12/23 19:53:01     1.6.6.2
  @@ -28,7 +28,7 @@
    *      
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.6.6.1 $
  + *   @version $Revision: 1.6.6.2 $
    */
   public class SingletonStatelessSessionInstancePool
      implements InstancePool, XmlLoadable
  @@ -143,7 +143,21 @@
         inUse = false;
         this.notifyAll();
      }
  -   
  +
  +   /**
  +    * Add a instance in the pool
  +    */
  +   public void add()
  +      throws Exception
  +   {
  +      // Empty
  +   }
  +
  +   public int getCurrentSize()
  +   {
  +      return 1;
  +   }
  +
      // Z implementation ----------------------------------------------
      
       // XmlLoadable implementation
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +44 -0     
jboss/src/main/org/jboss/ejb/plugins/Attic/InstancePoolFeeder.java
  
  
  
  
  1.1.2.1   +7 -17     
jboss/src/main/org/jboss/ejb/plugins/TimedInstancePoolFeeder.java
  
  Index: TimedInstancePoolFeeder.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/TimedInstancePoolFeeder.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- TimedInstancePoolFeeder.java      2001/12/23 19:50:47     1.1
  +++ TimedInstancePoolFeeder.java      2001/12/23 19:53:01     1.1.2.1
  @@ -1,13 +1,12 @@
   /*
  - * JBoss, the OpenSource EJB server
  - *
  - * Distributable under LGPL license.
  - * See terms of license at gnu.org.
  - */
  +* JBoss, the OpenSource EJB server
  +*
  +* Distributable under LGPL license.
  +* See terms of license at gnu.org.
  +*/
   package org.jboss.ejb.plugins;
   
   import org.jboss.ejb.InstancePool;
  -import org.jboss.ejb.InstancePoolFeeder;
   
   import org.jboss.logging.Logger;
   
  @@ -22,13 +21,7 @@
   import java.util.Timer;
   
   /**
  - * Implementation of Pool feeder that is a java.util.Timer that checks at
  - * regular period the size of the pool and bring it closer to its capacity by
  - * adding a number of new instances.
    *
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Harcq</a>
  - *
  - * @version $Revision: 1.1 $
    */
   public class TimedInstancePoolFeeder
         extends TimerTask
  @@ -48,9 +41,7 @@
   
      // Constructor ---------------------------------------------------
   
  -   public TimedInstancePoolFeeder()
  -   {
  -   }
  +   public TimedInstancePoolFeeder(){}
   
      // Public --------------------------------------------------------
   
  @@ -106,8 +97,7 @@
      public void importXml(Element element)
      throws DeploymentException
      {
  -      try
  -      {
  +      try{
            Element instancePoolConf = MetaData.getUniqueChild(element, 
"feeder-policy-conf");
            Element tmp;
            tmp = MetaData.getUniqueChild(instancePoolConf,"capacity");
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to