Record Class UsageLimitWarning
java.lang.Object
java.lang.Record
co.ankatech.ankasecure.sdk.model.warning.UsageLimitWarning
- Record Components:
invocationsRemaining- number of operations remaining before limit (must be positive)
- All Implemented Interfaces:
CryptoWarning
Warning indicating that a cryptographic key is approaching its usage limit.
Severity automatically escalates based on remaining operations, enabling applications to implement proactive key rotation strategies before hitting hard limits.
Severity escalation thresholds:
- CRITICAL - 100 or fewer operations (rotate immediately)
- WARNING - 101-500 operations (plan rotation soon)
- NOTICE - 501-1000 operations (monitor and plan)
- INFO - More than 1000 operations (awareness only)
Example - Operator rotation alert:
EncryptResult result = sdk.encrypt("high-volume-key", data);
for (CryptoWarning w : result.getWarnings()) {
if (w instanceof UsageLimitWarning ulw) {
if (ulw.invocationsRemaining() <= 50) {
// Rotation is a control-plane operation — alert the operator to
// rotate the key via ankasecure-cli-admin before the hard limit.
logger.warn("Key {} near usage limit — rotate via ankasecure-cli-admin",
result.getKeyRequested());
} else if (ulw.severity() == WarningSeverity.WARNING) {
logger.warn("{} - {}", ulw.message(), ulw.recommendedAction());
}
}
}
Example - Monitoring dashboard integration:
switch (warning) {
case UsageLimitWarning ulw when ulw.invocationsRemaining() <= 100 ->
metrics.gauge("crypto.key.usage_remaining", ulw.invocationsRemaining());
case UsageLimitWarning ulw ->
logger.debug("Usage OK: {} operations remaining", ulw.invocationsRemaining());
}
- Since:
- 3.0.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUsageLimitWarning(int invocationsRemaining) Creates an instance of aUsageLimitWarningrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intReturns the value of theinvocationsRemainingrecord component.message()Returns a human-readable warning message.Returns the recommended action to address this warning.severity()Returns the severity level of this warning.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
UsageLimitWarning
public UsageLimitWarning(int invocationsRemaining) Creates an instance of aUsageLimitWarningrecord class.- Parameters:
invocationsRemaining- the value for theinvocationsRemainingrecord component
-
-
Method Details
-
severity
Description copied from interface:CryptoWarningReturns the severity level of this warning.- Specified by:
severityin interfaceCryptoWarning- Returns:
- warning severity (INFO, NOTICE, WARNING, or CRITICAL)
-
message
Description copied from interface:CryptoWarningReturns a human-readable warning message.- Specified by:
messagein interfaceCryptoWarning- Returns:
- descriptive message
-
recommendedAction
Description copied from interface:CryptoWarningReturns the recommended action to address this warning.- Specified by:
recommendedActionin interfaceCryptoWarning- Returns:
- actionable guidance for the user
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
invocationsRemaining
public int invocationsRemaining()Returns the value of theinvocationsRemainingrecord component.- Returns:
- the value of the
invocationsRemainingrecord component
-