public class JobLockServiceImpl extends Object implements JobLockService
JobLockService.JobLockRefreshCallback
Constructor and Description |
---|
JobLockServiceImpl() |
Modifier and Type | Method and Description |
---|---|
String |
getLock(org.alfresco.service.namespace.QName lockQName,
long timeToLive)
Take a manually-managed lock.
|
String |
getLock(org.alfresco.service.namespace.QName lockQName,
long timeToLive,
JobLockService.JobLockRefreshCallback callback)
Take a manually-managed lock and provide a callback to refresh it periodically.
|
String |
getLock(org.alfresco.service.namespace.QName lockQName,
long timeToLive,
long retryWait,
int retryCount)
Take a manually-managed lock.
|
void |
getTransactionalLock(org.alfresco.service.namespace.QName lockQName,
long timeToLive)
Take a transactionally-managed lock.
|
void |
getTransactionalLock(org.alfresco.service.namespace.QName lockQName,
long timeToLive,
long retryWait,
int retryCount)
Take a transactionally-managed lock.
|
void |
refreshLock(String lockToken,
org.alfresco.service.namespace.QName lockQName,
long timeToLive)
Refresh the lock using a valid lock token.
|
void |
refreshLock(String lockToken,
org.alfresco.service.namespace.QName lockQName,
long timeToLive,
JobLockService.JobLockRefreshCallback callback)
Provide a callback to refresh a lock using a valid lock token, pushing responsibility
for regular lock refreshing onto the service implementation code.
|
void |
releaseLock(String lockToken,
org.alfresco.service.namespace.QName lockQName)
Release the lock using a valid lock token.
|
boolean |
releaseLockVerify(String lockToken,
org.alfresco.service.namespace.QName lockQName)
Release the lock using a valid lock token.
|
void |
setDefaultRetryCount(int defaultRetryCount)
Set the maximum number of attempts to make at getting a lock
|
void |
setDefaultRetryWait(long defaultRetryWait)
Set the default time to wait between attempts to acquire a lock
|
void |
setLockDAO(LockDAO lockDAO)
Set the lock DAO
|
void |
setRetryingTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
Set the helper that will handle low-level concurrency conditions i.e.
|
void |
shutdown()
Lifecycle method.
|
public void shutdown()
This is mostly used to tell the thread pool to shut itself down so as to allow the JVM to terminate.
public void setLockDAO(LockDAO lockDAO)
public void setRetryingTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
public void setDefaultRetryCount(int defaultRetryCount)
defaultRetryCount
- the number of attemptspublic void setDefaultRetryWait(long defaultRetryWait)
defaultRetryWait
- the wait time in millisecondspublic void getTransactionalLock(org.alfresco.service.namespace.QName lockQName, long timeToLive)
The following rules apply to taking and releasing locks:
- Expired locks can be taken by any process
- Lock expiration does not prevent a lock from being refreshed or released
- Only locks that were manipulated using another token will cause failure
The locks are automatically released when the transaction is terminated.
Any failure to acquire the lock (after retries), refresh the lock or subsequently release the owned locks will invalidate the transaction and cause rollback.
getTransactionalLock
in interface JobLockService
lockQName
- the name of the lock to acquiretimeToLive
- the time (in milliseconds) for the lock to remain valid.
This value must not be larger than either the anticipated
operation time or a server startup time. Typically, it should be
a few seconds.public void getTransactionalLock(org.alfresco.service.namespace.QName lockQName, long timeToLive, long retryWait, int retryCount)
The following rules apply to taking and releasing locks:
- Expired locks can be taken by any process
- Lock expiration does not prevent a lock from being refreshed or released
- Only locks that were manipulated using another token will cause failure
The locks are automatically released when the transaction is terminated.
Any failure to acquire the lock (after retries), refresh the lock or subsequently release the owned locks will invalidate the transaction and cause rollback.
If the lock cannot be immediately acquired, the process will wait and retry. Note that second and subsequent attempts to get the lock during a transaction cannot make use of retrying; the lock is actually being refreshed and will therefore never become valid if it doesn't refresh directly.
getTransactionalLock
in interface JobLockService
lockQName
- the name of the lock to acquiretimeToLive
- the time (in milliseconds) for the lock to remain valid.
This value must not be larger than either the anticipated
operation time or a server startup time. Typically, it should be
a few seconds.retryWait
- the time (in milliseconds) to wait before trying againretryCount
- the maximum number of times to attempt the lock acquisitionpublic String getLock(org.alfresco.service.namespace.QName lockQName, long timeToLive)
No lock management is provided: the lock must be released manually or will only become available by expiry. No deadlock management is provided, either.
getLock
in interface JobLockService
lockQName
- the name of the lock to acquiretimeToLive
- the time (in milliseconds) for the lock to remain valid.
This value must not be larger than either the anticipated
operation time or a server startup time. Typically, it should be
a few seconds.getLock(QName, long, long, int)
public String getLock(org.alfresco.service.namespace.QName lockQName, long timeToLive, long retryWait, int retryCount)
No lock management is provided: the lock must be released manually or will only become available by expiry. No deadlock management is provided, either.
If the lock cannot be immediately acquired, the process will wait and retry.
getLock
in interface JobLockService
lockQName
- the name of the lock to acquiretimeToLive
- the time (in milliseconds) for the lock to remain valid.
This value must not be larger than either the anticipated
operation time or a server startup time. Typically, it should be
a few seconds.retryWait
- the time (in milliseconds) to wait before trying againretryCount
- the maximum number of times to attempt the lock acquisitionpublic void refreshLock(String lockToken, org.alfresco.service.namespace.QName lockQName, long timeToLive)
refreshLock
in interface JobLockService
lockQName
- the name of the previously-acquired locktimeToLive
- the time (in milliseconds) for the lock to remain validLockAcquisitionException
- on failurepublic String getLock(org.alfresco.service.namespace.QName lockQName, long timeToLive, JobLockService.JobLockRefreshCallback callback)
JobLockService.getLock(QName,long)
and JobLockService.refreshLock(String,QName,long,JobLockRefreshCallback)
.getLock
in interface JobLockService
lockQName
- the name of the lock to acquiretimeToLive
- the time (in milliseconds) for the lock to remain valid.
This value must not be larger than either the anticipated
operation time or a server startup time. Typically, it should be
a few seconds.callback
- the object that will be called at intervals of timeToLive/2 (about)public void refreshLock(String lockToken, org.alfresco.service.namespace.QName lockQName, long timeToLive, JobLockService.JobLockRefreshCallback callback)
refreshLock
in interface JobLockService
lockToken
- the lock token returned when the lock was acquiredlockQName
- the name of the previously-acquired locktimeToLive
- the time (in milliseconds) for the lock to remain validcallback
- the object that will be called at intervals of timeToLive/2 (about)public void releaseLock(String lockToken, org.alfresco.service.namespace.QName lockQName)
releaseLock
in interface JobLockService
lockToken
- the lock token returned when the lock was acquiredlockQName
- the name of the previously-acquired lockpublic boolean releaseLockVerify(String lockToken, org.alfresco.service.namespace.QName lockQName)
releaseLockVerify
in interface JobLockService
lockToken
- the lock token returned when the lock was acquiredlockQName
- the name of the previously-acquired lockCopyright © 2005–2017 Alfresco Software. All rights reserved.