org.terracotta.locking
Interface LockStrategy<K>

Type Parameters:
K - supported key type
All Superinterfaces:
GenericLockStrategy<String,K>
All Known Implementing Classes:
BasicLockStrategy, HashcodeLockStrategy, NullLockStrategy, OneToOneLockStrategy

public interface LockStrategy<K>
extends GenericLockStrategy<String,K>

Implementations of LockStrategy can be supplied to implement custom map locking strategies.

Potential implementors are strongly advised to consider subclassing BasicLockStrategy instead of directly implementing this class.


Method Summary
 void beginLock(String lockID, int type)
          Called to acquire a lock on the given lockId at the given level.
 void commitLock(String lockID, int type)
          Called to release a lock on the given lockId held at the given level.
 String generateLockIdForKey(String instanceQualifier, K key)
          Generate the lock identifier to be used when performing operations for the given key.
 void pinLock(String lockID)
          Called to indicate that the associated lock might be required frequently.
 boolean tryBeginLock(String lockID, int type, long nanos)
          Called to attempt to acquire a lock on the given lockId at the given level.
 void unpinLock(String lockID)
          Called to indicate that the associated lock is no longer required frequently.
 

Method Detail

generateLockIdForKey

String generateLockIdForKey(String instanceQualifier,
                            K key)
Generate the lock identifier to be used when performing operations for the given key.

To prevent inter-map lock collisions the instanceQualifier provided by the caller should be used to form the key.

Specified by:
generateLockIdForKey in interface GenericLockStrategy<String,K>
Parameters:
instanceQualifier - A unique identifier for the map being operated on.
key - key to be locked
Returns:
lock identifier

beginLock

void beginLock(String lockID,
               int type)
Called to acquire a lock on the given lockId at the given level.

Specified by:
beginLock in interface GenericLockStrategy<String,K>
Parameters:
lockID - lock to lock
type - hold type to acquire

pinLock

void pinLock(String lockID)
Called to indicate that the associated lock might be required frequently.

This call can be used to help guide resource allocation and collection.

Specified by:
pinLock in interface GenericLockStrategy<String,K>
Parameters:
lockId - lock to `pin'

unpinLock

void unpinLock(String lockID)
Called to indicate that the associated lock is no longer required frequently.

This call can be used to help guide resource allocation and collection.

Specified by:
unpinLock in interface GenericLockStrategy<String,K>
Parameters:
lock - lock to `unpin'

commitLock

void commitLock(String lockID,
                int type)
Called to release a lock on the given lockId held at the given level.

Specified by:
commitLock in interface GenericLockStrategy<String,K>
Parameters:
lockID - lock to unlock
type - hold type to release

tryBeginLock

boolean tryBeginLock(String lockID,
                     int type,
                     long nanos)
                     throws InterruptedException
Called to attempt to acquire a lock on the given lockId at the given level.

Specified by:
tryBeginLock in interface GenericLockStrategy<String,K>
Parameters:
lockID - lock to lock
type - hold type to acquire
time - to wait for lock in nanoseconds
Throws:
InterruptedException


Copyright © 2015 Terracotta, Inc.. All Rights Reserved.