Package org.frankframework.util
Class Locker
java.lang.Object
org.frankframework.jdbc.JdbcFacade
org.frankframework.util.Locker
- All Implemented Interfaces:
FrankElement,HasApplicationContext,HasName,HasPhysicalDestination,HasTransactionAttribute,IConfigurable,IScopeProvider,IXAEnabled,NameAware,ConfigurableLifecycle,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.frankframework.jdbc.JdbcFacade
logFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacquire()acquire(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) If settrueand the IBISLOCK table does not exist in the database, the process continues as if the lock was obtainedvoidsetLockWaitTimeout(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 org.frankframework.jdbc.JdbcFacade
getConnection, getConnectionWithTimeout, getDatasource, getDatasourceName, getDbmsSupport, getPassword, getPhysicalDestinationName, isConnectionsArePooled, isRunning, isTransacted, setAuthAlias, setConnectionsArePooled, setDatasourceName, setDbmsSupportFactory, setName, setPassword, setTransacted, setUsername, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContextMethods inherited from interface org.frankframework.lifecycle.ConfigurableLifecycle
getPhase, isAutoStartup, isConfiguredMethods inherited from interface org.frankframework.core.FrankElement
addConfigWarningMethods inherited from interface org.frankframework.core.HasApplicationContext
getApplicationContext, getConfigurationClassLoaderMethods inherited from interface org.frankframework.core.HasTransactionAttribute
getTransactionAttribute, getTransactionTimeout, getTxDef, setTransactionAttribute, setTransactionTimeoutMethods inherited from interface org.springframework.context.SmartLifecycle
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 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
The unit of time for the retention-time. Possible values: SECONDS, MINUTES, HOURS, DAYS, WEEKS, MONTHS and YEARS. SeeTimeUnit.- Default value
- DAYS (type=P), 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 settrueand the IBISLOCK table does not exist in the database, the process continues as if the lock was obtained
-