[jetty-users] Detecting WAR stop within a servlet in Jetty 9

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[jetty-users] Detecting WAR stop within a servlet in Jetty 9

Chris Haynes
I have a servlet which opens server sockets (not HTTP). When the WAR containing the servlet is closed and re-opened the replacement servlet finds that the sockets are already open and crashes.

I need some means, inside the servlet, of detecting that the WAR is about to be shut down, so that I can close the sockets.  I can see all sorts of useful and apparently-relevant lifecycle artifacts inside Jetty. but the Jetty sandboxing of the servlet seems complete; I can find no way to link in to these classes.

I've also been trying the PreDestroy approach suggested in
http://wiki.eclipse.org/Jetty/Feature/Annotations
which looks as if it ought to work but the method tagged with the @PreDestroy attribute is never invoked.  I've noted that this is described in Java 8 documentation and I'm attempting Jetty 9 - is that significant?

I'm running out of ideas now. I have thought of designing a custom WebApplicationHandler, which presumably can participate in the lifecycle system and could than 'poke' my servlet through a custom Interface, but this is not very elegant.

Any other ideas?

Regards,

Chris Haynes

_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: [jetty-users] Detecting WAR stop within a servlet in Jetty 9

ccleve
HttpServlet.destroy() doesn't get called?

Note that sometimes the OS keeps sockets open for a time after you tell
it to close them.

On 1/19/2013 12:04 PM, Chris Haynes wrote:

> I have a servlet which opens server sockets (not HTTP). When the WAR containing the servlet is closed and re-opened the replacement servlet finds that the sockets are already open and crashes.
>
> I need some means, inside the servlet, of detecting that the WAR is about to be shut down, so that I can close the sockets.  I can see all sorts of useful and apparently-relevant lifecycle artifacts inside Jetty. but the Jetty sandboxing of the servlet seems complete; I can find no way to link in to these classes.
>
> I've also been trying the PreDestroy approach suggested in
> http://wiki.eclipse.org/Jetty/Feature/Annotations
> which looks as if it ought to work but the method tagged with the @PreDestroy attribute is never invoked.  I've noted that this is described in Java 8 documentation and I'm attempting Jetty 9 - is that significant?
>
> I'm running out of ideas now. I have thought of designing a custom WebApplicationHandler, which presumably can participate in the lifecycle system and could than 'poke' my servlet through a custom Interface, but this is not very elegant.
>
> Any other ideas?
>
> Regards,
>
> Chris Haynes
>


_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: [jetty-users] Detecting WAR stop within a servlet in Jetty 9

Chris Haynes
In reply to this post by Chris Haynes
Sorry all,

I've solved my own problem.
I had not noticed Servlet#destroy), which seems to be called at the right places in the life cycle.
Chris Haynes


On Saturday, January 19, 2013 at 6:04:13 PM, Chris Haynes wrote:
> I have a servlet which opens server sockets (not HTTP). When the
> WAR containing the servlet is closed and re-opened the replacement
> servlet finds that the sockets are already open and crashes.

> I need some means, inside the servlet, of detecting that the WAR is
> about to be shut down, so that I can close the sockets.  I can see
> all sorts of useful and apparently-relevant lifecycle artifacts
> inside Jetty. but the Jetty sandboxing of the servlet seems
> complete; I can find no way to link in to these classes.

> I've also been trying the PreDestroy approach suggested in
> http://wiki.eclipse.org/Jetty/Feature/Annotations
> which looks as if it ought to work but the method tagged with the
> @PreDestroy attribute is never invoked.  I've noted that this is
> described in Java 8 documentation and I'm attempting Jetty 9 - is that significant?

> I'm running out of ideas now. I have thought of designing a custom
> WebApplicationHandler, which presumably can participate in the
> lifecycle system and could than 'poke' my servlet through a custom
> Interface, but this is not very elegant.

> Any other ideas?

> Regards,

> Chris Haynes

> _______________________________________________
> jetty-users mailing list
> [hidden email]
> https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users