Hi, There is a reason why I did not start the pool from the ContainerFactory (well another that the classloader issue that you fixed ;) ) The setSessionContext have, in most cases, Home lookup (to cache them) and if all beans are not deployed you can have JNDI lookup failure (when using flat ejb-jar's for example). It is a problem that can happen in other cases as well I must agree and that the developer should take care of, but it appears as a "Jboss bug" when you first see it. I can only see one solution : have a postinit() method in container that is called when all containers have started.
Vincent. > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]] On > Behalf Of Scott M Stark > Sent: vendredi 28 d�cembre 2001 23:35 > To: [EMAIL PROTECTED] > Subject: [JBoss-dev] CVS update: > jboss/src/main/org/jboss/ejb/plugins > AbstractInstancePool.java > MessageDrivenInstanceInterceptor.java > StatefulSessionInstanceInterceptor.java > StatelessSessionInstanceInterceptor.java > > > User: starksm > Date: 01/12/28 14:35:14 > > Modified: src/main/org/jboss/ejb/plugins Tag: Branch_2_4 > AbstractInstancePool.java > MessageDrivenInstanceInterceptor.java > StatefulSessionInstanceInterceptor.java > StatelessSessionInstanceInterceptor.java > Log: > Add a strict pooling behavior that limits the number of > instances to that > specified by the container-pool-conf/MaximumSize > > Revision Changes Path > No revision > > > No revision > > > 1.9.6.6 +138 -65 > jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java > > Index: AbstractInstancePool.java > =================================================================== > RCS file: > /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/AbstractIn > stancePool.java,v > retrieving revision 1.9.6.5 > retrieving revision 1.9.6.6 > diff -u -r1.9.6.5 -r1.9.6.6 > --- AbstractInstancePool.java 2001/12/27 19:41:16 1.9.6.5 > +++ AbstractInstancePool.java 2001/12/28 22:35:13 1.9.6.6 > @@ -17,24 +17,26 @@ > import org.jboss.ejb.EnterpriseContext; > > import org.w3c.dom.Element; > + > +import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore; > + > import org.jboss.deployment.DeploymentException; > import org.jboss.metadata.MetaData; > import org.jboss.metadata.XmlLoadable; > import org.jboss.logging.Logger; > > /** > - * <review> > * Abstract Instance Pool class containing the basic logic > to create > * an EJB Instance Pool. > - * </review> > * > * @see <related> > * @author <a > href="mailto:[EMAIL PROTECTED]">Rickard �berg</a> > * @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> > + * @author <a > href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a> > + * @author <a > href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a> > + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark/a> > * > - * @version $Revision: 1.9.6.5 $ > + * @version $Revision: 1.9.6.6 $ > * > * <p><b>Revisions:</b> > * <p><b>20010704 marcf:</b> > @@ -56,19 +58,26 @@ > // Constants > ----------------------------------------------------- > > // Attributes > ---------------------------------------------------- > + /** A semaphore that is set when the strict max size > behavior is in effect. > + When set, only maxSize instance may be active and any > attempt to get an > + instance will block until an instance is freed. > + */ > + private FIFOSemaphore strictMaxSize; > + /** The time in milliseconds to wait for the > strictMaxSize semaphore. > + */ > + private long strictTimeout = Long.MAX_VALUE; > + /** The logging interface */ > protected Logger log = Logger.getLogger(this.getClass()); > - > + /** The Container the instance pool is associated with */ > protected Container container; > - > /** The instance pool stack */ > 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; > - > + /** The pool seed task set from the feeder-policy > config element */ > protected InstancePoolFeeder poolFeeder; > - protected boolean useFeeder = false; > > // Static > -------------------------------------------------------- > > @@ -103,14 +112,14 @@ > public void start() > throws Exception > { > + if( poolFeeder != null && poolFeeder.isStarted() == false ) > + poolFeeder.start(); > } > > public void stop() > { > - if (useFeeder && poolFeeder.isStarted()) > - { > + if( poolFeeder != null ) > poolFeeder.stop(); > - } > } > > public void destroy() > @@ -131,59 +140,81 @@ > this.reclaim = reclaim; > } > > - /** > - * Add a instance in the pool > + /** Add a instance in the pool by invoking create() with a new > + bean instance. > + @exception Exception, thrown on ctx creation failure > */ > public void add() > throws Exception > { > - EnterpriseContext ctx = > create(container.createBeanClassInstance()); > + EnterpriseContext ctx = null; > + try > + { > + ctx = create(container.createBeanClassInstance()); > + } > + catch (InstantiationException e) > + { > + throw new ServerException("Could not instantiate > bean", e); > + } > + catch (IllegalAccessException e) > + { > + throw new ServerException("Could not instantiate > bean", e); > + } > if( log.isTraceEnabled() ) > log.trace("Add instance "+this+"#"+ctx); > this.pool.push(ctx); > } > > - /** > - * Get an instance without identity. > - * Can be used by finders,create-methods, and activation > - * > - * @return Context /w instance > - * @exception RemoteException > - */ > - public synchronized EnterpriseContext get() > + /** Get an instance without identity. Can be used by > finders,create-methods, > + and activation. This method cannot be synchronized > since it may block on > + the strictMaxSize semaphore. > + > + @return Context with instance > + @exception RemoteException > + */ > + public EnterpriseContext get() > throws Exception > { > - if( log.isTraceEnabled() ) > + boolean trace = log.isTraceEnabled(); > + if( trace ) > log.trace("Get instance > "+this+"#"+pool.empty()+"#"+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 ServerException("Failed to acquire > the pool semaphore, strictTimeout="+strictTimeout); > + } > + EnterpriseContext ctx = internalGet(); > + return ctx; > + } > + > + /** Called by the public get() method with the > strictMaxSize has been acquired > + if strictMaxSize is being used. This method obtains a > ctx from the > + pool if it is not empty, else a new ctx is created by > calling add(). > + */ > + private synchronized EnterpriseContext internalGet() > + throws Exception > + { > EnterpriseContext ctx = null; > - if (!pool.empty()) > + if( pool.empty() == false ) > { > + // Take the next available instance > ctx = (EnterpriseContext) pool.pop(); > } > - // The Pool feeder should avoid this > else > { > - if(useFeeder && poolFeeder.isStarted() && > log.isDebugEnabled()) > + // Create an instance > + if(poolFeeder != null && 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(); > - ctx = create(container.createBeanClassInstance()); > - } > - catch (InstantiationException e) > - { > - throw new ServerException("Could not > instantiate bean", e); > } > - catch (IllegalAccessException e) > - { > - throw new ServerException("Could not > instantiate bean", e); > - } > + add(); > + ctx = (EnterpriseContext) pool.pop(); > } > > return ctx; > @@ -198,45 +229,66 @@ > * > * @param ctx > */ > - public synchronized void free(EnterpriseContext ctx) > + public void free(EnterpriseContext ctx) > { > if( log.isTraceEnabled() ) > { > - String msg = maxSize+" Free > instance:"+this+"#"+ctx.getId() > + String msg = "Free instance:"+this+"#"+ctx > +"#"+ctx.getTransaction() > +"#"+reclaim > +"#"+getContainer().getBeanClass(); > log.trace(msg); > } > - ctx.clear(); > + // If we block when maxSize instances are in use, > invoke release on strictMaxSize > + if( strictMaxSize != null ) > + strictMaxSize.release(); > + internalFree(ctx); > + } > > - if( this.reclaim && pool.size() < maxSize ) > + private synchronized void internalFree(EnterpriseContext ctx) > + { > + ctx.clear(); > + try > { > - // Add the unused context back into the pool > - try > + if( this.reclaim && pool.size() < maxSize ) > { > + // If we pool instances return the ctx to the > pool stack > pool.push(ctx); > } > - catch (Exception ignored) > + else > { > + // Discard the context > + ctx.discard(); > } > } > - else > + catch (Exception e) > { > - // Discard the context > - discard(ctx); > + log.debug("free failure", e); > } > } > > 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) > + } > + catch (RemoteException e) > { > - // DEBUG Logger.exception(e); > } > } > > @@ -256,20 +308,39 @@ > */ > public void importXml(Element element) throws > DeploymentException > { > - String maximumSize = > MetaData.getElementContent(MetaData.getUniqueChild(element, > "MaximumSize")); > + // Get the maximum capacity of the pool > + String maximumSize = > MetaData.getElementContent(MetaData.getOptionalChild(element, > "MaximumSize")); > try > { > - this.maxSize = Integer.parseInt(maximumSize); > + if( maximumSize != null ) > + 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 = Integer.parseInt(delay); > + } > + catch (NumberFormatException e) > + { > + throw new DeploymentException("Invalid > strictTimeout value for instance pool configuration"); > + } > + > + // Get the pool feeder task > String feederPolicy = > MetaData.getElementContent(MetaData.getOptionalChild(element, > "feeder-policy")); > + poolFeeder = null; > if (feederPolicy != null) > { > - useFeeder = true; > try > { > Class cls = > Thread.currentThread().getContextClassLoader().loadClass(feede > rPolicy); > @@ -283,10 +354,7 @@ > throw new DeploymentException("Can't create > instance pool feeder", x); > } > } > - else > - { > - useFeeder = false; > - } > + log.debug("config - MaximumSize="+maxSize+", > strictMaximumSize="+strictFlag+", feederPolicy="+feederPolicy); > } > > // Package protected > --------------------------------------------- > @@ -305,14 +373,19 @@ > Iterator i = this.pool.iterator(); > while (i.hasNext()) > { > - EnterpriseContext ec = (EnterpriseContext)i.next(); > + EnterpriseContext ctx = (EnterpriseContext)i.next(); > // Clear TX so that still TX entity pools get > killed as well > - ec.clear(); > - discard(ec); > + ctx.clear(); > + try > + { > + ctx.discard(); > + } > + catch (RemoteException e) > + { > + } > } > } > > // Inner classes > ------------------------------------------------- > > } > - > > > > 1.3.6.2 +15 -9 > jboss/src/main/org/jboss/ejb/plugins/MessageDrivenInstanceInte > rceptor.java > > Index: MessageDrivenInstanceInterceptor.java > =================================================================== > RCS file: > /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/MessageDri > venInstanceInterceptor.java,v > retrieving revision 1.3.6.1 > retrieving revision 1.3.6.2 > diff -u -r1.3.6.1 -r1.3.6.2 > --- MessageDrivenInstanceInterceptor.java 2001/12/14 > 03:22:10 1.3.6.1 > +++ MessageDrivenInstanceInterceptor.java 2001/12/28 > 22:35:13 1.3.6.2 > @@ -10,18 +10,19 @@ > import java.util.Map; > > import org.jboss.ejb.Container; > +import org.jboss.ejb.EnterpriseContext; > +import org.jboss.ejb.InstancePool; > import org.jboss.ejb.MessageDrivenContainer; > import org.jboss.ejb.MethodInvocation; > > /** > - * This container acquires the given instance. This must > be used after > - * the EnvironmentInterceptor, since acquiring instances > requires a proper > - * JNDI environment to be set. > + * This container acquires an MDB instance and context. > * > * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>. > * @author <a > href="mailto:[EMAIL PROTECTED]">Rickard �berg</a> > * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a> > - * @version $Revision: 1.3.6.1 $ > + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a> > + * @version $Revision: 1.3.6.2 $ > */ > public class MessageDrivenInstanceInterceptor > extends AbstractInterceptor > @@ -68,11 +69,12 @@ > throws Exception > { > // Get context > - mi.setEnterpriseContext(container.getInstancePool().get()); > + InstancePool pool = container.getInstancePool(); > + EnterpriseContext ctx = pool.get(); > + mi.setEnterpriseContext(ctx); > > // There is no need for synchronization since the > instance is always > // fresh also there should never be a tx associated > with the instance. > - > try > { > // Invoke through interceptors > @@ -80,20 +82,24 @@ > } catch (RuntimeException e) // Instance will be > GC'ed at MI return > { > mi.setEnterpriseContext(null); > + pool.discard(ctx); > throw e; > } catch (RemoteException e) // Instance will be > GC'ed at MI return > { > mi.setEnterpriseContext(null); > + pool.discard(ctx); > throw e; > } catch (Error e) // Instance will be GC'ed at MI return > { > mi.setEnterpriseContext(null); > + pool.discard(ctx); > throw e; > } finally > { > - // Return context > - if (mi.getEnterpriseContext() != null) > - > container.getInstancePool().free(mi.getEnterpriseContext()); > + // Return context, when can this be null? > + ctx = mi.getEnterpriseContext(); > + if( ctx != null ) > + pool.free(ctx); > } > } > // Monitorable implementation > ------------------------------------ > > > > 1.15.6.2 +76 -67 > jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceIn > terceptor.java > > Index: StatefulSessionInstanceInterceptor.java > =================================================================== > RCS file: > /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSe > ssionInstanceInterceptor.java,v > retrieving revision 1.15.6.1 > retrieving revision 1.15.6.2 > diff -u -r1.15.6.1 -r1.15.6.2 > --- StatefulSessionInstanceInterceptor.java 2001/09/04 > 01:51:07 1.15.6.1 > +++ StatefulSessionInstanceInterceptor.java 2001/12/28 > 22:35:13 1.15.6.2 > @@ -37,7 +37,8 @@ > * @author <a > href="mailto:[EMAIL PROTECTED]">Rickard �berg</a> > * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a> > * @author <a href="mailto:[EMAIL PROTECTED]">Bill Burke</a> > - * @version $Revision: 1.15.6.1 $ > + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a> > + * @version $Revision: 1.15.6.2 $ > * > * <p><b>Revisions:</b> > * <p><b>20010704 marcf</b> > @@ -55,12 +56,8 @@ > // Constants > ---------------------------------------------------- > > // Attributes > --------------------------------------------------- > - > - /** Instance logger. */ > - protected Category log = Category.getInstance(this.getClass()); > - > protected StatefulSessionContainer container; > - > + > // Static > ------------------------------------------------------- > > private static Method getEJBHome; > @@ -80,8 +77,10 @@ > isIdentical = > EJBObject.class.getMethod("isIdentical", new Class[] > {EJBObject.class}); > remove = EJBObject.class.getMethod("remove", noArg); > } > - catch (Exception e) { > - e.printStackTrace(); > + catch (Exception e) > + { > + Category tmp = > Category.getInstance(StatefulSessionInstanceInterceptor.class); > + tmp.error("Static setup failed", e); > throw new ExceptionInInitializerError(e); > } > } > @@ -94,63 +93,62 @@ > { > this.container = (StatefulSessionContainer)container; > } > - > + > public Container getContainer() > { > return container; > } > - > + > // Interceptor implementation > ----------------------------------- > > public Object invokeHome(MethodInvocation mi) > throws Exception > - { > - // Get context > - > + { > // get a new context from the pool (this is a home > method call) > - EnterpriseContext ctx = container.getInstancePool().get(); > - > - > + InstancePool pool = container.getInstancePool(); > + EnterpriseContext ctx = pool.get(); > + > // set the context on the methodInvocation > mi.setEnterpriseContext(ctx); > - > + > // It is a new context for sure so we can lock it > ctx.lock(); > - > try > { > // Invoke through interceptors > return getNext().invokeHome(mi); > - } finally > + } > + finally > { > synchronized (ctx) > { > // Release the lock > ctx.unlock(); > - > + > // Still free? Not free if create() was called > successfully > if (ctx.getId() == null) > { > - container.getInstancePool().free(ctx); > + pool.free(ctx); > } > } > } > } > - > + > private void register(EnterpriseContext ctx, > Transaction tx, BeanLock lock) > { > // Create a new synchronization > InstanceSynchronization synch = new > InstanceSynchronization(tx, ctx, lock); > > - try { > + try > + { > // OSH: An extra check to avoid warning. > // Can go when we are sure that we no longer get > // the JTA violation warning. > - if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) { > - > + if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) > + { > return; > } > - > + > // We want to be notified when the transaction commits > try > { > @@ -166,38 +164,39 @@ > > // EJB 1.1, 6.5.3 > synch.afterBegin(); > - > - } catch (RollbackException e) { > - > - } catch (Exception e) { > - > + } > + catch (RollbackException e) > + { > + log.debug("register failure", e); > + } > + catch (Exception e) > + { > throw new EJBException(e); > - > } > } > - > + > public Object invoke(MethodInvocation mi) > throws Exception > { > - AbstractInstanceCache cache = > - (AbstractInstanceCache)container.getInstanceCache(); > - Object id = mi.getId(); > + InstanceCache cache = container.getInstanceCache(); > + InstancePool pool = container.getInstancePool(); > + Object methodID = mi.getId(); > EnterpriseContext ctx = null; > > - BeanLock lock = > (BeanLock)container.getLockManager().getLock(id); > + BeanLock lock = > (BeanLock)container.getLockManager().getLock(methodID); > try > { > lock.sync(); // synchronized(ctx) > try // lock.sync > { > // Get context > - ctx = container.getInstanceCache().get(mi.getId()); > + ctx = cache.get(methodID); > // Associate it with the method invocation > mi.setEnterpriseContext(ctx); > > // BMT beans will lock and replace tx no > matter what, CMT do work on transaction > - if > (!((SessionMetaData)container.getBeanMetaData()).isBeanManagedTx()) { > - > + if > (!((SessionMetaData)container.getBeanMetaData()).isBeanManagedTx()) > + { > // Do we have a running transaction with the context > if (ctx.getTransaction() != null && > // And are we trying to enter with > another transaction > @@ -206,16 +205,16 @@ > // Calls must be in the same transaction > throw new RemoteException("Application > Error: tried to enter Stateful bean with different > transaction context"); > } > - > + > //If the instance will participate in a new > transaction we register a sync for it > - if (ctx.getTransaction() == null && > mi.getTransaction() != null) { > + if (ctx.getTransaction() == null && > mi.getTransaction() != null) > + { > register(ctx, mi.getTransaction(), lock); > } > } > - > + > if (!ctx.isLocked()) > { > - > //take it! > ctx.lock(); > } > @@ -244,23 +243,26 @@ > } catch (RemoteException e) > { > // Discard instance > - container.getInstanceCache().remove(mi.getId()); > + cache.remove(methodID); > + pool.discard(ctx); > ctx = null; > > throw e; > } catch (RuntimeException e) > { > // Discard instance > - container.getInstanceCache().remove(mi.getId()); > + cache.remove(methodID); > + pool.discard(ctx); > ctx = null; > > throw e; > } catch (Error e) > { > // Discard instance > - container.getInstanceCache().remove(mi.getId()); > + cache.remove(methodID); > + pool.discard(ctx); > ctx = null; > - > + > throw e; > } finally > { > @@ -270,7 +272,6 @@ > lock.sync(); // synchronized(ctx) > try > { > - > // release it > ctx.unlock(); > > @@ -278,7 +279,8 @@ > if (ctx.getId() == null) > { > // Remove from cache > - > container.getInstanceCache().remove(mi.getId()); > + cache.remove(methodID); > + pool.free(ctx); > } > } > finally > @@ -293,7 +295,7 @@ > container.getLockManager().removeLockRef(lock.getId()); > } > } > - > + > private boolean isCallAllowed(MethodInvocation mi) > { > Method m = mi.getMethod(); > @@ -345,8 +347,10 @@ > // Let's compute it now, to speed things up we could > notifySession = (ctx.getInstance() instanceof > javax.ejb.SessionSynchronization); > > - if (notifySession) { > - try { > + if (notifySession) > + { > + try > + { > // Get the class we are working on > Class sync = > Class.forName("javax.ejb.SessionSynchronization"); > > @@ -355,7 +359,8 @@ > beforeCompletion = > sync.getMethod("beforeCompletion", new Class[0]); > afterCompletion = > sync.getMethod("afterCompletion", new Class[] {boolean.class}); > } > - catch (Exception e) { > + catch (Exception e) > + { > log.error("failed to setup > InstanceSynchronization", e); > } > } > @@ -385,17 +390,19 @@ > // lock the context the transaction is being > commited (no need for sync) > ctx.lock(); > > - if (notifySession) { > - try { > - > + if (notifySession) > + { > + try > + { > beforeCompletion.invoke(ctx.getInstance(), > new Object[0]); > } > - catch (Exception e) { > + catch (Exception e) > + { > log.error("failed to invoke beforeCompletion", e); > } > } > } > - > + > public void afterCompletion(int status) > { > // DEBUG log.debug("afterCompletion called"); > @@ -409,20 +416,23 @@ > // unlock this context > ctx.unlock(); > > - if (notifySession) { > - > - try { > - > - if (status == Status.STATUS_COMMITTED) { > + if (notifySession) > + { > + try > + { > + if (status == Status.STATUS_COMMITTED) > + { > afterCompletion.invoke(ctx.getInstance(), > new Object[] { > Boolean.TRUE }); > } > - else { > + else > + { > afterCompletion.invoke(ctx.getInstance(), > new Object[] { > Boolean.FALSE }); > } > } > - catch (Exception e) { > + catch (Exception e) > + { > log.error("failed to invoke afterCompletion", e); > } > } > @@ -435,4 +445,3 @@ > } > } > } > - > > > > 1.6.6.2 +40 -33 > jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstanceI > nterceptor.java > > Index: StatelessSessionInstanceInterceptor.java > =================================================================== > RCS file: > /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/StatelessS > essionInstanceInterceptor.java,v > retrieving revision 1.6.6.1 > retrieving revision 1.6.6.2 > diff -u -r1.6.6.1 -r1.6.6.2 > --- StatelessSessionInstanceInterceptor.java > 2001/10/20 22:13:22 1.6.6.1 > +++ StatelessSessionInstanceInterceptor.java > 2001/12/28 22:35:14 1.6.6.2 > @@ -31,73 +31,80 @@ > * the EnvironmentInterceptor, since acquiring instances > requires a proper > * JNDI environment to be set > * > - * @see <related> > * @author Rickard �berg ([EMAIL PROTECTED]) > - * @version $Revision: 1.6.6.1 $ > + * @author [EMAIL PROTECTED] > + * @version $Revision: 1.6.6.2 $ > */ > public class StatelessSessionInstanceInterceptor > extends AbstractInterceptor > { > // Constants > ----------------------------------------------------- > - > + > // Attributes > ---------------------------------------------------- > - protected StatelessSessionContainer container; > + protected StatelessSessionContainer container; > > // Static > -------------------------------------------------------- > - > + > // Constructors > -------------------------------------------------- > > // Public > -------------------------------------------------------- > - public void setContainer(Container container) > - { > - this.container = (StatelessSessionContainer)container; > + public void setContainer(Container container) > + { > + this.container = (StatelessSessionContainer)container; > } > - > + > public Container getContainer() > { > - return container; > + return container; > } > - > + > // Interceptor implementation > -------------------------------------- > public Object invokeHome(MethodInvocation mi) > throws Exception > { > - // We don't need an instance since the call > will be handled by container > + // We don't need an instance since the call will be > handled by container > return getNext().invokeHome(mi); > } > - > + > public Object invoke(MethodInvocation mi) > throws Exception > { > // Get context > - mi.setEnterpriseContext(container.getInstancePool().get()); > - > - // There is no need for synchronization since the > instance is always fresh also there should > - // never be a tx associated with the instance. > - > + InstancePool pool = container.getInstancePool(); > + EnterpriseContext ctx = pool.get(); > + mi.setEnterpriseContext(ctx); > + > + // There is no need for synchronization since the > instance is always fresh also there should > + // never be a tx associated with the instance. > try > { > // Invoke through interceptors > return getNext().invoke(mi); > - } catch (RuntimeException e) // Instance will be > GC'ed at MI return > + } > + catch (RuntimeException e) // Instance will be GC'ed > at MI return > { > - mi.setEnterpriseContext(null); > - throw e; > - } catch (RemoteException e) // Instance will be > GC'ed at MI return > + mi.setEnterpriseContext(null); > + pool.discard(ctx); > + throw e; > + } > + catch (RemoteException e) // Instance will be GC'ed > at MI return > { > - mi.setEnterpriseContext(null); > - throw e; > - } catch (Error e) // Instance will be GC'ed at MI return > + mi.setEnterpriseContext(null); > + pool.discard(ctx); > + throw e; > + } > + catch (Error e) // Instance will be GC'ed at MI return > { > - mi.setEnterpriseContext(null); > - throw e; > - } finally > + mi.setEnterpriseContext(null); > + pool.discard(ctx); > + throw e; > + } > + finally > { > - // Return context > - if (mi.getEnterpriseContext() != null) > - > container.getInstancePool().free(mi.getEnterpriseContext()); > + // Return context, when can this be null? > + ctx = mi.getEnterpriseContext(); > + if( ctx != null ) > + pool.free(ctx); > } > } > - > } > - > > > > > _______________________________________________ > Jboss-development mailing list [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-development > _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
