Class AnnotatedLifecycle

java.lang.Object
org.atmosphere.config.managed.AnnotatedLifecycle

public final class AnnotatedLifecycle extends Object
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

  • Method Details

    • scan

      public static AnnotatedLifecycle scan(Class<?> clazz)
      Scans the given class for @Ready, @Disconnect methods and @PathParam fields.
      Parameters:
      clazz - the annotated endpoint class
      Returns:
      an immutable lifecycle descriptor
    • onReady

      public void onReady(Object target, AtmosphereResource resource)
      Invokes the @Ready-annotated method if present. Supports signatures: (), (AtmosphereResource).
    • onDisconnect

      public void onDisconnect(Object target, AtmosphereResourceEvent event)
      Invokes the @Disconnect-annotated method if present. Supports signatures: (), (AtmosphereResourceEvent).
    • readyMethod

      public Method readyMethod()
    • disconnectMethod

      public Method 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 that PathParamIntrospector expects, then delegates to Utils.inject(Object, Class, AtmosphereResource).
      Parameters:
      target - the endpoint instance
      resource - the current atmosphere resource
      pathTemplate - the path template (e.g. "/chat/{room}")
      config - the atmosphere configuration
    • injectFields

      public static void injectFields(AtmosphereFramework framework, Object instance)
      Injects @Inject-annotated fields on the target instance at registration time using Atmosphere's InjectableObjectFactory.
      Parameters:
      framework - the atmosphere framework
      instance - the endpoint instance to inject into
    • findMethod

      public static Method findMethod(Class<?> clazz, Class<? extends Annotation> annotation)
      Finds the first method annotated with the given annotation. Checks all public methods (including inherited) via Class.getMethods().
      Parameters:
      clazz - the class to scan
      annotation - the annotation to look for
      Returns:
      the annotated method, or null if not found
    • hasPathParamFields

      public static boolean hasPathParamFields(Class<?> clazz)
      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