Return-Path: Delivered-To: apmail-cocoon-users-archive@www.apache.org Received: (qmail 48873 invoked from network); 2 Aug 2005 12:08:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Aug 2005 12:08:51 -0000 Received: (qmail 90141 invoked by uid 500); 2 Aug 2005 12:08:44 -0000 Delivered-To: apmail-cocoon-users-archive@cocoon.apache.org Received: (qmail 90112 invoked by uid 500); 2 Aug 2005 12:08:43 -0000 Mailing-List: contact users-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: users@cocoon.apache.org List-Id: Delivered-To: mailing list users@cocoon.apache.org Received: (qmail 90074 invoked by uid 99); 2 Aug 2005 12:08:42 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Aug 2005 05:08:42 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of jc.textor@gmx.de designates 213.165.64.20 as permitted sender) Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 02 Aug 2005 05:08:34 -0700 Received: (qmail invoked by alias); 02 Aug 2005 12:08:40 -0000 Received: from i3ED63B4F.versanet.de (EHLO [192.168.0.23]) [62.214.59.79] by mail.gmx.net (mp010) with SMTP; 02 Aug 2005 14:08:40 +0200 X-Authenticated: #2236490 Message-ID: <42EF6247.3070300@gmx.de> Date: Tue, 02 Aug 2005 14:08:39 +0200 From: Johannes Textor User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050404) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 To: users@cocoon.apache.org Subject: Re: AW: AW: Accessing the cocoon session from my Hibernate User-Type References: <4202DDA3828BD24D9381128D46B13D2B024FEF77@ktaemail01.villa-bosch.de> In-Reply-To: <4202DDA3828BD24D9381128D46B13D2B024FEF77@ktaemail01.villa-bosch.de> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi Elad, > I actually came to the same conclusion myself, when waiting to your reply and doing some googling :). > well that should mean it's not such a bad idea I hope :) > However I have used the ThreadLocal object. I didn't quite understand the differences between the Inherited and the ThreadLocal, and when I should use each... I will try to research it. > > InheritableThreadLocals are passed on to any child threads created by the current thread. This might be necessary because cocoon could spawn up new child threads, for example in a flowscript: cocoon.sendPage( .... ) is an asynchronous call, so I'd say it spawns up a new thread (without actually having checked the source). So your User object would be invisible to the pipeline created by cocoon.sendPage( ... ) when it is stored as a ThreadLocal. Using an InheritableThreadLocal OTOH, the child thread would receive its own copy of the User object. > Another thought I had is regarding what and when to store in the ThreadLocal. > What - I am not sure I should store the whole user request. I mean - If I only need the locale, why store the whole request ? > > You're right, it should suffice to store the Locale. I stored the entire request for 2 reasons: 1.) At present, I'm using an OpenSessionInView filter to manage the Hibernate Session. Communication between the filter and cocoon takes place via the request object. By storing the request object in the ThreadLocal, the HibernateSession becomes also accessible to all objects, which makes it unnecessary to pass the Session instance as a parameter to DAO Objects (which, in fact, breaks the DAO Design pattern). 2.) There is a subtile issue here with the InheritableThreadLocal. Upon creation, the child threads receives a copy of all of the parents InheritableThreadLocal objects. But after this point, if the InheritableThreadLocal is changed by either the parent or the child, changes are not reflected back to the other. For instance, in the cocoon.sendPage example, the pipeline invoked might want to change the user locale - but this change would be invisible to the flow script which lives in the parent thread. Storing a reference to the request object in the ThreadLocal is a (brutal) way around this problem: The reference itself is never changed, only the values inside the request object. These changes will then be visible to all possibly created child threads. However, storing the Locale in a Map or Hashtable which is then stored as an InheritableThreadLocal would yield the same effect. > When - I thought about using the locale action - which already is in-charge of locale maintaining, to save the locale in the ThreadLocale. I thought about inherit it, and add the needed code (User.setLocale( locale ); ) > > Sounds like a good idea. Regards, Johannes --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org For additional commands, e-mail: users-help@cocoon.apache.org