On 25/02/2013 16:42, Danny Coward wrote:
> OK, well several of you have voiced a desire for this need to control
> creation of instances, I think our ServerEndpointConfigurator could be
> extended to play the role and provide the hook.
>
> If all of you that want this are ok with just using the CDI:
> javax.annotation.PostConstruct annotation, then please speak up and we
> are done ! But I strongly suspect not, so otherwise, please read on:-
>
> The 'EndpointFactory' proposal would be to add what was the old (from
> v008!) EndpointFactory.create() method for endpoint instances to todays
> ServerEndpointConfigurator.
>
> The developer can already provide a customized
> ServerEndpointConfigurator by subtyping it, overriding any of its
> methods and either setting it in the ServerEndpointConfigurationBuilder,
> or by using the configuration() attribute in @ServerEndpoint.
>
> So if we add the factory method there, the developer can provide his own
> implementation of the method. The specification would require that this
> method be used if overridden. The container default
> ServerEndpointConfigurator would use its existing mechanisms to
> instantiate the endpoint instances (i.e. using CDI in the EE case,
> public no-arg constructor else).
>
> Specifically, add to ServerEndpointConfigurator
>
> /** (something like) This method is called by the container when it
> needs a new
> ** instance of the endpoint this configurator configures. Developers
> ** may override this method to control instantiation of
> ** endpoint instances in order to customize the initialization
> ** of the endpoint instance, or manage them in some other way.
> ** If the developer overrides this method, services like
> ** dependency injection that are otherwise supported
> ** may not be available.
> */
> public Object createEndpoint() throws InstantiationException;
>
> Works equally well for programmatic endpoints and annotated endpoints,
> and fits with the existing configuration scheme.
The name createEndpoint() suggests a new object is created every time.
Maybe change it?
I'd like to see something along the following lines in the Javadoc:
The default implementation will return a new object on every call. Other
implementations may return the same object for multiple calls or have
some other strategy for determing if object a reused or a new object
created.
Mark