> Date: Tue, 10 May 2005 06:50:11 -0700 (PDT)
> From: Jinpeng Xie <jinpengxie@xxx.com>
> Subject: singleton startup class
> To: resin-interest@xxx.com
> Reply-To: resin-interest@xxx.com
>
> I want to integrate a singleton startup class into the
> server. The startup class will be started with the
> server and before the application. Also the startup
> class is also bound into a JNDI name so it can be
> accessed by any application via lookup. Please direct
> me documantation and sameples.
In Resin, we call that a "Resource".
There is a tutorial here:
http://www.caucho.com/resin-3.0/resource/tutorial/basic/index.xtp
If your bean has an public void init() method, it will be called after the
setters are called.
http://www.caucho.com/resin-3.0/ioc/bean-patterns.xtp
If your bean has a public void destroy() method, it will be
called when the web-app or server or host is shutdown (depending
on where the configuration is placed).
Since you want the lifecycle of your singleton to match the
lifecycle of the server, you can configure it as a child of the
<server> in resin.conf:
<server>
...
<resource jndi-name="test/basic" type="test.TestResource">
<init>
<value>An Example Resource</value>
</init>
</resource>
...
</web-app>
That configuration causes the instantiation of one instance of
"test.TestResource" and makes the instance available with the jndi name
"java:comp/env/test/basic".
When doing a jndi lookup from a web-app, the resources in the enclosing host,
and enclosing server, are available. By putting a resource with the jndi name
"test/basic" in the <server> level, every web-app will get the same instance
of that resource when it uses the "java:comp/env/test/basic" for a jndi lookup.
If you put a resource at the server level, the class that is the resource, and
all of the classes that it depends on, need to be in the server classloader.
You can put a jar in $RESIN_HOME/lib, or use the <classloader> configuration in
<server> to add a customized location.
-- Sam
Received on Tue 10 May 2005 08:28:33 -0700
This archive was generated by hypermail 2.1.8 : Thu Sep 28 2006 - 20:18:42 PDT