in src/main/java/com/google/gcs/sdrs/dao/impl/LockDaoImpl.java [71:93]
public DistributedLock obtainLock(Session lockSession, int timeout, String lockId) {
if (lockSession == null || lockId == null) {
return null;
}
DistributedLock distributedLock = null;
try {
lockSession.beginTransaction();
distributedLock =
lockSession.get(
DistributedLock.class,
lockId,
new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(timeout));
distributedLock.setLockToken(generateUniqueToken(Thread.currentThread().getName()));
distributedLock.setCreatedAt(new Timestamp(System.currentTimeMillis()));
} catch (PessimisticLockException e) {
logger.info("Lock wait timeout exceeded.", e);
} catch (Exception e) {
logger.info("Failed to acquire lock.", e);
}
return distributedLock;
}