cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giacomo Pati <giac...@apache.org>
Subject Re: [C2]Advise on pooling
Date Thu, 16 Nov 2000 06:23:44 GMT
Giacomo Pati wrote:
> 
> --- Lassi Immonen <limmonen@malla.urova.fi> wrote:
> > Giacomo Pati wrote:
> > >
> > > --- Lassi Immonen <limmonen@malla.urova.fi> wrote:
> > > > Giacomo Pati wrote:
> > > > >
> > > > > --- Lassi Immonen <limmonen@malla.urova.fi> wrote:
> > > > > > Hi,
> > > > > >
> > > > > > I would like to implement pooling in Transformer which
> > translates
> > > > > > xml-files from translations file.
> > > > > > Now it loads translations to Map every time request is made
> > but I
> > > > > > would
> > > > > > like to keep available pool of Maps containing translations
> > for a
> > > > > > given
> > > > > > url/language.
> > > > >
> > > > > I don't know exactly what you mean. If you want to save already
> > > > > processed stuff into a store for later reusage then use the
> > store
> > > > > component (see XalanTransformer.java).
> > > >
> > > > Well, now my transformer has field "Map dictionary". And I want
> > to
> > > > add
> > > > "Hashtable dictionaries" which is in form (incoming url+lang,
> > > > dictionary) and put loaded dictionaries in there and check if one
> > is
> > > > available before parsing translations file.
> > >
> > > Don't use Hashtables! We are coding against a JDK 1.2 so use
> > HashMaps.
> >
> > Aha, there are quite many Hashtables in C2 source...
> 
> I know (it's on my todo list) but it would be better not to introduce
> new ones :)
> 
> > >
> > > > Do I have to make my transformer poolable or put dictionaries
> > > > Hashtable
> > > > outside transformer to get the available dictionaries every time
> > my
> > > > transformer is called? Is transformer created every time/request
> > or
> > > > does
> > > > it stay in memory?
> > >
> > > No transformer is able to be thread safe because of the SAX model
> > > (except you are using ThreadLocal stuff). So, if you implement
> > Poolable
> > > on your transformer you prevent reinstaciating your transformer
> > over
> > > and over again because the framework will put it into a pool. Use
> > the
> > > store component from the ComponentManager to put your Maps into.
> > >
> >
> > So something like this:
> >
> > MyTransformer
> >
> > ....
> > Hashmap dict = null;
> > ComponentManager cm;
> > ..
> > setup(...) {
> >       MemoryStore ms = (MemoryStore)cm.lookup(Roles.STORE)
> >       Hashmap dictionaries = ms.get("DICTIONARIES");
> >       if (dictionaries == null)
> >               dictionaries = new Hashmap();
> >               ms.store("DICTIONARIES",dictionaries);
> >       if ( dictionaries has dictionary i need)
> >               dict = dictionaries.get(...)
> >       else {
> >           dict = InitialiseDictionaryFromXMLFile();
> >           dictionaries.put(...,dict);
> >       }
> > }
> 
> Yup, but try to use a name for the object in the store to prevent
> collisions.
> 
> > Should I synchronize setup?
> 
> Not necessary because your transformer will not be used multithreaded.

Of course you should synchronize your "dictionaries" when you modify it.

Giacomo

Mime
View raw message