Class ComponentProviderService


  • public class ComponentProviderService
    extends java.lang.Object
    Provides an instance of component. Searches for registered ComponentProviders which are used to provide instances.
    Author:
    Martin Matula, Stepan Kopriva, Pavel Bucek
    • Constructor Detail

      • ComponentProviderService

        public ComponentProviderService​(ComponentProviderService componentProviderService)
        Copy constructor.
        Parameters:
        componentProviderService - original instance.
    • Method Detail

      • createClient

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

        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
      • getInvocableMethod

        public java.lang.reflect.Method getInvocableMethod​(java.lang.reflect.Method method)
      • removeSession

        public void removeSession​(Session session)
        Remove Session 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)