public V execute(final LockService lock, final RunnableFuture<V> task) { try { lock.lock(); task.run(); return task.get(); } catch (final Exception e) { throw new RuntimeException(e); } finally { lock.unlock(); } }
private long getLeaseTime(long leaseTime) { long maxLeaseTimeInMillis = lockService.getMaxLeaseTimeInMillis(); if (leaseTime > maxLeaseTimeInMillis) { throw new IllegalArgumentException( "Max allowed lease time: " + maxLeaseTimeInMillis + "ms. " + "Given lease time: " + leaseTime + "ms."); } if (leaseTime < 0) { leaseTime = maxLeaseTimeInMillis; } return leaseTime; }