package org.jboss.ejb.plugins;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import org.jboss.deployment.DeploymentException;
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.StatelessSessionEnterpriseContext;
import org.jboss.metadata.MetaData;
import org.w3c.dom.Element;
public class SingletonStatelessSessionInstancePool extends AbstractInstancePool
{
EnterpriseContext ctx;
boolean inUse = false;
boolean isSynchronized = true;
public void create()
throws Exception
{
}
public void start()
throws Exception
{
}
public void stop()
{
}
public void destroy()
{
}
public synchronized EnterpriseContext get()
throws Exception
{
while(inUse && isSynchronized)
{
try { this.wait(); } catch (InterruptedException e) {}
}
if (ctx == null)
{
try
{
ctx = create(getContainer().createBeanClassInstance());
} catch (InstantiationException e)
{
throw new EJBException("Could not instantiate bean", e);
} catch (IllegalAccessException e)
{
throw new EJBException("Could not instantiate bean", e);
}
}
else
{
}
inUse = true;
return ctx;
}
public synchronized void free(EnterpriseContext ctx)
{
inUse = false;
this.notifyAll();
}
public synchronized void discard(EnterpriseContext ctx)
{
try
{
ctx.discard();
} catch (RemoteException e)
{
}
inUse = false;
this.notifyAll();
}
public void add()
throws Exception
{
}
public int getCurrentSize()
{
return 1;
}
public int getMaxSize()
{
return 1;
}
public void importXml(Element element) throws DeploymentException
{
Element synch = MetaData.getUniqueChild(element, "Synchronized");
isSynchronized = Boolean.valueOf(MetaData.getElementContent(synch)).booleanValue();
}
protected EnterpriseContext create(Object instance)
throws Exception
{
return new StatelessSessionEnterpriseContext(instance, getContainer());
}
}