Hi, There seems to be no simple way to destroy jndi resources in tomcat, somebody had a similar problem here (http://fogbugz.atomikos.com/default.asp?community.6.2101.7) and was advised to use tomcat org.apache.catalina.Lifecycle* classes.
What I had first in mind was to register a NamespaceChangeListener into the context passed to the getObjectInstance() method but, apparently, it does not implement javax.naming.event.EventContext. This is what I wanted to do: http://pastebin.com/W7dCafPS (on pastebin to keep the formating). Is there another (simple) way to destroy my jndi resources? Thanks, Xavier > From: kal...@hotmail.com > To: users@tomcat.apache.org > Subject: RE: Destroying resources created with a custom ObjectFactory > Date: Tue, 29 Jan 2013 09:22:36 +0100 > > Hi, > Here is my context.xml > <Context> <Resource name="/cache/CacheManager" > type="net.sf.ehcache.CacheManager" factory="eg.CacheManagerFactory" > configurationFile="${catalina.home}/conf/test-ehcache.xml" /></Context> > and this is my ObjectFactory: > public class CacheManagerFactory implements ObjectFactory { > public Object getObjectInstance(Object object, Name jndiName, Context > context, Hashtable<?, ?> environment) throws Exception { String > configurationFile = null; if (object instanceof Reference) { > Reference reference = (Reference) object; Enumeration<RefAddr> refAddrs > = reference.getAll(); while (refAddrs.hasMoreElements()) { > RefAddr refAddr = refAddrs.nextElement(); if > ("configurationFile".equals(refAddr.getType())) { configurationFile > = (String) refAddr.getContent(); } } } CacheManager > cacheManager = configurationFile == null ? CacheManager.create() : > CacheManager.create(configurationFile); // Register some hook here to call > cacheManager.shutdown() on undeploy/redeploy return cacheManager; }} > Xavier > > Date: Mon, 28 Jan 2013 13:07:15 -0500 > > From: ch...@christopherschultz.net > > To: users@tomcat.apache.org > > Subject: Re: FW: Destroying resources created with a custom ObjectFactory > > > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA256 > > > > Xavier, > > > > On 1/28/13 12:20 PM, Xavier Dury wrote: > > > I'm using Tomcat 7.0.x and made a custom > > > javax.naming.spi.ObjectFactory to create a Ehcache manager, > > > exposing a configured CacheManager to an application through > > > (local) JNDI. My question is: how/where can I call the > > > CacheManager.shutdown() method when my application is > > > (re|un)deployed? I tried adding a NamespaceChangerListener to the > > > (Event)Context passed to the ObjectFactory.getObjectInstance() > > > method without luck. > > > > What does your configuration look like? Are you using <Resource> in > > server.xml/context.xml? > > > > - -chris > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG/MacGPG2 v2.0.17 (Darwin) > > Comment: GPGTools - http://gpgtools.org > > Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ > > > > iEYEAREIAAYFAlEGvlMACgkQ9CaO5/Lv0PAmawCfS5ZP+1RzKbQJzZBtwo6vrPj1 > > Z6YAn3NHTr/oiR7RUVgzZgMcs5NDNlCq > > =iX5J > > -----END PGP SIGNATURE----- > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > > For additional commands, e-mail: users-h...@tomcat.apache.org > > >