Methods Summary |
---|
public void | destroy()
freeAll();
|
public void | discard(BeanContext ctx)
if (log.isTraceEnabled())
{
String msg = "Discard instance:" + this + "#" + ctx
+ "#" + container.getBeanClass();
log.trace(msg);
}
// If we block when maxSize instances are in use, invoke release on strictMaxSize
strictMaxSize.release();
--inUse;
// Throw away, unsetContext()
super.discard(ctx);
|
private void | freeAll()At undeployment we want to free completely the pool.
LinkedList clone = (LinkedList) pool.clone();
for (int i = 0; i < clone.size(); i++)
{
BeanContext bc = (BeanContext) clone.get(i);
// Clear TX so that still TX entity pools get killed as well
discard(bc);
}
pool.clear();
inUse = 0;
|
public BeanContext | get()Get an instance without identity.
Can be used by finders,create-methods, and activation
boolean trace = log.isTraceEnabled();
if (trace)
log.trace("Get instance " + this + "#" + pool.size() + "#" + container.getBeanClass());
// Block until an instance is available
try
{
boolean acquired = strictMaxSize.attempt(strictTimeout);
if (trace)
log.trace("Acquired(" + acquired + ") strictMaxSize semaphore, remaining=" + strictMaxSize.permits());
if (acquired == false)
throw new EJBException("Failed to acquire the pool semaphore, strictTimeout=" + strictTimeout);
}
catch (InterruptedException e)
{
throw new EJBException("Pool strictMaxSize semaphore was interrupted");
}
synchronized (pool)
{
if (!pool.isEmpty())
{
BeanContext bean = (BeanContext) pool.removeFirst();
++inUse;
return bean;
}
}
// Pool is empty, create an instance
++inUse;
return create();
|
public BeanContext | get(java.lang.Class[] initTypes, java.lang.Object[] initValues)
boolean trace = log.isTraceEnabled();
if (trace)
log.trace("Get instance " + this + "#" + pool.size() + "#" + container.getBeanClass());
// Block until an instance is available
try
{
boolean acquired = strictMaxSize.attempt(strictTimeout);
if (trace)
log.trace("Acquired(" + acquired + ") strictMaxSize semaphore, remaining=" + strictMaxSize.permits());
if (acquired == false)
throw new EJBException("Failed to acquire the pool semaphore, strictTimeout=" + strictTimeout);
}
catch (InterruptedException e)
{
throw new EJBException("Pool strictMaxSize semaphore was interrupted");
}
synchronized (pool)
{
if (!pool.isEmpty())
{
BeanContext bean = (BeanContext) pool.removeFirst();
++inUse;
return bean;
}
}
// Pool is empty, create an instance
++inUse;
return create(initTypes, initValues);
|
public int | getAvailableCount()
return maxSize - inUse;
|
public int | getCurrentSize()
return pool.size();
|
public int | getMaxSize()
return maxSize;
|
public void | initialize(Container container, java.lang.Class contextClass, java.lang.Class beanClass, int maxSize, long timeout)super.initialize() must have been called in advance
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
super.initialize(container, contextClass, beanClass, maxSize, timeout);
this.maxSize = maxSize;
this.strictMaxSize = new FIFOSemaphore(maxSize);
this.strictTimeout = timeout;
|
public void | release(BeanContext ctx)Return an instance after invocation.
Called in 2 cases:
a) Done with finder method
b) Just removed
if (log.isTraceEnabled())
{
String msg = pool.size() + "/" + maxSize + " Free instance:" + this
+ "#" + container.getBeanClass();
log.trace(msg);
}
try
{
// Add the unused context back into the pool
boolean removeIt = false;
synchronized (pool)
{
if (pool.size() < maxSize)
{
pool.addFirst(ctx);
}
else
{
removeIt = true;
}
}
if (removeIt) remove(ctx);
// If we block when maxSize instances are in use, invoke release on strictMaxSize
strictMaxSize.release();
--inUse;
}
catch (Exception ignored)
{
}
|
public void | setMaxSize(int maxSize)
this.maxSize = maxSize;
this.strictMaxSize = new FIFOSemaphore(maxSize);
|