org.alfresco.repo.lock
Class JobLockServiceImpl

java.lang.Object
  extended by org.alfresco.repo.lock.JobLockServiceImpl
All Implemented Interfaces:
JobLockService

public class JobLockServiceImpl
extends java.lang.Object
implements JobLockService

Since:
3.2

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.alfresco.repo.lock.JobLockService
JobLockService.JobLockRefreshCallback
 
Constructor Summary
JobLockServiceImpl()
           
 
Method Summary
 java.lang.String getLock(org.alfresco.service.namespace.QName lockQName, long timeToLive)
          Take a manually-managed lock.
 java.lang.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(java.lang.String lockToken, org.alfresco.service.namespace.QName lockQName, long timeToLive)
          Refresh the lock using a valid lock token.
 void refreshLock(java.lang.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(java.lang.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JobLockServiceImpl

public JobLockServiceImpl()
Method Detail

shutdown

public void shutdown()
Lifecycle method. This method should be called when the JobLockService is no longer required allowing proper clean up before disposing of the object.

This is mostly used to tell the thread pool to shut itself down so as to allow the JVM to terminate.


setLockDAO

public void setLockDAO(LockDAO lockDAO)
Set the lock DAO


setRetryingTransactionHelper

public void setRetryingTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
Set the helper that will handle low-level concurrency conditions i.e. that enforces optimistic locking and deals with stale state issues.


setDefaultRetryCount

public void setDefaultRetryCount(int defaultRetryCount)
Set the maximum number of attempts to make at getting a lock

Parameters:
defaultRetryCount - the number of attempts

setDefaultRetryWait

public void setDefaultRetryWait(long defaultRetryWait)
Set the default time to wait between attempts to acquire a lock

Parameters:
defaultRetryWait - the wait time in milliseconds

getTransactionalLock

public void getTransactionalLock(org.alfresco.service.namespace.QName lockQName,
                                 long timeToLive)
Take a transactionally-managed lock. This method can be called repeatedly to both initially acquire the lock as well as to maintain the lock. This method should be called repeatedly during the transaction to ensure that the lock remains refreshed. DO NOT use a long-lived lock to avoid calling this method at intervals; long-lived locks get left behind during server crashes, amongst other things.

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.

Specified by:
getTransactionalLock in interface JobLockService
Parameters:
lockQName - the name of the lock to acquire
timeToLive - 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.

getTransactionalLock

public void getTransactionalLock(org.alfresco.service.namespace.QName lockQName,
                                 long timeToLive,
                                 long retryWait,
                                 int retryCount)
Take a transactionally-managed lock. This method can be called repeatedly to both initially acquire the lock as well as to maintain the lock. This method should be called repeatedly during the transaction to ensure that the lock remains refreshed. DO NOT use a long-lived lock to avoid calling this method at intervals; long-lived locks get left behind during server crashes, amongst other things.

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.

Specified by:
getTransactionalLock in interface JobLockService
Parameters:
lockQName - the name of the lock to acquire
timeToLive - 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 again
retryCount - the maximum number of times to attempt the lock acquisition

getLock

public java.lang.String getLock(org.alfresco.service.namespace.QName lockQName,
                                long timeToLive)
Take a manually-managed lock. The lock current thread or transaction will not be tagged - the returned lock token must be used for further management of the lock.

No lock management is provided: the lock must be released manually or will only become available by expiry. No deadlock management is provided, either.

Specified by:
getLock in interface JobLockService
Parameters:
lockQName - the name of the lock to acquire
timeToLive - 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.
Returns:
Returns the newly-created lock token
See Also:
JobLockServiceImpl.getLock(QName, long, long, int)

getLock

public java.lang.String getLock(org.alfresco.service.namespace.QName lockQName,
                                long timeToLive,
                                long retryWait,
                                int retryCount)
Take a manually-managed lock. The lock current thread or transaction will not be tagged - the returned lock token must be used for further management of the lock.

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.

Specified by:
getLock in interface JobLockService
Parameters:
lockQName - the name of the lock to acquire
timeToLive - 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 again
retryCount - the maximum number of times to attempt the lock acquisition

refreshLock

public void refreshLock(java.lang.String lockToken,
                        org.alfresco.service.namespace.QName lockQName,
                        long timeToLive)
Refresh the lock using a valid lock token.

Specified by:
refreshLock in interface JobLockService
Parameters:
lockToken - the lock token returned when the lock was acquired
lockQName - the name of the previously-acquired lock
timeToLive - the time (in milliseconds) for the lock to remain valid
Throws:
LockAcquisitionException - on failure

refreshLock

public void refreshLock(java.lang.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. This method should only be called once for a given lock token to prevent unnecessary refreshing.

Since the lock is not actually refreshed by this method, there will be no LockAcquisitionException.

The TTL (time to live) will be divided by two and the result used to trigger a timer thread to initiate the callback.

Specified by:
refreshLock in interface JobLockService
Parameters:
lockToken - the lock token returned when the lock was acquired
lockQName - the name of the previously-acquired lock
timeToLive - the time (in milliseconds) for the lock to remain valid
callback - the object that will be called at intervals of timeToLive/2 (about)

releaseLock

public void releaseLock(java.lang.String lockToken,
                        org.alfresco.service.namespace.QName lockQName)
Release the lock using a valid lock token.

Specified by:
releaseLock in interface JobLockService
Parameters:
lockToken - the lock token returned when the lock was acquired
lockQName - the name of the previously-acquired lock


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.