User: starksm 
  Date: 01/12/27 11:41:16

  Modified:    src/main/org/jboss/ejb/plugins Tag: Branch_2_4
                        AbstractInstancePool.java EntityInstancePool.java
                        SingletonStatelessSessionInstancePool.java
                        TimedInstancePoolFeeder.java
  Log:
  Restore the AbstractInstancePool MaximumSize and add a getMaxSize() method
  to InstancePool. The getMaxSize() method is used by TimedInstancePoolFeeder
  instead of the capacity element.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.9.6.5   +67 -33    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.4
  retrieving revision 1.9.6.5
  diff -u -r1.9.6.4 -r1.9.6.5
  --- AbstractInstancePool.java 2001/12/23 19:53:00     1.9.6.4
  +++ AbstractInstancePool.java 2001/12/27 19:41:16     1.9.6.5
  @@ -34,25 +34,20 @@
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
    *
  - *  @version $Revision: 1.9.6.4 $
  + *  @version $Revision: 1.9.6.5 $
    *
    *  <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.
  + *  <li>- Added InstancePoolFeeder concept for initializing the pool.
    *  </ul>
    */
   public abstract class AbstractInstancePool
  @@ -61,13 +56,14 @@
      // Constants -----------------------------------------------------
   
      // Attributes ----------------------------------------------------
  +   protected Logger log = Logger.getLogger(this.getClass());
   
  -   protected Logger log = Logger.getLogger(AbstractInstancePool.class);
  -
      protected Container container;
   
  +   /** The instance pool stack */
      protected Stack pool = new Stack();
  -
  +   /** The maximum number of instances allowed in the pool */
  +   protected int maxSize = 30;
      /** determine if we reuse EnterpriseContext objects i.e. if we actually do 
pooling */
      protected boolean reclaim = false;
   
  @@ -92,9 +88,7 @@
      }
   
      /**
  -   * <review>
      * @return Callback to the container which can be null if not set proviously
  -   * </review>
      **/
      public Container getContainer()
      {
  @@ -113,13 +107,14 @@
   
      public void stop()
      {
  -      if (useFeeder && poolFeeder.isStarted()) poolFeeder.stop();
  -      freeAll();
  +      if (useFeeder && poolFeeder.isStarted())
  +      {
  +         poolFeeder.stop();
  +      }
      }
   
      public void destroy()
      {
  -      if (useFeeder && poolFeeder.isStarted()) poolFeeder.stop();
         freeAll();
      }
   
  @@ -142,7 +137,10 @@
      public void add()
         throws Exception
      {
  -      this.pool.push(create(container.createBeanClassInstance()));
  +      EnterpriseContext ctx = create(container.createBeanClassInstance());
  +      if( log.isTraceEnabled() )
  +         log.trace("Add instance "+this+"#"+ctx);
  +      this.pool.push(ctx);
      }
   
      /**
  @@ -155,30 +153,40 @@
      public synchronized EnterpriseContext get()
         throws Exception
      {
  -      //Logger.debug("Get instance 
"+this+"#"+pool.empty()+"#"+getContainer().getBeanClass());
  +      if( log.isTraceEnabled() )
  +         log.trace("Get instance 
"+this+"#"+pool.empty()+"#"+getContainer().getBeanClass());
   
  +      EnterpriseContext ctx = null;
         if (!pool.empty())
         {
  -         return (EnterpriseContext)pool.pop();
  -
  +         ctx = (EnterpriseContext) pool.pop();
         }
         // The Pool feeder should avoid this
         else
         {
  -         if (useFeeder && poolFeeder.isStarted() && log.isDebugEnabled()) 
log.debug("The Pool for " + container.getBeanClass().getName()
  +         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)
  +            if (useFeeder && ! poolFeeder.isStarted())
  +               poolFeeder.start();
  +            ctx = create(container.createBeanClassInstance());
  +         }
  +         catch (InstantiationException e)
            {
               throw new ServerException("Could not instantiate bean", e);
  -         } catch (IllegalAccessException e)
  +         }
  +         catch (IllegalAccessException e)
            {
               throw new ServerException("Could not instantiate bean", e);
            }
         }
  +
  +      return ctx;
      }
   
      /**
  @@ -192,21 +200,32 @@
       */
      public synchronized void free(EnterpriseContext ctx)
      {
  -      // Pool it
  -      //Logger.debug(maxSize+" Free 
instance:"+this+"#"+ctx.getId()+"#"+ctx.getTransaction()+"#"+reclaim+"#"+getContainer().getBeanClass());
  +      if( log.isTraceEnabled() )
  +      {
  +         String msg = maxSize+" Free instance:"+this+"#"+ctx.getId()
  +            +"#"+ctx.getTransaction()
  +            +"#"+reclaim
  +            +"#"+getContainer().getBeanClass();
  +         log.trace(msg);
  +      }
         ctx.clear();
   
  -      // If (!reclaim), we do not reuse but create a brand new instance simplifies 
the design
  -      try {
  -         if ( this.reclaim )
  +      if( this.reclaim && pool.size() < maxSize )
  +      {
  +         // Add the unused context back into the pool
  +         try
            {
               pool.push(ctx);
            }
  -         else
  +         catch (Exception ignored)
            {
  -            discard(ctx);
            }
  -      } catch (Exception ignored) {}
  +      }
  +      else
  +      {
  +         // Discard the context
  +         discard(ctx);
  +      }
      }
   
      public void discard(EnterpriseContext ctx)
  @@ -225,13 +244,28 @@
      {
         return this.pool.size();
      }
  +   public int getMaxSize()
  +   {
  +      return this.maxSize;
  +   }
   
      // Z implementation ----------------------------------------------
   
        /**
       * XmlLoadable implementation
       */
  -   public void importXml(Element element) throws DeploymentException {
  +   public void importXml(Element element) throws DeploymentException
  +   {
  +      String maximumSize = 
MetaData.getElementContent(MetaData.getUniqueChild(element, "MaximumSize"));
  +      try
  +      {
  +         this.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)
         {
  
  
  
  1.9.6.4   +3 -3      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.3
  retrieving revision 1.9.6.4
  diff -u -r1.9.6.3 -r1.9.6.4
  --- EntityInstancePool.java   2001/12/23 19:53:00     1.9.6.3
  +++ EntityInstancePool.java   2001/12/27 19:41:16     1.9.6.4
  @@ -23,7 +23,7 @@
    *  @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 $
  + *   @version $Revision: 1.9.6.4 $
    *
    * <p><b>Revisions:</b>
    * <p><b>20010718 andreas schaefer:</b>
  @@ -63,7 +63,8 @@
          // If transaction still present don't do anything (let the instance be GC)
          if (ctx.getTransaction() != null)
          {
  -          // log.debug("Can Not FREE Entity Context because a Transaction exists.");
  +          if( log.isTraceEnabled() )
  +            log.trace("Can Not FREE Entity Context because a Transaction exists.");
             return ;
          }
   
  @@ -90,4 +91,3 @@
      // Inner classes -------------------------------------------------
   
   }
  -
  
  
  
  1.6.6.3   +13 -8     
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.2
  retrieving revision 1.6.6.3
  diff -u -r1.6.6.2 -r1.6.6.3
  --- SingletonStatelessSessionInstancePool.java        2001/12/23 19:53:01     1.6.6.2
  +++ SingletonStatelessSessionInstancePool.java        2001/12/27 19:41:16     1.6.6.3
  @@ -28,7 +28,7 @@
    *      
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.6.6.2 $
  + *   @version $Revision: 1.6.6.3 $
    */
   public class SingletonStatelessSessionInstancePool
      implements InstancePool, XmlLoadable
  @@ -157,14 +157,19 @@
      {
         return 1;
      }
  -
  +   public int getMaxSize()
  +   {
  +      return 1;
  +   }
      // Z implementation ----------------------------------------------
  -   
  -    // XmlLoadable implementation
  -     public void importXml(Element element) throws DeploymentException {
  -             isSynchronized = 
Boolean.valueOf(MetaData.getElementContent(MetaData.getUniqueChild(element, 
"Synchronized"))).booleanValue();
  +
  +   // XmlLoadable implementation
  +     public void importXml(Element element) throws Exception
  +   {
  +      Element synch = MetaData.getUniqueChild(element, "Synchronized");
  +             isSynchronized = 
Boolean.valueOf(MetaData.getElementContent(synch)).booleanValue();
        }
  -     
  +
      // Package protected ---------------------------------------------
       
      // Protected -----------------------------------------------------
  @@ -173,7 +178,7 @@
      {
         return new StatelessSessionEnterpriseContext(instance, con);
      }
  -    
  +   
      // Private -------------------------------------------------------
   
      // Inner classes -------------------------------------------------
  
  
  
  1.1.2.2   +12 -16    
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.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- TimedInstancePoolFeeder.java      2001/12/23 19:53:01     1.1.2.1
  +++ TimedInstancePoolFeeder.java      2001/12/27 19:41:16     1.1.2.2
  @@ -6,20 +6,16 @@
   */
   package org.jboss.ejb.plugins;
   
  -import org.jboss.ejb.InstancePool;
  +import java.util.TimerTask;
  +import java.util.Timer;
   
  -import org.jboss.logging.Logger;
  +import org.w3c.dom.Element;
   
  +import org.jboss.deployment.DeploymentException;
  +import org.jboss.ejb.InstancePool;
   import org.jboss.metadata.XmlLoadable;
   import org.jboss.metadata.MetaData;
   
  -import org.jboss.deployment.DeploymentException;
  -
  -import org.w3c.dom.Element;
  -
  -import java.util.TimerTask;
  -import java.util.Timer;
  -
   /**
    *
    */
  @@ -29,11 +25,11 @@
   {
   
      // Private -------------------------------------------------------
  -
  +   /** The instance pool we feed */
      private InstancePool ip;
  -
  +   /** The rate in milliseconds between updates to the InstancePool */
      private int rate;
  -   private int capacity;
  +   /** The number of instances to add to the pool each period */
      private int increment;
   
      private Timer timer;
  @@ -49,6 +45,7 @@
      {
         try
         {
  +         int capacity = ip.getMaxSize();
            if (ip.getCurrentSize() < capacity)
            {
               for (int i=0 ; i < increment ; i++)
  @@ -95,13 +92,12 @@
      // XmlLoadable Impl ----------------------------------------------
   
      public void importXml(Element element)
  -   throws DeploymentException
  +      throws DeploymentException
      {
  -      try{
  +      try
  +      {
            Element instancePoolConf = MetaData.getUniqueChild(element, 
"feeder-policy-conf");
            Element tmp;
  -         tmp = MetaData.getUniqueChild(instancePoolConf,"capacity");
  -         capacity = Integer.parseInt(MetaData.getElementContent(tmp));
            tmp = MetaData.getUniqueChild(instancePoolConf,"increment");
            increment = Integer.parseInt(MetaData.getElementContent(tmp));
            tmp = MetaData.getUniqueChild(instancePoolConf,"period");
  
  
  

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

Reply via email to