Cache for stateful session beans.
| Method from org.jboss.ejb.plugins.StatefulSessionInstanceCache Detail: |
protected EnterpriseContext acquireContext() throws Exception {
return m_container.getInstancePool().get();
}
|
protected void activate(EnterpriseContext ctx) throws RemoteException {
m_container.getPersistenceManager().activateSession((StatefulSessionEnterpriseContext) ctx);
passivatedIDs.remove(ctx.getId());
}
|
protected boolean canPassivate(EnterpriseContext ctx) {
if (ctx.isLocked())
{
// The context is in the interceptor chain
return false;
}
else if (m_container.getLockManager().canPassivate(ctx.getId()) == false)
{
return false;
}
else
{
if (ctx.getTransaction() != null)
{
try
{
return (ctx.getTransaction().getStatus() == Status.STATUS_NO_TRANSACTION);
}
catch (SystemException e)
{
// SA FIXME: not sure what to do here
return false;
}
}
}
return true;
}
|
public void destroy() {
synchronized (this)
{
this.m_container = null;
}
passivatedIDs.clear();
super.destroy();
}
|
protected boolean doActivate(EnterpriseContext ctx) throws RemoteException {
Object id = ctx.getId();
synchronized (activating)
{
// This is a recursive invocation
if (activating.contains(id))
return false;
activating.add(id);
}
try
{
return super.doActivate(ctx);
}
finally
{
synchronized (activating)
{
activating.remove(id);
}
}
}
|
protected void freeContext(EnterpriseContext ctx) {
m_container.getInstancePool().free(ctx);
}
|
protected synchronized Container getContainer() {
return m_container;
}
|
protected Object getKey(EnterpriseContext ctx) {
return ctx.getId();
}
|
public long getPassivatedCount() {
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
return passivatedIDs.size();
}
Get the passivated count. |
protected void passivate(EnterpriseContext ctx) throws RemoteException {
m_container.getPersistenceManager().passivateSession((StatefulSessionEnterpriseContext) ctx);
passivatedIDs.put(ctx.getId(), new Long(System.currentTimeMillis()));
}
|
protected void postRemovalCleanup(Object key) {
// no-op...extending classes may add cleanup
}
|
protected void preRemovalPreparation(Object key) {
// no-op...extending classes may add prep
}
|
protected void removePassivated(long maxLifeAfterPassivation) {
StatefulSessionPersistenceManager store = m_container.getPersistenceManager();
long now = System.currentTimeMillis();
log.debug("removePassivated, now="+now+", maxLifeAfterPassivation="+maxLifeAfterPassivation);
boolean trace = log.isTraceEnabled();
Iterator entries = passivatedIDs.entrySet().iterator();
while (entries.hasNext())
{
Map.Entry entry = (Map.Entry) entries.next();
Object key = entry.getKey();
Long value = (Long) entry.getValue();
if (value != null)
{
long passivationTime = value.longValue();
if (now - passivationTime > maxLifeAfterPassivation)
{
preRemovalPreparation(key);
store.removePassivated(key);
if (trace)
log(key, passivationTime);
// Must use iterator to avoid ConcurrentModificationException
entries.remove();
postRemovalCleanup(key);
}
}
}
}
Remove all passivated instances that have been inactive too long. |
public void setContainer(Container c) {
m_container = (StatefulSessionContainer) c;
}
|
protected void setKey(Object id,
EnterpriseContext ctx) {
ctx.setId(id);
}
|