Package me.ahoo.cosid.machine
Class GuardianState
java.lang.Object
me.ahoo.cosid.machine.GuardianState
Represents the state of a machine ID guardian operation.
This class encapsulates the result of a guarding attempt for a specific machine ID, including the timestamp of the operation and any error that occurred.
Example usage:
// Successful guard operation
GuardianState successState = GuardianState.success(System.currentTimeMillis());
// Failed guard operation
GuardianState failedState = GuardianState.failed(System.currentTimeMillis(), new RuntimeException("Guard failed"));
if (failedState.isFailed()) {
// Handle failure
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GuardianStateThe initial state representing no guarding operation has been performed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GuardianStateCreates a failed guardian state.booleanisFailed()Checks if the guarding operation failed.static GuardianStatesuccess(long guardAt) Creates a successful guardian state.
-
Field Details
-
INITIAL
The initial state representing no guarding operation has been performed.
-
-
Constructor Details
-
GuardianState
public GuardianState()
-
-
Method Details
-
isFailed
public boolean isFailed()Checks if the guarding operation failed.- Returns:
- true if an error occurred during guarding, false otherwise
-
success
Creates a successful guardian state.- Parameters:
guardAt- the timestamp of the successful guarding operation- Returns:
- a new GuardianState representing success
-
failed
Creates a failed guardian state.- Parameters:
guardAt- the timestamp of the failed guarding operationerror- the error that caused the failure- Returns:
- a new GuardianState representing failure
-