| Method from org.jboss.ejb.plugins.AbstractInstancePool Detail: |
public void clear() {
synchronized (pool)
{
freeAll();
}
}
|
abstract protected EnterpriseContext create(Object instance) throws Exception
|
protected void destroyService() throws Exception {
freeAll();
this.container = null;
}
|
public void discard(EnterpriseContext ctx) {
if( log.isTraceEnabled() )
{
String msg = "Discard instance:"+this+"#"+ctx
+"#"+ctx.getTransaction()
+"#"+reclaim
+"#"+getContainer().getBeanClass();
log.trace(msg);
}
// If we block when maxSize instances are in use, invoke release on strictMaxSize
if( strictMaxSize != null )
strictMaxSize.release();
// Throw away, unsetContext()
try
{
ctx.discard();
}
catch (RemoteException e)
{
if( log.isTraceEnabled() )
log.trace("Ctx.discard error", e);
}
}
|
public void free(EnterpriseContext ctx) {
if( log.isTraceEnabled() )
{
String msg = pool.size() + "/" + maxSize+" Free instance:"+this
+"#"+ctx.getId()
+"#"+ctx.getTransaction()
+"#"+reclaim
+"#"+getContainer().getBeanClass();
log.trace(msg);
}
ctx.clear();
try
{
// If the pool is not full, add the unused context back into the pool,
// otherwise, just discard the extraneous context and leave it for GC
boolean addedToPool = false;
synchronized (pool)
{
if (pool.size() < maxSize)
{
pool.addFirst(ctx);
addedToPool = true;
}
}
if (addedToPool)
{
// If we block when maxSize instances are in use, invoke release on strictMaxSize
if(strictMaxSize != null)
{
strictMaxSize.release();
}
}
else
{
// Get rid of the extraneous instance; strictMaxSize should be null
// (otherwise we wouldn't have gotten the extra instance)
discard(ctx);
}
}
catch (Exception ignored)
{
}
}
Return an instance after invocation.
Called in 2 cases:
a) Done with finder method
b) Just removed |
public EnterpriseContext get() throws Exception {
boolean trace = log.isTraceEnabled();
if( trace )
log.trace("Get instance "+this+"#"+pool.size()+"#"+getContainer().getBeanClass());
if( strictMaxSize != null )
{
// Block until an instance is available
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);
}
synchronized (pool)
{
if ( pool.isEmpty() == false )
{
return (EnterpriseContext) pool.removeFirst();
}
}
// Pool is empty, create an instance
try
{
Object instance = container.createBeanClassInstance();
return create(instance);
}
catch (Throwable e)
{
// Release the strict max size mutex if it exists
if( strictMaxSize != null )
{
strictMaxSize.release();
}
// Don't wrap CreateExceptions
if( e instanceof CreateException )
throw (CreateException) e;
// Wrap e in an Exception if needed
Exception ex = null;
if(e instanceof Exception)
{
ex = (Exception)e;
} else
{
ex = new UndeclaredThrowableException(e);
}
throw new EJBException("Could not instantiate bean", ex);
}
}
Get an instance without identity.
Can be used by finders,create-methods, and activation |
public long getAvailableCount() {
long size = Long.MAX_VALUE;
if( strictMaxSize != null )
size = strictMaxSize.permits();
return size;
}
Get the current avaiable count from the strict max view. If there is
no strict max then this will be Long.MAX_VALUE to indicate there is no
restriction. |
public Container getContainer() {
return container;
}
|
public int getCurrentSize() {
synchronized (pool)
{
return this.pool.size();
}
}
|
public int getMaxSize() {
return this.maxSize;
}
|
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");
}
// Get whether the pool will block when MaximumSize instances are active
String strictValue = MetaData.getElementContent(MetaData.getOptionalChild(element, "strictMaximumSize"));
Boolean strictFlag = Boolean.valueOf(strictValue);
if( strictFlag == Boolean.TRUE )
this.strictMaxSize = new FIFOSemaphore(this.maxSize);
String delay = MetaData.getElementContent(MetaData.getOptionalChild(element, "strictTimeout"));
try
{
if( delay != null )
this.strictTimeout = Long.parseLong(delay);
}
catch (NumberFormatException e)
{
throw new DeploymentException("Invalid strictTimeout value for instance pool configuration");
}
}
XmlLoadable implementation |
public void setContainer(Container c) {
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
this.container = c;
}
Set the callback to the container. This is for initialization.
The IM may extract the configuration from the container. |