Return-Path: Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 45942 invoked from network); 15 Nov 2000 15:04:31 -0000 Received: from mail.urova.fi (193.167.212.200) by locus.apache.org with SMTP; 15 Nov 2000 15:04:31 -0000 Received: from mail.urova.fi (limmonen.urova.fi [193.167.218.219]) by mail.urova.fi (8.10.2/8.10.2) with ESMTP id eAFF3vX28350 for ; Wed, 15 Nov 2000 17:03:57 +0200 (EET) Message-ID: <3A12A52C.1A113393@mail.urova.fi> Date: Wed, 15 Nov 2000 17:01:01 +0200 From: Lassi Immonen X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: fi,en,sv MIME-Version: 1.0 To: cocoon-dev@xml.apache.org Subject: Re: [C2]Advise on pooling References: <20001115145508.20624.qmail@web6202.mail.yahoo.com> Content-Type: multipart/mixed; boundary="------------1EE27F9D6F9C9DE8478434BA" X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------1EE27F9D6F9C9DE8478434BA Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Giacomo Pati wrote: > > --- Lassi Immonen wrote: > > Giacomo Pati wrote: > > > > > > --- Lassi Immonen 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... > > > 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); } } Should I synchronize setup? Lassi --------------1EE27F9D6F9C9DE8478434BA Content-Type: text/x-vcard; charset=us-ascii; name="limmonen.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Lassi Immonen Content-Disposition: attachment; filename="limmonen.vcf" begin:vcard n:Immonen;Lassi tel;cell:+358-40-7529690 tel;home:+358-40-7529690 tel;work:+358-40-7529690 x-mozilla-html:TRUE url:www.urova.fi org:University of Lapland;Digitys-project adr:;;PL 122;Rovaniemi;;96100;Finland version:2.1 email;internet:lassi.immonen@urova.fi title:Designer fn:Lassi Immonen end:vcard --------------1EE27F9D6F9C9DE8478434BA--