Top Description Fields Constructors Methods
org.glassfish.tyrus.core

public Class ComponentProviderService

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.ArrayList, .Arrays, .Collections, .HashMap, .List, .Map, java.util.concurrent.ConcurrentHashMap, jakarta.websocket.Decoder, .DeploymentException, .Encoder, .EndpointConfig, .Session, org.glassfish.tyrus.core.l10n.LocalizationMessages

Provides an instance of component. Searches for registered ComponentProviders which are used to provide instances.
Authors
Martin Matula, Stepan Kopriva, Pavel Bucek

Field Summary

Modifier and TypeField and Description
private final List<ComponentProvider>
private final Map<Session, Map<Class<?>, Object>>

Constructor Summary

AccessConstructor and Description
private
public
ComponentProviderService(ComponentProviderService
original instance.
componentProviderService
)

Copy constructor.

Method Summary

Modifier and TypeMethod and Description
public static ComponentProviderService

Returns:

initialized ComponentProviderService.
create
()

Create new instance of ComponentProviderService.

public static ComponentProviderService

Returns:

initialized ComponentProviderService.
createClient
()

Create new instance of ComponentProviderService.

public <
type of the provided instance.
T
>
Object

Returns:

instance
getCoderInstance
(Class<T>
Class whose instance will be provided.
c
,
Session
session to which the instance belongs (think of this as a scope).
session
,
EndpointConfig endpointConfig, ErrorCollector
error collector.
collector
)

Provide an instance of jakarta.websocket.Encoder or jakarta.websocket.Decoder descendant which is coupled to Session.

public <
the type of the endpoint.
T
>
Object

Returns:

an instance of the endpoint that will handle all interactions from a new client.
getEndpointInstance
(Class<T>
the class of the endpoint.
endpointClass
)

This method is called by the container each time a new client connects to the logical endpoint this configurator configures.

public <
type of the provided instance.
T
>
Object

Returns:

instance
getInstance
(Class<T>
Class whose instance will be provided.
c
,
Session
session to which the instance belongs (think of this as a scope).
session
,
ErrorCollector
error collector.
collector
)

Provide an instance of class which is coupled to Session.

private <T> Object
getInstance(Class<T> clazz)

public Method
public void
removeSession(Session
to be removed.
session
)

Remove Session from cache.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

providersback to summary
private final List<ComponentProvider> providers
sessionToObjectback to summary
private final Map<Session, Map<Class<?>, Object>> sessionToObject

Constructor Detail

ComponentProviderServiceback to summary
private ComponentProviderService(List<ComponentProvider> providers)
ComponentProviderServiceback to summary
public ComponentProviderService(ComponentProviderService componentProviderService)

Copy constructor.

Parameters
componentProviderService:ComponentProviderService

original instance.

Method Detail

createback to summary
public static ComponentProviderService create()

Create new instance of ComponentProviderService.

Searches for registered ComponentProviders and registers them with this service.

DefaultComponentProvider is always added to found providers.

Returns:ComponentProviderService

initialized ComponentProviderService.

createClientback to summary
public static ComponentProviderService createClient()

Create new instance of ComponentProviderService.

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:ComponentProviderService

initialized ComponentProviderService.

getCoderInstanceback to summary
public <T> Object getCoderInstance(Class<T> c, Session session, EndpointConfig endpointConfig, ErrorCollector collector)

Provide an instance of jakarta.websocket.Encoder or jakarta.websocket.Decoder descendant which is coupled to Session.

The first time the method is called the provider creates an instance, calls jakarta.websocket.Encoder#init(jakarta.websocket.EndpointConfig) or jakarta.websocket.Decoder#init(jakarta.websocket.EndpointConfig) and caches it. Next time the method is called the cached instance is returned.

Parameters
<T>
type of the provided instance.
c:Class<T>

Class whose instance will be provided.

session:Session

session to which the instance belongs (think of this as a scope).

endpointConfig:EndpointConfig

configuration corresponding to current context. Used for jakarta.websocket.Encoder#init(jakarta.websocket.EndpointConfig) and jakarta.websocket.Decoder#init(jakarta.websocket.EndpointConfig)

collector:ErrorCollector

error collector.

Returns:Object

instance

getEndpointInstanceback to summary
public <T> Object getEndpointInstance(Class<T> endpointClass) throws InstantiationException

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.

Parameters
<T>
the type of the endpoint.
endpointClass:Class<T>

the class of the endpoint.

Returns:Object

an instance of the endpoint that will handle all interactions from a new client.

Exceptions
InstantiationException:
if there was an error producing the endpoint instance.
See Also
jakarta.websocket.server.ServerEndpointConfig.Configurator#getEndpointInstance(Class)
getInstanceback to summary
public <T> Object getInstance(Class<T> c, Session session, ErrorCollector collector)

Provide an instance of class which is coupled to Session.

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.

Parameters
<T>
type of the provided instance.
c:Class<T>

Class whose instance will be provided.

session:Session

session to which the instance belongs (think of this as a scope).

collector:ErrorCollector

error collector.

Returns:Object

instance

getInstanceback to summary
private <T> Object getInstance(Class<T> clazz) throws InstantiationException
getInvocableMethodback to summary
public Method getInvocableMethod(Method method)
removeSessionback to summary
public void removeSession(Session session)

Remove Session from cache.

Parameters
session:Session

to be removed.