You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the following code stripped form the LockMethodInterceptor to get the retry/timeout functionality with a simple redis lock. It sure would be nice if it was part of the library.
`
private String getLockToken(List keys, String storeId, int retry, long timeOut, long expiration) {
String token = null;
try {
token = constructRetryTemplate(retry, timeOut).execute(context -> {
final String attemptedToken = lock.acquire(keys, storeId, expiration);
if (StringUtils.isEmpty(attemptedToken)) {
throw new LockNotAvailableException(
String.format("Lock not available for keys: %s in store %s", keys, storeId));
}
return attemptedToken;
});
} catch (final Exception e) {
throw new DistributedLockException(String.format("Unable to acquire lock for keys: %s in store %s", keys, storeId), e);
}
return token;
}
private RetryTemplate constructRetryTemplate(int retryPeriodMs, long timeOutMs) {
// how long to sleep between retries
final FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
fixedBackOffPolicy.setBackOffPeriod(retryPeriodMs);
// when to timeout the whole operation
final TimeoutRetryPolicy timeoutRetryPolicy = new TimeoutRetryPolicy();
timeoutRetryPolicy.setTimeout(timeOutMs);
// what exceptions to retry; only LockNotAvailableException, all other exceptions are unexpected and locking should fail
final SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy(Integer.MAX_VALUE, Collections.singletonMap(LockNotAvailableException.class, true));
// combine policies
final CompositeRetryPolicy compositeRetryPolicy = new CompositeRetryPolicy();
compositeRetryPolicy.setPolicies(new RetryPolicy[]{timeoutRetryPolicy, simpleRetryPolicy});
// construct the template
final RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(compositeRetryPolicy);
retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
return retryTemplate;
}
`
The text was updated successfully, but these errors were encountered:
Released a new version which should have what you are looking for. Hopefully, com.github.alturkovic.lock.retry.RetriableLock is what you were looking for. If not, feel free to leave a comment. If it was, please close the issue.
I used the following code stripped form the LockMethodInterceptor to get the retry/timeout functionality with a simple redis lock. It sure would be nice if it was part of the library.
`
private String getLockToken(List keys, String storeId, int retry, long timeOut, long expiration) {
`
The text was updated successfully, but these errors were encountered: