User: vharcq
Date: 01/12/27 19:47:10
Modified: src/main/org/jboss/ejb/plugins 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
1.22 +62 -18 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- AbstractInstancePool.java 2001/12/23 19:50:46 1.21
+++ AbstractInstancePool.java 2001/12/28 03:47:10 1.22
@@ -40,7 +40,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>
*
- * @version $Revision: 1.21 $
+ * @version $Revision: 1.22 $
*
* <p><b>Revisions:</b>
* <p><b>20010704 marcf:</b>
@@ -68,12 +68,15 @@
// Attributes ----------------------------------------------------
- protected Logger log = Logger.getLogger(AbstractInstancePool.class);
+ protected Logger log = Logger.getLogger(this.getClass());
protected Container container;
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;
@@ -105,9 +108,7 @@
}
/**
- * <review>
* @return Callback to the container which can be null if not set proviously
- * </review>
*/
public Container getContainer()
{
@@ -126,13 +127,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();
}
@@ -155,7 +157,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);
}
/**
@@ -168,22 +173,29 @@
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())
{
mReadyBean.remove();
- 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());
+ if (useFeeder && ! poolFeeder.isStarted())
+ poolFeeder.start();
+ ctx = create(container.createBeanClassInstance());
} catch (InstantiationException e)
{
throw new ServerException("Could not instantiate bean", e);
@@ -192,6 +204,8 @@
throw new ServerException("Could not instantiate bean", e);
}
}
+
+ return ctx;
}
/**
@@ -205,24 +219,43 @@
*/
public synchronized void free(EnterpriseContext ctx)
{
- // Pool it
- //DEBUG Logger.debug("Free
instance:"+ctx.getId()+"#"+ctx.getTransaction());
+ 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 {
mReadyBean.add();
- if (this.reclaim)
+ if( this.reclaim && pool.size() < maxSize )
{
- pool.push(ctx);
+ // Add the unused context back into the pool
+ try
+ {
+ pool.push(ctx);
+ }
+ catch (Exception ignored)
+ {
+ }
}
else
{
+ // Discard the context
discard (ctx);
}
} catch (Exception ignored) {}
}
+ public int getMaxSize()
+ {
+ return this.maxSize;
+ }
+
public void discard(EnterpriseContext ctx)
{
// Throw away, unsetContext()
@@ -246,7 +279,18 @@
/**
* 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.18 +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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- EntityInstancePool.java 2001/12/23 19:50:47 1.17
+++ EntityInstancePool.java 2001/12/28 03:47:10 1.18
@@ -17,7 +17,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.17 $
+ * @version $Revision: 1.18 $
*
* <p><b>Revisions:</b>
* <p><b>20010718 andreas schaefer:</b>
@@ -62,7 +62,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.17 +10 -3
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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SingletonStatelessSessionInstancePool.java 2001/12/23 19:50:47 1.16
+++ SingletonStatelessSessionInstancePool.java 2001/12/28 03:47:10 1.17
@@ -29,7 +29,7 @@
*
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
- * @version $Revision: 1.16 $
+ * @version $Revision: 1.17 $
*
* <p><b>Revisions:</b>
* <p><b>20010718 andreas schaefer:</b>
@@ -200,11 +200,18 @@
mReadyBean.reset();
}
+ 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();
+ public void importXml(Element element) throws DeploymentException
+ {
+ Element synch = MetaData.getUniqueChild(element, "Synchronized");
+ isSynchronized =
Boolean.valueOf(MetaData.getElementContent(synch)).booleanValue();
}
// Package protected ---------------------------------------------
1.2 +17 -30
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.2
diff -u -r1.1 -r1.2
--- TimedInstancePoolFeeder.java 2001/12/23 19:50:47 1.1
+++ TimedInstancePoolFeeder.java 2001/12/28 03:47:10 1.2
@@ -1,34 +1,24 @@
/*
- * 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 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.ejb.InstancePoolFeeder;
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;
-
/**
- * 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
@@ -36,11 +26,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;
@@ -48,9 +38,7 @@
// Constructor ---------------------------------------------------
- public TimedInstancePoolFeeder()
- {
- }
+ public TimedInstancePoolFeeder(){}
// Public --------------------------------------------------------
@@ -58,6 +46,7 @@
{
try
{
+ int capacity = ip.getMaxSize();
if (ip.getCurrentSize() < capacity)
{
for (int i=0 ; i < increment ; i++)
@@ -104,14 +93,12 @@
// XmlLoadable Impl ----------------------------------------------
public void importXml(Element element)
- throws DeploymentException
+ throws DeploymentException
{
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