Package com.axelor.db

Class ClaimLease

java.lang.Object
com.axelor.db.ClaimLease

public final class ClaimLease extends Object
The three columns that say a row is being worked on, and by whom.

A row claimed for work carries owner, claimToken and claimedAt: who holds it, which claim this is, and since when. The last is what makes the claim a lease rather than a flag -- a node that dies holding a row does not take the work with it, because the row can be told from its timestamp to have been abandoned and handed to somebody else.

Only the columns live here, not the policy. What predicate wins the row, what status it moves through, how long a lease may run and what happens when one expires all differ per table and belong with the table's own code. What must not differ is the shape, so a table that grows a lease copies a name rather than a convention.

The maps are meant to be handed to GuardedUpdate.setAll(java.util.Map<java.lang.String, java.lang.Object>) alongside whatever else the caller is writing -- the claim and the status change are one statement, or they are not atomic.

  • Field Details

  • Method Details

    • taken

      public static Map<String,Object> taken(String owner)
      Take the row for owner, stamped now, under a claim of its own.
    • renewed

      public static Map<String,Object> renewed()
      Say the holder is still alive, without changing whose claim it is.

      A lease measured from when the row was claimed expires on work that simply takes longer than the lease -- and the row is then handed to somebody else while the first holder is still going. Renewing moves the clock forward so the lease measures liveness rather than duration.

    • released

      public static Map<String,Object> released()
      Let the row go, so the next caller to try may have it.
    • leaseSeconds

      public static long leaseSeconds(Duration lease)
      The lease OUTLIVED measures against, in seconds.

      Measured from when the row was claimed, never from when the work became due: a row claimed a moment ago but overdue by a day -- a backlog after downtime -- is being worked on, not abandoned, and reaping it would take it away from the node that holds it.