Class Locker

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

    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 Detail

      • Locker

        public Locker()
    • Method Detail

      • 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
      • getLockerInfo

        public String getLockerInfo​(String objectIdWithSuffix)
      • 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()
      • getDateFormatSuffix

        public String getDateFormatSuffix()
      • getRetention

        public int getRetention()
      • getNumRetries

        public int getNumRetries()
      • getFirstDelay

        public int getFirstDelay()
      • getRetryDelay

        public int getRetryDelay()
      • isIgnoreTableNotExist

        public boolean isIgnoreTableNotExist()
      • 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 EJB transaction attribute. Possible values for transactionAttribute:
        transactionAttributecallers TransactionPipeline excecuted in Transaction
        Required noneT2
        T1 T1
        RequiresNew noneT2
        T1 T2
        Mandatory noneerror
        T1 T1
        NotSupportednonenone
        T1 none
        Supports nonenone
        T1 T1
        Never nonenone
        T1 error
        Specified by:
        setTransactionAttribute in interface HasTransactionAttribute
      • getLockWaitTimeout

        public int getLockWaitTimeout()
      • getTxManager

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

        public void setTxManager​(org.springframework.transaction.PlatformTransactionManager txManager)