Class ActionDiscovery

java.lang.Object
com.tnsai.actions.ActionDiscovery

@ThreadSafe public class ActionDiscovery extends Object
Discovers actions from Role classes using reflection. Scans public methods with @Action annotation and converts them to ActionMetadata. Following ADR-004: Action Discovery via Reflection - Public methods with @Action annotation = Actions - Methods without @Action = Helper methods (ignored) - Private/protected methods = Helper methods (ignored) - Results are cached for performance IMPORTANT: @Action annotation is MANDATORY for methods to be discovered as actions. Inherited public instance actions remain available until overridden. An override without @ActionSpec removes exposure; an annotated override supplies the complete method metadata. The same override rule applies to capability defaults. Thread-safe with concurrent cache.
  • Constructor Details

    • ActionDiscovery

      public ActionDiscovery()
  • Method Details

    • discoverActions

      public static DiscoveredRoleActions discoverActions(Role role)
      Discovers all actions from a Role instance. Results are cached by role class.
      Parameters:
      role - the role instance
      Returns:
      role metadata with all discovered actions
    • discoverActions

      public static DiscoveredRoleActions discoverActions(Class<?> roleClass)
      Discovers all actions from a Role class. Results are cached by role class.

      Thread-safe: Uses computeIfAbsent to ensure atomic cache operations and prevent duplicate reflection work across concurrent threads.

      Parameters:
      roleClass - the role class
      Returns:
      role metadata with all discovered actions
    • clearCache

      public static void clearCache(Class<?> roleClass)
      Clears the cache for a specific role class. Useful for testing or dynamic reloading.
      Parameters:
      roleClass - the role class to clear from cache
    • clearAllCache

      public static void clearAllCache()
      Clears the entire cache. Useful for testing.
    • getCacheSize

      public static int getCacheSize()
      Gets the current cache size.
      Returns:
      number of cached role classes
    • isCached

      public static boolean isCached(Class<?> roleClass)
      Checks if a role class is cached.
      Parameters:
      roleClass - the role class to check
      Returns:
      true if cached