Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [servlet-dev] Big ticket items for Servlet 6 / Jakarta EE 10?



On Thu, 3 Sept 2020 at 00:20, Stuart Douglas <sdouglas@xxxxxxxxxx> wrote:
CDI needs more than just the instance to destroy the object properly, and you really need to let CDI actually create the instance to get interceptors etc. 

Ideally you want an API that looks like the Undertow one:

public interface InstanceFactory<T> {
    InstanceHandle<T> createInstance();
}

public interface InstanceHandle<T> {
    T getInstance();
    void release();
}

The problem here is that we already have the factory methods `ServletContext.createServlet(Class) etc.
The servlet, filters and listeners returned are intended to be added with the corresponding add method, but they could be wrapped or used in some other way.    Thus we don't have a good way to pass around the InstanceHandle.    
Filters and Servlets have destroy methods, so perhaps there is some scope to somehow wire them up to some CDI release mechanism, but Listeners don't have the same.

So I'm totally on board with making these create methods able to delegate to CDI (or some other factory method), so having a pluggable factory is a good start.     But we need to consider how we trigger release in all cases - including when the instances are not directly passed to an add method.

Thus I think we need to clean up these lifecycle methods to make sure they cover the full livecycle of the object.  Once we do that, it should be trivial to make it pluggable and thus be able to plug in CDI

cheers






 
--

Back to the top