java.lang.Object
fr.paris.lutece.plugins.forms.business.form.lock.LockDAO
All Implemented Interfaces:
ILockDAO

@ApplicationScoped public class LockDAO extends Object implements ILockDAO
JDBC-escape {fn TIMESTAMPADD(SQL_TSI_SECOND, ?, CURRENT_TIMESTAMP)} is portable across HSQLDB, MySQL, PostgreSQL and Oracle; all timestamp comparisons use the DB clock so JVM clock skew between cluster members cannot steal a still-valid lock or extend a stale one beyond its real TTL.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    acquire(String indexName, String instanceName, String uuid, long ttlSeconds, fr.paris.lutece.portal.service.plugin.Plugin plugin)
    Try to acquire the row for indexName.
    boolean
    refresh(String uuid, long ttlSeconds, fr.paris.lutece.portal.service.plugin.Plugin plugin)
    Extend the expiration of the row owned by uuid, but ONLY if it still belongs to us (row not stolen after TTL expiration).
    void
    release(String uuid, fr.paris.lutece.portal.service.plugin.Plugin plugin)
    Release the row owned by uuid.
    int
    releaseByInstance(String instanceName, fr.paris.lutece.portal.service.plugin.Plugin plugin)
    Release every row currently owned by the given instance.

    Methods inherited from class java.lang.Object

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

    • LockDAO

      public LockDAO()
  • Method Details

    • acquire

      public boolean acquire(String indexName, String instanceName, String uuid, long ttlSeconds, fr.paris.lutece.portal.service.plugin.Plugin plugin)
      Description copied from interface: ILockDAO
      Try to acquire the row for indexName. Succeeds if the row is currently unlocked or if its expired_date is in the past (reclaim after crash).
      Specified by:
      acquire in interface ILockDAO
      Parameters:
      indexName - lock key
      instanceName - runtime-unique identifier of THIS JVM (see FormsInstanceId)
      uuid - handle tying the caller to the row, used by ILockDAO.refresh(java.lang.String, long, fr.paris.lutece.portal.service.plugin.Plugin)/ILockDAO.release(java.lang.String, fr.paris.lutece.portal.service.plugin.Plugin)
      ttlSeconds - how long the lock stays valid from now, in seconds
      plugin - plugin handle for the DB pool
      Returns:
      true if the row was taken, false if another instance already holds it
    • release

      public void release(String uuid, fr.paris.lutece.portal.service.plugin.Plugin plugin)
      Description copied from interface: ILockDAO
      Release the row owned by uuid. No-op if the handle is unknown.
      Specified by:
      release in interface ILockDAO
    • refresh

      public boolean refresh(String uuid, long ttlSeconds, fr.paris.lutece.portal.service.plugin.Plugin plugin)
      Description copied from interface: ILockDAO
      Extend the expiration of the row owned by uuid, but ONLY if it still belongs to us (row not stolen after TTL expiration). Returns false if the lock has been lost — the caller must abort its critical section.
      Specified by:
      refresh in interface ILockDAO
      Returns:
      true if still ours and extended, false if lost
    • releaseByInstance

      public int releaseByInstance(String instanceName, fr.paris.lutece.portal.service.plugin.Plugin plugin)
      Description copied from interface: ILockDAO
      Release every row currently owned by the given instance. Safe in cluster: rows owned by other instances are never touched.
      Specified by:
      releaseByInstance in interface ILockDAO
      Returns:
      the number of rows released