Class Locker

All Implemented Interfaces:
HasPhysicalDestination, HasTransactionAttribute, IConfigurable, IConfigurationAware, INamedObject, IScopeProvider, IXAEnabled, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

@FrankDocGroup(OTHER) public class Locker extends JdbcFacade implements HasTransactionAttribute
Locker of scheduler jobs and pipes. Tries to set a lock (by inserting a record in the database table IbisLock) and only if this is done successfully the job is executed. For an Oracle database the following objects are used:
        CREATE TABLE <schema_owner>.IBISLOCK
        (
        OBJECTID VARCHAR2(100 CHAR),
        TYPE CHAR(1 CHAR),
        HOST VARCHAR2(100 CHAR),
        CREATIONDATE TIMESTAMP(6),
        EXPIRYDATE TIMESTAMP(6)
        CONSTRAINT PK_IBISLOCK PRIMARY KEY (OBJECTID)
        );

        CREATE INDEX <schema_owner>.IX_IBISLOCK ON <schema_owner>.IBISLOCK
        (EXPIRYDATE);

        GRANT DELETE, INSERT, SELECT, UPDATE ON <schema_owner>.IBISLOCK TO <rolename>;
        GRANT SELECT ON SYS.DBA_PENDING_TRANSACTIONS TO <rolename>;

        COMMIT;
  
Author:
Peter Leeuwenburgh
  • Constructor Details

    • Locker

      public Locker()
  • Method Details

    • configure

      public void configure() throws ConfigurationException
      Specified by:
      configure in interface IConfigurable
      Overrides:
      configure in class JdbcFacade
      Throws:
      ConfigurationException
    • acquire

      Throws:
      JdbcException
      SQLException
      InterruptedException
    • acquire

      public String acquire(MessageKeeper messageKeeper) throws JdbcException, SQLException, InterruptedException
      Obtain the lock. If successful, the non-null lockId is returned. If the lock cannot be obtained within the lock-timeout because it is held by another party, null is returned. The lock wait timeout of the database can be overridden by setting lockWaitTimeout. A wait timeout beyond the basic lockWaitTimeout and transactionTimeout can be set using numRetries in combination with retryDelay.
      Throws:
      JdbcException
      SQLException
      InterruptedException
    • release

      public void release(String objectIdWithSuffix) throws JdbcException, SQLException
      Throws:
      JdbcException
      SQLException
    • getLockerInfo

      public String getLockerInfo(String objectIdWithSuffix)
    • getLogPrefix

      protected String getLogPrefix()
      Overrides:
      getLogPrefix in class JdbcFacade
    • toString

      public String toString()
      Overrides:
      toString in class JndiBase
    • setObjectId

      @Mandatory public void setObjectId(String objectId)
      Identifier for this lock
    • setType

      public void setType(Locker.LockType type)
      Type for this lock: P(ermanent) or T(emporary). A temporary lock is released after the job has completed
      Default value
      T
    • setDateFormatSuffix

      public void setDateFormatSuffix(String dateFormatSuffix)
      Format for date which is added after objectid (e.g. yyyyMMdd to be sure the job is executed only once a day)
    • setRetention

      public void setRetention(int retention)
      The time (for type=P in days and for type=T in hours) to keep the record in the database before making it eligible for deletion by a cleanup process
      Default value
      30 days (type=P), 4 hours (type=T)
    • setNumRetries

      public void setNumRetries(int numRetries)
      The number of times an attempt should be made to acquire a lock, after this many times an exception is thrown when no lock could be acquired, when -1 the number of retries is unlimited
      Default value
      0
    • setFirstDelay

      public void setFirstDelay(int firstDelay)
      The time in ms to wait before the first attempt to acquire a lock is made
      Default value
      0
    • setRetryDelay

      public void setRetryDelay(int retryDelay)
      The time in ms to wait before another attempt to acquire a lock is made
      Default value
      10000
    • setLockWaitTimeout

      public void setLockWaitTimeout(int i)
      If > 0: The time in s to wait before the INSERT statement to obtain the lock is canceled. N.B. On Oracle hitting this lockWaitTimeout may cause the error: (SQLRecoverableException) SQLState [08003], errorCode [17008] connection closed
      Default value
      0
    • setIgnoreTableNotExist

      public void setIgnoreTableNotExist(boolean b)
      If set true and the IBISLOCK table does not exist in the database, the process continues as if the lock was obtained
    • getObjectId

      public String getObjectId()
    • getType

      public Locker.LockType getType()
    • getDateFormatSuffix

      public String getDateFormatSuffix()
    • getRetention

      public int getRetention()
    • getNumRetries

      public int getNumRetries()
    • getFirstDelay

      public int getFirstDelay()
    • getRetryDelay

      public int getRetryDelay()
    • isIgnoreTableNotExist

      public boolean isIgnoreTableNotExist()
    • getTransactionAttribute

      public TransactionAttribute getTransactionAttribute()
      Specified by:
      getTransactionAttribute in interface HasTransactionAttribute
    • setTransactionAttribute

      public void setTransactionAttribute(TransactionAttribute transactionAttribute)
      Description copied from interface: HasTransactionAttribute
      The transactionAttribute declares transactional behavior of execution. It applies both to database transactions and XA transactions. The pipeline uses this to start a new transaction or suspend the current one when required. For developers: it is equal to <a href=\"https://docs.oracle.com/javaee/7/tutorial/transactions003.htm\">EJB transaction attribute. Possible values for transactionAttribute: <table border=\"1\"> transactionAttributecallers TransactionPipeline excecuted in Transaction <td colspan=\"1\" rowspan=\"2\">Required noneT2 T1 T1 <td colspan=\"1\" rowspan=\"2\">RequiresNew noneT2 T1 T2 <td colspan=\"1\" rowspan=\"2\">Mandatory noneerror T1 T1 <td colspan=\"1\" rowspan=\"2\">NotSupportednonenone T1 none <td colspan=\"1\" rowspan=\"2\">Supports nonenone T1 T1 <td colspan=\"1\" rowspan=\"2\">Never nonenone T1 error
      Specified by:
      setTransactionAttribute in interface HasTransactionAttribute
    • getTransactionTimeout

      public int getTransactionTimeout()
      Specified by:
      getTransactionTimeout in interface HasTransactionAttribute
    • setTransactionTimeout

      public void setTransactionTimeout(int transactionTimeout)
      Description copied from interface: HasTransactionAttribute
      Timeout (in seconds) of transaction started to process a message.
      Specified by:
      setTransactionTimeout in interface HasTransactionAttribute
    • getLockWaitTimeout

      public int getLockWaitTimeout()
    • getTxManager

      public org.springframework.transaction.PlatformTransactionManager getTxManager()
    • setTxManager

      public void setTxManager(org.springframework.transaction.PlatformTransactionManager txManager)
    • getTxDef

      public org.springframework.transaction.TransactionDefinition getTxDef()
      Specified by:
      getTxDef in interface HasTransactionAttribute