You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Romain Manni-Bucau <rm...@gmail.com> on 2015/11/04 07:28:04 UTC

websocket tomcat listener API?

Hi guys,

Would it be possible to add to tomcat codebase a way to register custom
websocket lifecycle listeners for technical integration. For instance in
TomEE we would need a clean way to listen for close() or timeout() without
modifying the user code side if possible.

wdyt?

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

Re: websocket tomcat listener API?

Posted by Rémy Maucherat <re...@apache.org>.
2015-11-04 17:58 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:

> I see, will it be "fixed" or should it be worked-around with a
> BackgroundProcess - that is what we use ATM in TomEE SNAPSHOT code?
>
> I'd say it's not going to be improved further for now.

Rémy

Re: websocket tomcat listener API?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I see, will it be "fixed" or should it be worked-around with a
BackgroundProcess - that is what we use ATM in TomEE SNAPSHOT code?


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-11-04 8:57 GMT-08:00 Rémy Maucherat <re...@apache.org>:

> 2015-11-04 17:46 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:
>
> > there is not only fireClose case I think, if the client disconnect
> brutally
> > you skip this part I think, isn't it?
> >
>
> It is always called, but the websockets code isn't very rich on finally, so
> if something really unexpected occurs during the close process, it won't
> get called in some cases. It would need a finally on every line, so ...
>
> Rémy
>

Re: websocket tomcat listener API?

Posted by Rémy Maucherat <re...@apache.org>.
2015-11-04 17:46 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:

> there is not only fireClose case I think, if the client disconnect brutally
> you skip this part I think, isn't it?
>

It is always called, but the websockets code isn't very rich on finally, so
if something really unexpected occurs during the close process, it won't
get called in some cases. It would need a finally on every line, so ...

Rémy

Re: websocket tomcat listener API?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
2015-11-04 8:43 GMT-08:00 Rémy Maucherat <re...@apache.org>:

> 2015-11-04 15:59 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:
>
> > That is what I thought but extending WsSession in t8 is hard.
> >
> > Probably.
>
> So I'll see about porting it to Tomcat 8 if feedback is ok.
>
> However, I have two new problems:
> - I noticed during testing that the upgrade handler instance is created
> through the instance manager, but never destroyed
>

there is not only fireClose case I think, if the client disconnect brutally
you skip this part I think, isn't it?


> - the websockets client endpoint instances won't go through the instance
> manager
>

this is fine IMO as a first big step, client endpoints are easier to
integrate in client code since you - the user - handle the connection.


> For both of these situations, it would likely have to work through a static
> CL map, like naming does.
>
> Rémy
>

Re: websocket tomcat listener API?

Posted by Rémy Maucherat <re...@apache.org>.
2015-11-04 15:59 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:

> That is what I thought but extending WsSession in t8 is hard.
>
> Probably.

So I'll see about porting it to Tomcat 8 if feedback is ok.

However, I have two new problems:
- I noticed during testing that the upgrade handler instance is created
through the instance manager, but never destroyed
- the websockets client endpoint instances won't go through the instance
manager
For both of these situations, it would likely have to work through a static
CL map, like naming does.

Rémy

Re: websocket tomcat listener API?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
That is what I thought but extending WsSession in t8 is hard.
Le 4 nov. 2015 06:45, "Rémy Maucherat" <re...@apache.org> a écrit :

> 2015-11-04 15:16 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:
>
> > Yes, and would avoid a custom configurator :).
> >
> > In way the difficulty is that the configurator takes over the instance
> creation, but doesn't care about its destruction. If the default Tomcat
> configurator took care of newInstance, the tracking would fail if the
> configurator is replaced. Not very good. So the
> InstanceManager.newInstance(Object o) should always be used instead IMO
> after delegating instance creation to whatever configurator is present.
> Maybe from WsSession (since it's in a good position to call destroyInstance
> as well).
>
> Rémy
>

Re: websocket tomcat listener API?

Posted by Rémy Maucherat <re...@apache.org>.
2015-11-04 15:16 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:

> Yes, and would avoid a custom configurator :).
>
> In way the difficulty is that the configurator takes over the instance
creation, but doesn't care about its destruction. If the default Tomcat
configurator took care of newInstance, the tracking would fail if the
configurator is replaced. Not very good. So the
InstanceManager.newInstance(Object o) should always be used instead IMO
after delegating instance creation to whatever configurator is present.
Maybe from WsSession (since it's in a good position to call destroyInstance
as well).

Rémy

Re: websocket tomcat listener API?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Yes, and would avoid a custom configurator :).
Le 4 nov. 2015 06:09, "Rémy Maucherat" <re...@apache.org> a écrit :

