On Friday 19 October 2001 18:35, Bill Burke wrote:
> The new interceptors were specifically designed so that other components
> such as CMP do not know whether or not or how a bean is cached.  What we
> can do is peek into the cache.  If the object is already there and is the
> same exact object (obj1 == obj2), then don't try to reinsert it.  I'll put
> this fix in.
>

I don't know if that would be so easy. As I can see from the 
EntityInstanceInterceptor.invokeHome() source this method pulls new context 
from the pool, associates it with the MethiodInvocation and sets the 
transaction context to it. Then it calls down the chain of interceptors.

If ejbPostCreate() down that chain calls some bussiness methods of other 
beans that in turn want to get to the context of our bean (as we see this 
happens when referencing relations), then AbstractInstanceCache.get(id) will 
be called and the AbstractInstanceCache.get(id) will not find our context in 
the cache since it was not inserted yet and will pull new context from pool 
and insert it with the same id into the cace. When 
EntityInstanceInterceptor.getNext().invokeHome() is finished we'll have a 
context in the cache with the same id as the context that we are about to 
insert but that will be two different contexts.

Just peeking into cache to see if context with the same id was already 
inserted is wrong, since until that time two contexts for the same instance 
were used and neither of them is correct any more.

If inserting into cache down the chain is out of question, then perhaps the 
following idea would be something to consider:

besides the "invoke" and "invokeHome" methods add "postInvoke" and 
"postInvokeHome" to the interceptors. The post* methods will be mostly empty 
(just a call down the chain) except when invocation is "create". This is the 
only invocation that gets distributed to two bean methods with complex 
processing between invocations (as we see the processing involves cache 
manipulation). That way the insertion into the cache would go into the 
EntityInstanceInterceptor.postInvokeHome() method just before calling down 
the chain with getNext().postInvokeHome() that will in turn lead to 
ejbPostCreate() invocation...

Peter


> > -----Original Message-----
> > From: Peter Levart [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, October 19, 2001 12:02 PM
> > To: Peter Levart; Bill Burke; Ole Husgaard;
> > [EMAIL PROTECTED]
> > Subject: Re: [JBoss-dev] Bug in cache
> >
> > My feeling is that the context should be inserted into cache between the
> > return from the ejbCreate() and the call to ejbPostCreate()
> > method. As soon
> > as the identity of the instance is established. This way the calls to
> > business methods in ejbPostCreate() will get an already cached
> > context via
> > AbstractInstanceCache.get() and this method (AbstractInstanceCache.get())
> > will not blindly acquireContext(), set it's id, activate it and
> > so on... only
> > to later, when time has come to insert the created context, find out that
> > some other context with same id has already been inserted...
> >
> > This is my ignorant understanding of the matter (I have just
> > downloaded the
> > sources and began to study the EJB specs a few days ago)...
> >
> > Peter

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to