• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Tomcat resources in application context  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
This is my first post here. Not sure if it belongs to the servlets or the tomcat subforum.

Some background first -
I am using a database pooling framework called primrose. Among other things, it contains a web console, using which one may view the statuses and statistics about database connections. The console works as follows - an ObjectFactory implementor is provided, and the webconsole needs to be declared as a resource. The factory starts a (non daemon) thread in the background, and starts listening for connections on some port. To shut down the web console, a servlet class in the Primrose code needs to be declared in web.xml, and this servlet shuts down the web console, among other things.

Some questions:
1. AFAIK, the resource can be declared in the application's context, as well as in the GlobalResources context. The rest of the framework uses configuration (such as db connection info) can be declared in the application's context. Can something declared as a resource in the global context access a class created by a resource declaration in an application context? I did not think that it was possible, but that is how it seems to be - I verified it using a debugger.

2. As I mentioned above, the resource creates a thread in the background. When is the resource loaded - i.e. when is the factory method of the resource called? Based on my observations (using debuggers, etc), if the resource is declared in the global context, it is loaded when tomcat starts. If it is declared in the application context, the factory method is not called unless
a) It is called when a lookup is performed in the code, mentioned here - http://tomcat.apache.org/tomcat-6.0-doc/jndi-resourceshowto.html#Adding_Custom_Resource_Factories
Something like:

b) It is of type javax.sql.DataSource. This may sound strange, but here's the relevant code listing from the addResource method of org.apache.catalina.core.NamingContextListener class

As mentioned before, the webconsole needs to get the getinstance() method of its factory called. This can be done by putting it in the global context, but how does one do it by putting it in the META-INF/context.xml? Declaring the resource's type as javax.sql.DataSource may do the trick, but sounds like a real hack. Any suggestions?
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
global solutions you can do in your home or backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!