Package com.teracloud.streams.dl
Interface LockFactory
public interface LockFactory
-
Method Summary
Modifier and TypeMethodDescriptioncreateOrGetLock
(String name) This function can be used to create a new distributed lock with a given lock name or obtain an existing distributed lock in the event that a distributed lock with the given lock name already exists.int
getPidForLock
(String name) Get the Linux process id that currently owns this lock.boolean
removeLock
(Lock lock) This function can be used to remove a given distributed lock id.
-
Method Details
-
createOrGetLock
This function can be used to create a new distributed lock with a given lock name or obtain an existing distributed lock in the event that a distributed lock with the given lock name already exists.LockFactory lf = DistributedLocks.getLockFactory(); Lock myLock = lf.createOrGetLock("Lock_For_Test_Store1");
- Parameters:
name
- an arbitrary string representing the intended lock name.- Returns:
- a
Lock
object. - Throws:
LockFactoryException
- if an error occurs.
-
removeLock
This function can be used to remove a given distributed lock id. For the final function argument, you must provide a mutable variable to receive the DPS error code in the event of a problem in the remove lock operation. Since the whole purpose of distributed locks is to ensure operations are performed safely on shared resources by multiple unrelated application components, don't remove the distributed locks abruptly unless you are very clear about what you are doing. Do it only when you are sure that no one is using the lock at the time of removing it.LockFactory lf = DistributedLocks.getLockFactory(); Lock myLock = lf.createOrGetLock("Lock_For_Test_Store1"); // access shared data // once you are certain the lock is no longer needed, the lock can be removed. lf.removeLock(myLock);
- Parameters:
lock
- the lock to remove- Returns:
- true if the lock was successfully removed.
- Throws:
LockFactoryException
- if an error occurs removing the lock.
-
getPidForLock
Get the Linux process id that currently owns this lock.- Parameters:
name
- the name of the lock- Returns:
- the id of the Linux process that owns this lock, or 0 if no one owns the lock.
- Throws:
LockFactoryException
- if an error occurs
-