Package org.frankframework.util
Class Locker
java.lang.Object
org.frankframework.jndi.JndiBase
org.frankframework.jdbc.JdbcFacade
org.frankframework.util.Locker
- All Implemented Interfaces:
HasPhysicalDestination
,HasTransactionAttribute
,IConfigurable
,IConfigurationAware
,INamedObject
,IScopeProvider
,IXAEnabled
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
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
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionacquire()
acquire
(MessageKeeper messageKeeper) Obtain the lock.void
int
getLockerInfo
(String objectIdWithSuffix) int
protected String
int
int
int
int
org.springframework.transaction.TransactionDefinition
getTxDef()
org.springframework.transaction.PlatformTransactionManager
getType()
boolean
void
void
setDateFormatSuffix
(String dateFormatSuffix) Format for date which is added afterobjectid
(e.g. yyyyMMdd to be sure the job is executed only once a day)void
setFirstDelay
(int firstDelay) The time in ms to wait before the first attempt to acquire a lock is madevoid
setIgnoreTableNotExist
(boolean b) If settrue
and the IBISLOCK table does not exist in the database, the process continues as if the lock was obtainedvoid
setLockWaitTimeout
(int i) If > 0: The time in s to wait before the INSERT statement to obtain the lock is canceled.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 unlimitedvoid
setObjectId
(String objectId) Identifier for this lockvoid
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 processvoid
setRetryDelay
(int retryDelay) The time in ms to wait before another attempt to acquire a lock is madevoid
setTransactionAttribute
(TransactionAttribute transactionAttribute) ThetransactionAttribute
declares transactional behavior of execution.void
setTransactionTimeout
(int transactionTimeout) Timeout (in seconds) of transaction started to process a message.void
setTxManager
(org.springframework.transaction.PlatformTransactionManager txManager) void
setType
(Locker.LockType type) Type for this lock: P(ermanent) or T(emporary).toString()
Methods inherited from class org.frankframework.jdbc.JdbcFacade
getAuthAlias, getConnection, getConnectionWithTimeout, getDatasource, getDataSourceFactory, getDatasourceInfo, getDatasourceName, getDbmsSupport, getDomain, getPassword, getPhysicalDestinationName, getUsername, isConnectionsArePooled, isTransacted, setAuthAlias, setConnectionsArePooled, setDataSourceFactory, setDatasourceName, setDbmsSupportFactory, setJmsRealm, setPassword, setTransacted, setUsername
Methods inherited from class org.frankframework.jndi.JndiBase
getApplicationContext, getAuthentication, getConfigurationClassLoader, getContext, getCredentials, getInitialContextFactoryName, getJmsRealmName, getJndiAuthAlias, getJndiContextPrefix, getJndiEnv, getJndiProperties, getName, getPrincipal, getProviderURL, getSecurityProtocol, getUrlPkgPrefixes, setApplicationContext, setAuthentication, setCredentials, setInitialContextFactoryName, setJndiAuthAlias, setJndiContextPrefix, setJndiProperties, setName, setPrincipal, setProviderURL, setSecurityProtocol, setUrlPkgPrefixes, stop
-
Constructor Details
-
Locker
public Locker()
-
-
Method Details
-
configure
- Specified by:
configure
in interfaceIConfigurable
- Overrides:
configure
in classJdbcFacade
- Throws:
ConfigurationException
-
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:
JdbcException
SQLException
-
getLockerInfo
-
getLogPrefix
- Overrides:
getLogPrefix
in 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)
-
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 settrue
and the IBISLOCK table does not exist in the database, the process continues as if the lock was obtained -
getObjectId
-
getType
-
getDateFormatSuffix
-
getRetention
public int getRetention() -
getNumRetries
public int getNumRetries() -
getFirstDelay
public int getFirstDelay() -
getRetryDelay
public int getRetryDelay() -
isIgnoreTableNotExist
public boolean isIgnoreTableNotExist() -
getTransactionAttribute
- Specified by:
getTransactionAttribute
in interfaceHasTransactionAttribute
-
setTransactionAttribute
Description copied from interface:HasTransactionAttribute
ThetransactionAttribute
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\">transactionAttribute callers Transaction Pipeline excecuted in Transaction <td colspan=\"1\" rowspan=\"2\">Required none T2 T1 T1 <td colspan=\"1\" rowspan=\"2\">RequiresNew none T2 T1 T2 <td colspan=\"1\" rowspan=\"2\">Mandatory none error T1 T1 <td colspan=\"1\" rowspan=\"2\">NotSupported none none T1 none <td colspan=\"1\" rowspan=\"2\">Supports none none T1 T1 <td colspan=\"1\" rowspan=\"2\">Never none none T1 error - Specified by:
setTransactionAttribute
in interfaceHasTransactionAttribute
-
getTransactionTimeout
public int getTransactionTimeout()- Specified by:
getTransactionTimeout
in interfaceHasTransactionAttribute
-
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 interfaceHasTransactionAttribute
-
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 interfaceHasTransactionAttribute
-