> 2015-11-04 14:55 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:
>
> > Here is the use case: we make these endpoints go through the javee
> instance
> > manager. Being a ee server we support @Inject and in some cases - sadly
> the
> > most common one - we need a cleanup hook once the endpoint is no more
> used.
> >
> > Strictly at tomcat level think to postconstruct/predestroy support for
> > instance.
> >
> > Side note: when i spoke about timeout i thought to WsTimeout. Main point
> is
> > to know when to release the instance.
> >
> > Note also it would be awesome to have it for tomcat 8 :).
> >
>
> So if websockets was using the instance manager to get/destroy endpoint
> instances (it does for Servlets / JSP tags / etc, but not that at the
> moment) it would likely work for you, right ?
>
> Rémy
>

Re: websocket tomcat listener API?

Posted by Rémy Maucherat <re...@apache.org>.
2015-11-04 14:55 GMT+01:00 Romain Manni-Bucau <rm...@gmail.com>:

> Here is the use case: we make these endpoints go through the javee instance
> manager. Being a ee server we support @Inject and in some cases - sadly the
> most common one - we need a cleanup hook once the endpoint is no more used.
>
> Strictly at tomcat level think to postconstruct/predestroy support for
> instance.
>
> Side note: when i spoke about timeout i thought to WsTimeout. Main point is
> to know when to release the instance.
>
> Note also it would be awesome to have it for tomcat 8 :).
>

So if websockets was using the instance manager to get/destroy endpoint
instances (it does for Servlets / JSP tags / etc, but not that at the
moment) it would likely work for you, right ?

Rémy

Re: websocket tomcat listener API?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Here is the use case: we make these endpoints go through the javee instance
manager. Being a ee server we support @Inject and in some cases - sadly the
most common one - we need a cleanup hook once the endpoint is no more used.

Strictly at tomcat level think to postconstruct/predestroy support for
instance.

Side note: when i spoke about timeout i thought to WsTimeout. Main point is
to know when to release the instance.

Note also it would be awesome to have it for tomcat 8 :).

Le 4 nov. 2015 00:57, "Rémy Maucherat" <re...@apache.org> a écrit :
>
> 2015-11-04 9:47 GMT+01:00 Mark Thomas <ma...@apache.org>:
>
> > On 04/11/2015 06:28, Romain Manni-Bucau wrote:
> > > Hi guys,
> >
> > So you only want the views of the male committers?
> >
> > > Would it be possible to add to tomcat codebase a way to register
custom
> > > websocket lifecycle listeners for technical integration. For instance
in
> > > TomEE we would need a clean way to listen for close() or timeout()
> > without
> > > modifying the user code side if possible.
> >
> > Why? What is the use case?
> >
> > Also, there is no timeout() method but there is an error() method. There
> > is no clear way to differentiate between timeout and any other errors.
> >
> > > wdyt?
> >
> > Looking at trunk, it appears to be doable with some refactoring but
> > there would be a (probably small) performance impact. It depends on the
> > justification.
> >
> > Maybe it could be the usual integration thing, for example at the moment
> the endpoint instances are not going through the InstanceManager. Not sure
> if that would be enough for him. Obviously a listener system would be much
> more annoying (configuration needed, etc ...).
>
> Rémy

Re: websocket tomcat listener API?

Posted by Rémy Maucherat <re...@apache.org>.
2015-11-04 9:47 GMT+01:00 Mark Thomas <ma...@apache.org>:

> On 04/11/2015 06:28, Romain Manni-Bucau wrote:
> > Hi guys,
>
> So you only want the views of the male committers?
>
> > Would it be possible to add to tomcat codebase a way to register custom
> > websocket lifecycle listeners for technical integration. For instance in
> > TomEE we would need a clean way to listen for close() or timeout()
> without
> > modifying the user code side if possible.
>
> Why? What is the use case?
>
> Also, there is no timeout() method but there is an error() method. There
> is no clear way to differentiate between timeout and any other errors.
>
> > wdyt?
>
> Looking at trunk, it appears to be doable with some refactoring but
> there would be a (probably small) performance impact. It depends on the
> justification.
>
> Maybe it could be the usual integration thing, for example at the moment
the endpoint instances are not going through the InstanceManager. Not sure
if that would be enough for him. Obviously a listener system would be much
more annoying (configuration needed, etc ...).

Rémy

Re: websocket tomcat listener API?

Posted by Mark Thomas <ma...@apache.org>.
On 04/11/2015 06:28, Romain Manni-Bucau wrote:
> Hi guys,

So you only want the views of the male committers?

> Would it be possible to add to tomcat codebase a way to register custom
> websocket lifecycle listeners for technical integration. For instance in
> TomEE we would need a clean way to listen for close() or timeout() without
> modifying the user code side if possible.

Why? What is the use case?

Also, there is no timeout() method but there is an error() method. There
is no clear way to differentiate between timeout and any other errors.

> wdyt?

Looking at trunk, it appears to be doable with some refactoring but
there would be a (probably small) performance impact. It depends on the
justification.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org