Class GuardianState

java.lang.Object
me.ahoo.cosid.machine.GuardianState

public class GuardianState extends Object
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 Details

    • INITIAL

      public static final GuardianState 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

      public static GuardianState success(long guardAt)
      Creates a successful guardian state.
      Parameters:
      guardAt - the timestamp of the successful guarding operation
      Returns:
      a new GuardianState representing success
    • failed

      public static GuardianState failed(long guardAt, Throwable error)
      Creates a failed guardian state.
      Parameters:
      guardAt - the timestamp of the failed guarding operation
      error - the error that caused the failure
      Returns:
      a new GuardianState representing failure