Class ComponentProviderService
- java.lang.Object
-
- org.glassfish.tyrus.core.ComponentProviderService
-
public class ComponentProviderService extends java.lang.Object
Provides an instance of component. Searches for registeredComponentProvider
s which are used to provide instances.- Author:
- Martin Matula (martin.matula at oracle.com), Stepan Kopriva (stepan.kopriva at oracle.com), Pavel Bucek (pavel.bucek at oracle.com)
-
-
Constructor Summary
Constructors Constructor Description ComponentProviderService(ComponentProviderService componentProviderService)
Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ComponentProviderService
create()
Create new instance ofComponentProviderService
.static ComponentProviderService
createClient()
Create new instance ofComponentProviderService
.<T> java.lang.Object
getCoderInstance(java.lang.Class<T> c, Session session, EndpointConfig endpointConfig, ErrorCollector collector)
<T> java.lang.Object
getEndpointInstance(java.lang.Class<T> endpointClass)
This method is called by the container each time a new client connects to the logical endpoint this configurator configures.<T> java.lang.Object
getInstance(java.lang.Class<T> c, Session session, ErrorCollector collector)
Provide an instance of class which is coupled toSession
.java.lang.reflect.Method
getInvocableMethod(java.lang.reflect.Method method)
void
removeSession(Session session)
RemoveSession
from cache.
-
-
-
Constructor Detail
-
ComponentProviderService
public ComponentProviderService(ComponentProviderService componentProviderService)
Copy constructor.- Parameters:
componentProviderService
- original instance.
-
-
Method Detail
-
create
public static ComponentProviderService create()
Create new instance ofComponentProviderService
.Searches for registered
ComponentProvider
s and registers them with this service.DefaultComponentProvider
is always added to found providers.- Returns:
- initialized
ComponentProviderService
.
-
createClient
public static 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
public <T> java.lang.Object getInstance(java.lang.Class<T> c, Session session, ErrorCollector collector)
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
-Class
whose 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> java.lang.Object getCoderInstance(java.lang.Class<T> c, Session session, EndpointConfig endpointConfig, ErrorCollector collector)
Provide an instance ofEncoder
orDecoder
descendant which is coupled toSession
.The first time the method is called the provider creates an instance, calls
Encoder.init(javax.websocket.EndpointConfig)
orDecoder.init(javax.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
-Class
whose instance will be provided.session
- session to which the instance belongs (think of this as a scope).collector
- error collector.endpointConfig
- configuration corresponding to current context. Used forEncoder.init(javax.websocket.EndpointConfig)
andDecoder.init(javax.websocket.EndpointConfig)
- Returns:
- instance
-
getInvocableMethod
public java.lang.reflect.Method getInvocableMethod(java.lang.reflect.Method method)
-
removeSession
public void removeSession(Session session)
RemoveSession
from cache.- Parameters:
session
- to be removed.
-
getEndpointInstance
public <T> java.lang.Object getEndpointInstance(java.lang.Class<T> endpointClass) throws java.lang.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.- 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:
java.lang.InstantiationException
- if there was an error producing the endpoint instance.- See Also:
ServerEndpointConfig.Configurator.getEndpointInstance(Class)
-
-