Return-Path: Delivered-To: apmail-cocoon-users-archive@www.apache.org Received: (qmail 70082 invoked from network); 10 Feb 2004 10:07:40 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 10 Feb 2004 10:07:40 -0000 Received: (qmail 3359 invoked by uid 500); 10 Feb 2004 10:06:54 -0000 Delivered-To: apmail-cocoon-users-archive@cocoon.apache.org Received: (qmail 3340 invoked by uid 500); 10 Feb 2004 10:06:54 -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 Delivered-To: mailing list users@cocoon.apache.org Received: (qmail 3265 invoked from network); 10 Feb 2004 10:06:53 -0000 Received: from unknown (HELO moutng.kundenserver.de) (212.227.126.184) by daedalus.apache.org with SMTP; 10 Feb 2004 10:06:53 -0000 Received: from [212.227.126.209] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1AqUnK-0006fl-00 for users@cocoon.apache.org; Tue, 10 Feb 2004 11:07:06 +0100 Received: from [217.228.228.70] (helo=gmx.net) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1AqUnJ-0000E8-00 for users@cocoon.apache.org; Tue, 10 Feb 2004 11:07:06 +0100 Message-ID: <4028AD48.5050101@gmx.net> Date: Tue, 10 Feb 2004 11:07:04 +0100 From: Stephan Coboos User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: users@cocoon.apache.org Subject: Re: How to initialize a component coming from the pool? References: <4027D38A.4040609@gmx.net> <4028A5FF.8030306@gmx.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:431002173563032d2d00337e9d76f4cf X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Jorg Heymans wrote: > Looking a bit better at the docs that was not the best advice from my > part sorry. > > I am assuming that you want to use myComponent throughout your whole > component, hence the need to only look it up once when it comes from > the pool. But what is so special about myComponent that you want a > fresh one every time? > > Think about a SQL connection which should shared between two or more methods in the component. After usage of the component the connection must returned to the pool. Next time I will get the component from the pool I need another connection object from the pool. I'm appending a part of a message which I had posted in the avalon mailing list about this problem: public class AnotherComponent implements Serviceable, AnotherInterface, Recyclable, Initializable { private ServiceManager m_ServiceManager; private ComponentDatasource ds; private Connection con; public void processSomething() { Connection con = this.con; // Do something here with con... // but do not close! } public void processSomething2() { Connection con = this.con; // Do something here with con... // but do not close! } public void initialize() { this.ds = ... // Getting the datasource from the serviceManager this.con = this.ds.getConnection(); } public void recycle() { // Here close the connection and return them to the pool this.con.close(); // Release the datasource this.serviceManager.release(ds); } public void service( ServiceManager man ) { m_ServiceManager = man; } } Please have a look into the code above. In the method initialize() I'am creating the datasource and the connection. The connection will be used by the two methods processSomething() and processSomething2(). I dont want to create a new connection or close it in each method. After the component will not be longer in use, I'am returning it into the pool and therefore the method recycle() will be called which closes the connection and releases the datsource. But what happens if I get the component the next time from the pool? Where is the initialization process to get the datasource and connection called? In intialize()? I think not because initialize() will be called only once at instanciation time and after that never more. So where to put the initialization code if I have a pooled component? Thank you. Regards Stephan --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org For additional commands, e-mail: users-help@cocoon.apache.org