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.
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?
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java