Class DispatchLeaseManager

java.lang.Object
org.opencastproject.serviceregistry.impl.DispatchLeaseManager

public class DispatchLeaseManager extends Object
Elects exactly one job dispatcher across a cluster of candidate nodes by acquiring and renewing a lease stored in a single, shared database row. Only the node currently holding the lease should perform job dispatching; all other candidate nodes must sit idle until they acquire it, e.g. after the current holder stops renewing it.

Acquisition and renewal are both done with a single, portable JPQL bulk update whose WHERE clause compares the stored expiry against the database's own CURRENT_TIMESTAMP, not the calling node's local clock. This makes the race between competing nodes safe by relying purely on the database engine's row-level locking during the update, without needing vendor-specific advisory locks, and makes every competing node judge lease freshness against one shared clock rather than against each other's local clocks.

  • Constructor Summary

    Constructors
    Constructor
    Description
    DispatchLeaseManager(org.opencastproject.db.DBSession db, String owner, long leaseTimeoutSeconds)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Release the lease if this node currently holds it, allowing another candidate node to take over immediately instead of waiting for the lease to expire.
    boolean
    Attempt to acquire the dispatch lease, or renew it if this node already holds it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DispatchLeaseManager

      public DispatchLeaseManager(org.opencastproject.db.DBSession db, String owner, long leaseTimeoutSeconds)
  • Method Details

    • tryAcquireOrRenew

      public boolean tryAcquireOrRenew()
      Attempt to acquire the dispatch lease, or renew it if this node already holds it.
      Returns:
      true if this node is (now, or still) the elected dispatcher, false otherwise
    • release

      public void release()
      Release the lease if this node currently holds it, allowing another candidate node to take over immediately instead of waiting for the lease to expire. Safe to call even if this node isn't the current leader.