Are you not worried about code breaking when container vendors take
advantage of the spec? We can define something now that will support the
current spec. I propose replacing servlets such as DatabaseServlet with the
concept of a "plugin" (hopefully, you can come up with a less overused
name):
1. Define the plugin interface:
public interface IPlugin {
void init(HttpServlet servlet) throws ServletException;
void destroy(HttpServlet servlet);
}
2. Define a plugin manager class:
public PluginManager implements IPlugin {
// list of plugins
private List _plugins;
public void init(HttpServlet servlet) throws ServletException {
// get the list of plugins from servlet's init parameters or
from a file
// for every plugin in the list, call its init method
}
public void destroy(HttpServlet servlet) {
// for every plugin in the list, call its destroy method
}
}
3. Convert DatabaseServlet and any other such servlets to plugins:
public DatabasePlugin implements IPlugin {
public void init(HttpServlet servlet) throws ServletException {
// original DatabaseServlet init code
}
public void destroy(HttpServlet servlet) {
// original DatabaseServlet destroy code
}
}
4. In ActionServlet's init method, instantiate PluginManager and call its
init method.
5. In ActionServlet's destroy method, call the PluginManager instance's
destroy method.
I don't know if you could (or if you would even want to) store the list of
plugins in the ActionServlet's init parameters because the order in which
they are initialized could be important.
Mike
- Original Message -
From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 21, 2000 10:13 PM
Subject: Re: Global resources and DatabaseServlet (struts-example)
> Mike Dunn wrote:
>
> > The DatabaseServlet in the example puts the database (a Hashtable) in
the
> > ServletContext. It removes it in its destroy method. As DatabaseServlet
can be
> > unloaded at anytime, why would you remove this global resource at this
time
> > (potentially prematurely)?
> >
> > Mike
>
> Under the servlet 2.2 API, there is no graceful way to deal with this.
The
> current implementation relies on the behavior of most servlet containers
that
> leave the servlet in place until the container is shut down.
>
> Under the new servlet 2.3 spec, the API support for application events
provides
> a *much* better place to do application startup and application shutdown
> processing, because you are guaranteed that the listener will be called
only at
> those two times.
>
> Craig McClanahan
>
>
>