cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grzegorz Kossakowski <>
Subject Re: Objects inherited in subrequests
Date Thu, 17 Jul 2008 17:44:29 GMT
imran pisze:
> Hello all
> Grzegorz as u wrote...
> Therefore I would like to propose introduction of a new scope called 
> "request-inheritable" which
> would allow beans (like ObjectModel) to be inherited but by cloning.
> can you please elaborate on that ... coz thats where we are stuck ...  
> if u have a look at the file
> public void forwardTo(String uri, Object bizData,
>                          WebContinuation continuation,
>                          Redirector redirector)
>    throws Exception {
>        if (SourceUtil.indexOfSchemeColon(uri) == -1) {
>            uri = "cocoon:/" + uri;
>            final Map objectModel = 
> this.processInfoProvider.getObjectModel();
>            FlowHelper.setWebContinuation(objectModel, newObjectModel, 
> continuation);
>            FlowHelper.setContextObject(objectModel, newObjectModel, 
> bizData);
>            if (redirector.hasRedirected()) {
>                throw new IllegalStateException("Pipeline has already 
> been processed for this request");
>            }
>            // this is a hint for the redirector
>            objectModel.put("cocoon:forward", "true");
>            redirector.redirect(false, uri);
>        } else {
>            throw new Exception("uri is not allowed to contain a scheme 
> (cocoon:/ is always automatically used)");
>        }
>    }
> so the instance of newObjectModel is the one from the bean factory ... 
> and if u have multithreading then all the threads change that 
> objectmodel simultaneously and then finally the objectmodel coming to 
> the JXTemplategenerator(Injected by spring) is not thread specific ...

It's not thread-specific but request-specific but here request means the one coming from browser
handled by servlet container and not those internal requests that Cocoon is doing when cocoon:
servlet: protocols are being used.

> in the setup method of the generator class we replace the objectmodel 
> injected by spring with the one passed with that method ... after doing 
> this the errors are not that frequent .. but they are still there :( .. 
> its still being modified by some other threads ...
> Could you please let us know how do u intend to implement ur proposed 
> solution

The idea is to introduce a new implementation of a Spring scope that will work in a following
1. if requested object (like OM) exists in current context then just return it
2. if requested object does not yet exist in current context then find out if this context
derived from root one:
    a) if the context is derived then ask the root for the object, clone it and store cloned
in current context
    b) if the context is not derived one so itself is a root then just ask Spring to create
a new 
instance of requested object and again store it in current context

The introduction of new contexts should happen only in two cases:
1. new thread is being invoked (for multi-thread scenarios)
2. new internal request is being invoked (in case of using servlet/cocoon protocols)

Even if this may sound scary, the implementation of this idea should be very simple. It's
only a few 
lines of code are needed to handle everything. Of course, the problem is where to inject this
Actually, today I was so busy with other work that I hadn't enough time to look into Cocoon
but tomorrow I'll do so and give you more detailed instructions how to implement this.

Hopefully, proposed solution should fix this problem once and for ever (at least I fail to
any situation when this wouldn't work)

Best regards,
Grzegorz Kossakowski

View raw message