You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Morten Primdahl <mo...@caput.com> on 2000/05/08 12:57:27 UTC

Producers

Hi. Where does the Director used to initialize a producer come
from? How do I access it prior to initializing a producer? I need
some way to have some persistent classes which are shared among
several producers, eg. a JDBC connection pool, as far as I can
tell, the proper way to do this, is to make a class that implements
the director interface and then do something like 
setRole("jdbcpool",connectionPool). Are there other ways to share
a persistent service between several producers?

Thanks in advance

Morten

-- 
Morten Primdahl		Caput ApS	Tel +45 33 12 24 42		
morten@caput.com	Nygade 6	Fax +45 33 91 24 42
http://www.caput.com	DK-1164 Kbh K

Re: Producers

Posted by Stefano Mazzocchi <st...@apache.org>.
Morten Primdahl wrote:
> 
> Hi. Where does the Director used to initialize a producer come
> from? How do I access it prior to initializing a producer? I need
> some way to have some persistent classes which are shared among
> several producers, eg. a JDBC connection pool, as far as I can
> tell, the proper way to do this, is to make a class that implements
> the director interface and then do something like
> setRole("jdbcpool",connectionPool). Are there other ways to share
> a persistent service between several producers?

in your Producer overload the Actor.init(Director director) method:

  void init(Director director) {
	Object pool = director.getRole("jdbcpool");
	if (pool == null) {
          director.setRole("jdbcppool", new MyConnectionPool());
	}
  }

then each you can use director.getRole() from other producers to gain
access to that instance.

The only problem is to make sure the producer which initializes this
component is called first...

The Avalon framework provides a much better solution for this and
Cocoon2 is moving in this direction, so I suggest you to look at the
Cocoon2 source for more advanced usages and more future-compatible code.

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<st...@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------