Re: Global resources and DatabaseServlet (struts-example)

2000-11-24 Thread Craig R. McClanahan

Mike Dunn wrote:

> 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):
>

Are you thinking that the "plugins" will be plugged into ActionServlet?  If so,
you've still got the same issues as with DatabaseServlet, because the servlet
container is entitled to throw out your ActionServlet instance if it wants to.

In the servlet 2.3 API, there is a new feature called "Application Event
Listeners".  You can register (in web.xml) a particular class as a listener, and
an instance of your class will be called when the application is created, and
when it is destroyed -- completely independent of the lifecycle of the servlets
in that application.

This is perfect for things like initializing and finalizing database
connections, or any other resources that you want to guarantee you have
available for the entire lifetime of your app.  Unfortunately, I cannot (yet)
use them in Struts because it wouldn't be supported in any of the servlet 2.2 /
JSP 1.1 containers out there.

If you want to try this new feature, I suggest you download a recent milestone
release of Tomcat 4.0 (http://jakarta.apache.org), which supports the new APIs.

Craig McClanahan





Re: Global resources and DatabaseServlet (struts-example)

2000-11-24 Thread Mike Dunn

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
>
>
>



Re: Global resources and DatabaseServlet (struts-example)

2000-11-21 Thread Craig R. McClanahan

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