Interface PolicyRegistry

All Known Implementing Classes:
InMemoryPolicyRegistry

@ExperimentalJSentinelApi public interface PolicyRegistry
Lookup + evaluation SPI for named policies.

Discovered via java.util.ServiceLoader; consuming applications register a default implementation in META-INF/services/com.svenruppert.jsentinel.policy.spi.PolicyRegistry. If no implementation is registered, the JSentinelServiceResolver supplies an in-memory default.

Implementations should be thread-safe: registration typically happens at startup, evaluation runs on every protected access.

  • Method Details

    • register

      void register(Policy policy)
      Registers a policy. Implementations decide whether duplicate names replace or reject the existing entry — see the implementation's Javadoc.
      Parameters:
      policy - policy; must not be null
    • find

      Optional<Policy> find(String name)
      Looks up a previously registered policy by name.
      Parameters:
      name - policy name
      Returns:
      policy, if present
    • evaluate

      PolicyDecision evaluate(String name, PolicyContext context)
      Evaluates the policy with the given name against the context.

      If no policy is registered for name, implementations return Denied("unknown policy: <name>") rather than throwing — this matches the fail-closed default of the rest of the framework and lets adapters fall through to a standard Forbidden response without special-casing missing policies.

      Parameters:
      name - policy name
      context - policy context
      Returns:
      decision