java.lang.Object
org.miaixz.bus.limiter.metric.ResourceManager
Manages resources and their associated limiting protections for a specific user or context. This class tracks the
state of various resources, applying
Limiting rules to control access and prevent overload.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds a resource key to the set of protected methods.static booleanChecks if a given resource key is currently registered as a protected method.booleanAttempts to gain entry to a resource, applying the specified limiting rules.booleanisClear()Checks if all managed resources within thisResourceManagerare clear (i.e., their protection has expired and they have been removed).
-
Constructor Details
-
ResourceManager
public ResourceManager()
-
-
Method Details
-
contain
Checks if a given resource key is currently registered as a protected method.- Parameters:
resourceKey- The unique identifier of the resource.- Returns:
trueif the resource is protected,falseotherwise.
-
add
Adds a resource key to the set of protected methods. This marks the resource as being under some form of limiting protection.- Parameters:
resourceKey- The unique identifier of the resource to add.
-
entry
Attempts to gain entry to a resource, applying the specified limiting rules. If the resource is not yet managed, a newResourceManager.Protectioninstance is created. It checks for expiration and remaining allowance before granting access.- Parameters:
resourceKey- The unique identifier of the resource to access.limiting- TheLimitingannotation defining the rules for this resource.- Returns:
trueif access is allowed,falseif access is denied due to limiting.- Throws:
IllegalStateException- if the state of the protection is invalid (though current implementation does not explicitly throw this).
-
isClear
public boolean isClear()Checks if all managed resources within thisResourceManagerare clear (i.e., their protection has expired and they have been removed). This method iterates through the managed resources and removes expired ones.- Returns:
trueif all resources are clear and the map is empty,falseotherwise.
-