Class InMemoryPolicyRegistry

java.lang.Object
com.svenruppert.jsentinel.policy.impl.InMemoryPolicyRegistry
All Implemented Interfaces:
PolicyRegistry

@ExperimentalJSentinelApi public final class InMemoryPolicyRegistry extends Object implements PolicyRegistry
Thread-safe in-memory PolicyRegistry.

Re-registering a policy with the same name replaces the previous entry. Concurrent reads and registrations are safe because the backing map is a ConcurrentHashMap.

This is the default implementation returned by JSentinelServiceResolver.policyRegistry() when no SPI override is registered.

  • Constructor Details

    • InMemoryPolicyRegistry

      public InMemoryPolicyRegistry()
      Creates an empty registry.
  • Method Details

    • register

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

      public Optional<Policy> find(String name)
      Description copied from interface: PolicyRegistry
      Looks up a previously registered policy by name.
      Specified by:
      find in interface PolicyRegistry
      Parameters:
      name - policy name
      Returns:
      policy, if present
    • evaluate

      public PolicyDecision evaluate(String name, PolicyContext context)
      Description copied from interface: PolicyRegistry
      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.

      Specified by:
      evaluate in interface PolicyRegistry
      Parameters:
      name - policy name
      context - policy context
      Returns:
      decision