Package org.atmosphere.config.managed
Class AnnotatedLifecycle
java.lang.Object
org.atmosphere.config.managed.AnnotatedLifecycle
Shared lifecycle and injection support for annotated endpoint classes.
Provides a unified framework that both
ManagedAtmosphereHandler
(@ManagedService) and @AiEndpoint delegate to, so
annotation scanning, lifecycle invocation, and field injection are
never duplicated.
Usage
// At registration time:
var lifecycle = AnnotatedLifecycle.scan(MyEndpoint.class);
AnnotatedLifecycle.injectFields(framework, instance);
// On connect:
lifecycle.onReady(instance, resource);
lifecycle.injectPathParams(instance, resource, pathTemplate, config);
// On disconnect:
lifecycle.onDisconnect(instance, event);
Capabilities
- Scans for
@Readyand@Disconnectlifecycle methods - Detects
@PathParamfields for per-request injection - Invokes lifecycle methods via
Utils.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object) - Triggers per-request
@PathParamfield injection viaInjectableObjectFactory.requestScoped(java.lang.Object, java.lang.Class<?>, org.atmosphere.cpr.AtmosphereResource) - Triggers one-time
@Injectfield injection viaInjectableObjectFactory.injectInjectable(U, java.lang.Class<? extends U>, org.atmosphere.cpr.AtmosphereFramework)
-
Method Summary
Modifier and TypeMethodDescriptionstatic MethodfindMethod(Class<?> clazz, Class<? extends Annotation> annotation) Finds the first method annotated with the given annotation.static booleanhasPathParamFields(Class<?> clazz) Checks whether the class has any@PathParam-annotated fields.booleanstatic voidinjectFields(AtmosphereFramework framework, Object instance) Injects@Inject-annotated fields on the target instance at registration time using Atmosphere'sInjectableObjectFactory.voidinjectPathParams(Object target, AtmosphereResource resource, String pathTemplate, AtmosphereConfig config) Injects@PathParam-annotated fields on the target instance for the current request.voidonDisconnect(Object target, AtmosphereResourceEvent event) Invokes the@Disconnect-annotated method if present.voidonReady(Object target, AtmosphereResource resource) Invokes the@Ready-annotated method if present.static AnnotatedLifecycle
-
Method Details
-
scan
- Parameters:
clazz- the annotated endpoint class- Returns:
- an immutable lifecycle descriptor
-
onReady
Invokes the@Ready-annotated method if present. Supports signatures:(),(AtmosphereResource). -
onDisconnect
Invokes the@Disconnect-annotated method if present. Supports signatures:(),(AtmosphereResourceEvent). -
readyMethod
-
disconnectMethod
-
hasPathParams
public boolean hasPathParams() -
injectPathParams
public void injectPathParams(Object target, AtmosphereResource resource, String pathTemplate, AtmosphereConfig config) Injects@PathParam-annotated fields on the target instance for the current request. Sets the request attribute thatPathParamIntrospectorexpects, then delegates toUtils.inject(Object, Class, AtmosphereResource).- Parameters:
target- the endpoint instanceresource- the current atmosphere resourcepathTemplate- the path template (e.g."/chat/{room}")config- the atmosphere configuration
-
injectFields
Injects@Inject-annotated fields on the target instance at registration time using Atmosphere'sInjectableObjectFactory.- Parameters:
framework- the atmosphere frameworkinstance- the endpoint instance to inject into
-
findMethod
Finds the first method annotated with the given annotation. Checks all public methods (including inherited) viaClass.getMethods().- Parameters:
clazz- the class to scanannotation- the annotation to look for- Returns:
- the annotated method, or
nullif not found
-
hasPathParamFields
Checks whether the class has any@PathParam-annotated fields.- Parameters:
clazz- the class to scan- Returns:
- true if at least one field is annotated with
@PathParam
-