Class Locker
- All Implemented Interfaces:
FrankElement, HasApplicationContext, HasName, HasPhysicalDestination, HasTransactionAttribute, IConfigurable, IScopeProvider, NameAware, TransactionAware, ConfigurableLifecycle, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
scheduler jobs, the Pipeline 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.
This ensures that only one instance of a job is executed at the same time, even if the job is present on multiple nodes in a cluster. A lock requires an objectId, which is used to identify the lock. There are two types of locks: temporary and permanent. A temporary lock is automatically released after the job has completed, a permanent lock is not released. If a dateFormatSuffix is specified, it is added to the objectId. This allows for permanent locks to be executed once per day, week, month or year.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class JdbcFacade
logFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacquire()@Nullable Stringacquire(MessageKeeper messageKeeper) Obtain the lock.voidConfigure this component.getLockerInfo(String objectIdWithSuffix) protected StringvoidvoidsetDateFormatSuffix(String dateFormatSuffix) Format for date which is added afterobjectid(e.g. yyyyMMdd to be sure the job is executed only once a day)voidsetFirstDelay(int firstDelay) The time in ms to wait before the first attempt to acquire a lock is madevoidsetIgnoreTableNotExist(boolean b) Deprecated.voidsetLockWaitTimeout(int i) If > 0: The time in s to wait before the INSERT statement to obtain the lock is canceled.voidsetNumRetries(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 unlimitedvoidsetObjectId(String objectId) Identifier for this lockvoidsetRetention(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 processvoidsetRetentionTimeUnit(TimeUnit retentionTimeUnit) The unit of time for the retention-time.voidsetRetryDelay(int retryDelay) The time in ms to wait before another attempt to acquire a lock is madevoidsetType(Locker.LockType type) Type for this lock: P(ermanent) or T(emporary).toString()Methods inherited from class JdbcFacade
convertQuery, getConnection, getConnectionWithTimeout, getDatasource, getDatasourceName, getDbmsSupport, getPassword, getPhysicalDestinationName, isRunning, setAuthAlias, setBlobCharset, setBlobsCompressed, setBlobSmartGet, setDatasourceName, setDbmsSupportFactory, setName, setPassword, setSqlDialect, setUsername, start, stop, withConnection, withConnectionMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContextMethods inherited from interface ConfigurableLifecycle
getPhase, isAutoStartup, isConfiguredMethods inherited from interface FrankElement
addConfigWarningMethods inherited from interface HasApplicationContext
getApplicationContext, getConfigurationClassLoaderMethods inherited from interface HasTransactionAttribute
getTransactionAttribute, getTransactionTimeout, getTxDef, setTransactionAttribute, setTransactionTimeoutMethods inherited from interface org.springframework.context.SmartLifecycle
isPauseable, stop
-
Constructor Details
-
Locker
public Locker()
-
-
Method Details
-
configure
Description copied from interface:IConfigurableConfigure this component.configure()is called once at startup of the framework in the configure method of the owner of thisIConfigurable. Purpose of this method is to check whether the static configuration of the object is correct. As much as possible class-instantiating should take place in theconfigure(), to improve performance.In the case of a container, this will propagate the configure signal to all components that apply.
- Specified by:
configurein interfaceIConfigurable- Overrides:
configurein classJdbcFacade- Throws:
ConfigurationException- in case it was not able to configure the component.
-
acquire
-
acquire
public @Nullable 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. -
release
- Throws:
JdbcExceptionSQLException
-
getLockerInfo
-
getLogPrefix
- Overrides:
getLogPrefixin classJdbcFacade
-
toString
-
setObjectId
Identifier for this lock -
setType
Type for this lock: P(ermanent) or T(emporary). A temporary lock is released after the job has completed- Default value
- T
-
setDateFormatSuffix
Format for date which is added afterobjectid(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)
-
setRetentionTimeUnit
-
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
@Deprecated @ConfigurationWarning("The IBISLOCK table should always exist.") public void setIgnoreTableNotExist(boolean b) Deprecated.If settrueand the IBISLOCK table does not exist in the database, the process continues as if the lock was obtained
-