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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionevaluate(String name, PolicyContext context) Evaluates the policy with the given name against the context.Looks up a previously registered policy by name.voidRegisters a policy.
-
Constructor Details
-
InMemoryPolicyRegistry
public InMemoryPolicyRegistry()Creates an empty registry.
-
-
Method Details
-
register
Description copied from interface:PolicyRegistryRegisters a policy. Implementations decide whether duplicate names replace or reject the existing entry — see the implementation's Javadoc.- Specified by:
registerin interfacePolicyRegistry- Parameters:
policy- policy; must not benull
-
find
Description copied from interface:PolicyRegistryLooks up a previously registered policy by name.- Specified by:
findin interfacePolicyRegistry- Parameters:
name- policy name- Returns:
- policy, if present
-
evaluate
Description copied from interface:PolicyRegistryEvaluates the policy with the given name against the context.If no policy is registered for
name, implementations returnDenied("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 standardForbiddenresponse without special-casing missing policies.- Specified by:
evaluatein interfacePolicyRegistry- Parameters:
name- policy namecontext- policy context- Returns:
- decision
-