Class ComponentProviderService
ComponentProviders which are used to provide
instances.- Author:
- Martin Matula, Stepan Kopriva, Pavel Bucek
-
Constructor Summary
ConstructorsConstructorDescriptionComponentProviderService(ComponentProviderService componentProviderService) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic ComponentProviderServicecreate()Create new instance ofComponentProviderService.static ComponentProviderServiceCreate new instance ofComponentProviderService.<T> ObjectgetCoderInstance(Class<T> c, Session session, EndpointConfig endpointConfig, ErrorCollector collector) <T> ObjectgetEndpointInstance(Class<T> endpointClass) This method is called by the container each time a new client connects to the logical endpoint this configurator configures.<T> ObjectgetInstance(Class<T> c, Session session, ErrorCollector collector) Provide an instance of class which is coupled toSession.getInvocableMethod(Method method) voidremoveSession(Session session) RemoveSessionfrom cache.
-
Constructor Details
-
ComponentProviderService
Copy constructor.- Parameters:
componentProviderService- original instance.
-
-
Method Details
-
create
Create new instance ofComponentProviderService.Searches for registered
ComponentProviders and registers them with this service.DefaultComponentProvideris always added to found providers.- Returns:
- initialized
ComponentProviderService.
-
createClient
Create new instance ofComponentProviderService.Contains *only*
DefaultComponentProvider. Used for creating client instances (CDI/EJB container are often confused and using them to retrieve instances leads to unstable results since the injection scope is not properly defined for these cases). See https://java.net/jira/browse/WEBSOCKET_SPEC-197 and https://java.net/jira/browse/WEBSOCKET_SPEC-196.- Returns:
- initialized
ComponentProviderService.
-
getInstance
Provide an instance of class which is coupled toSession.The first time the method is called the provider creates an instance and caches it. Next time the method is called the cached instance is returned.
- Type Parameters:
T- type of the provided instance.- Parameters:
c-Classwhose instance will be provided.session- session to which the instance belongs (think of this as a scope).collector- error collector.- Returns:
- instance
-
getCoderInstance
public <T> Object getCoderInstance(Class<T> c, Session session, EndpointConfig endpointConfig, ErrorCollector collector) Provide an instance ofEncoderorDecoderdescendant which is coupled toSession.The first time the method is called the provider creates an instance, calls
Encoder.init(jakarta.websocket.EndpointConfig)orDecoder.init(jakarta.websocket.EndpointConfig)and caches it. Next time the method is called the cached instance is returned.- Type Parameters:
T- type of the provided instance.- Parameters:
c-Classwhose instance will be provided.session- session to which the instance belongs (think of this as a scope).endpointConfig- configuration corresponding to current context. Used forEncoder.init(jakarta.websocket.EndpointConfig)andDecoder.init(jakarta.websocket.EndpointConfig)collector- error collector.- Returns:
- instance
-
getInvocableMethod
-
removeSession
RemoveSessionfrom cache.- Parameters:
session- to be removed.
-
getEndpointInstance
This method is called by the container each time a new client connects to the logical 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, for example, when the implementation is part of the Java EE platform may not be available. The platform default implementation of this method returns a new endpoint instance per call, thereby ensuring that there is one endpoint instance per client, the default deployment cardinality.- Type Parameters:
T- the type of the endpoint.- Parameters:
endpointClass- the class of the endpoint.- Returns:
- an instance of the endpoint that will handle all interactions from a new client.
- Throws:
InstantiationException- if there was an error producing the endpoint instance.- See Also:
-