jsr356-experts@websocket-spec.java.net

[jsr356-experts] Instances and lifecycles for annotated endpoints

From: Scott Ferguson <ferg_at_caucho.com>
Date: Fri, 26 Oct 2012 19:13:55 -0700

http://java.net/jira/browse/WEBSOCKET_SPEC-21
http://java.net/jira/browse/WEBSOCKET_SPEC-37

This is an important issue.

In particular, the @WebSocketMessage methods really want to operate on
beans that are scoped to the connection/session (using the standard
@PostConstruct, @PreDestroy for lifecycle.) They're basically
MessageHandlers, not endpoints, and should have the same lifecycle as
MessageHandlers.

The @WebSocketOpen could be scoped to the application (as current, i.e.
as Endpoint), but it might be cleaner to change it as well to be called
on a new instance for each request (as if MessageHandler), to avoid
recreating the old home/instance EJB model. Either way would be logical,
but having a single lifecycle in the spec would be simpler to
define/explain.

So I'd suggest the cleanest change would be to instantiate a new
instance for each connection/session.

(Also, I assume each onMessage is in a new CDI RequestScope (?))

(Also, the 7.3.2 CDI injection into MessageHandlers doesn't make sense
to me. In the current API, the developer instantiates the handler and
therefore it would be weird for CDI to inject anything.)

-- Scott