On 10/26/2012 07:13 PM, Scott Ferguson wrote:
> 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.
I also think that would be clean. This means session parameter is not
required on all other methods except onOpen.
The instance can keep state across the connection messages.
@PostConstruct/_at_PreDestroy methods on an instance are called per connection.
I also think that websocket container (instead of CDI container) should
instantiate the bean, and handover it to CDI for injection.
Jitu
>
> (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
>