Class JakartaEndpointComponents
java.lang.Object
io.micronaut.servlet.websocket.JakartaEndpointComponents
Instantiates the classes a
@ServerEndpoint names in decoders, encoders
and configurator.
A Jakarta container creates these with Class.newInstance(). Here a class is resolved
through the first route that can produce it, and only the last one reflects:
- as a bean, when it is one;
- through its introspection, which the annotation processor generates for every class the endpoint names, when it has a no-argument constructor;
- reflectively, when
micronaut-reflectionis on the classpath and the type matches amicronaut.introspection.allow-reflectionpattern, after which it is a bean whose constructor arguments are injected.
- Since:
- 6.2.0
- Author:
- graemerocher
-
Constructor Summary
ConstructorsConstructorDescriptionJakartaEndpointComponents(io.micronaut.context.BeanContext beanContext, @Nullable ReflectiveBeanDefinitions reflective) Default constructor. -
Method Summary
Modifier and TypeMethodDescription@Nullable Class<?> encodedType(Class<?> encoder) The type an encoder encodes: the type argument of theEncoderinterface it implements.<T> Tinstantiate(Class<T> type) Creates an instance of the component.booleanisReflectionAllowed(Class<?> type) Whether the container itself may instantiate the type reflectively, which is what it does with the encoders of aServerEndpointConfig.
-
Constructor Details
-
JakartaEndpointComponents
public JakartaEndpointComponents(io.micronaut.context.BeanContext beanContext, @Nullable ReflectiveBeanDefinitions reflective) Default constructor.- Parameters:
beanContext- The bean contextreflective- The reflective route, present only withmicronaut-reflection
-
-
Method Details
-
instantiate
Creates an instance of the component. A bean is created as its scope says; an introspected type is instantiated anew on every call.- Type Parameters:
T- The component type- Parameters:
type- The component type- Returns:
- The instance
- Throws:
io.micronaut.websocket.exceptions.WebSocketException- if no route can produce the type
-
encodedType
The type an encoder encodes: the type argument of theEncoderinterface it implements.Read from the bean definition when the encoder is a bean, which the processors recorded at compilation time. Reading it from the class's generic signature is reflection, so that only happens with
micronaut-reflectionon the classpath. Otherwise the type is unknown and the encoder is offered every value, stepping aside for one it cannot encode; an encoder is therefore best declared as a bean.- Parameters:
encoder- The encoder class- Returns:
- The encoded type, or
nullwhen it cannot be resolved
-
isReflectionAllowed
Whether the container itself may instantiate the type reflectively, which is what it does with the encoders of aServerEndpointConfig.- Parameters:
type- The type- Returns:
truewhen the application has opted the type into reflection
-