private <T> T callWithTimeLimit(Callable<T> callable, LockRequestSpecification specification) throws InterruptedException { try { return timeLimiter.callWithTimeout(callable, blockingTimeLimitMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { // In this case, the thread was interrupted for some other reason, perhaps because we lost leadership. log.info("Lock service was interrupted when servicing {} for client \"{}\"; request was {}", SafeArg.of("method", specification.method()), SafeArg.of("client", specification.client()), UnsafeArg.of("lockRequest", specification.lockRequest()), e); throw e; } catch (TimeoutException e) { // This is the legitimate timeout case we're trying to catch. throw logAndHandleTimeout(specification); } catch (Exception e) { // We don't know, and would prefer not to throw checked exceptions apart from InterruptedException. throw Throwables.propagate(e); } }
private <T> T callWithTimeLimit(Callable<T> callable, LockRequestSpecification specification) throws InterruptedException { try { return timeLimiter.callWithTimeout(callable, blockingTimeLimitMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { // In this case, the thread was interrupted for some other reason, perhaps because we lost leadership. log.info("Lock service was interrupted when servicing {} for client \"{}\"; request was {}", SafeArg.of("method", specification.method()), SafeArg.of("client", specification.client()), UnsafeArg.of("lockRequest", specification.lockRequest()), e); throw e; } catch (TimeoutException e) { // This is the legitimate timeout case we're trying to catch. throw logAndHandleTimeout(specification); } catch (Exception e) { // We don't know, and would prefer not to throw checked exceptions apart from InterruptedException. throw Throwables.propagate(e); } }
private BlockingTimeoutException logAndHandleTimeout(LockRequestSpecification specification) { final String logMessage = "Lock service timed out after {} milliseconds" + " when servicing {} for client \"{}\""; log.info(logMessage, SafeArg.of("timeoutDurationMillis", blockingTimeLimitMillis), SafeArg.of("method", specification.method()), SafeArg.of("client", specification.client()), UnsafeArg.of("lockRequest", specification.lockRequest())); String errorMessage = String.format( logMessage.replace("{}", "%s"), blockingTimeLimitMillis, specification.method(), specification.client()); return new BlockingTimeoutException(errorMessage); }
private BlockingTimeoutException logAndHandleTimeout(LockRequestSpecification specification) { final String logMessage = "Lock service timed out after {} milliseconds" + " when servicing {} for client \"{}\""; log.info(logMessage, SafeArg.of("timeoutDurationMillis", blockingTimeLimitMillis), SafeArg.of("method", specification.method()), SafeArg.of("client", specification.client()), UnsafeArg.of("lockRequest", specification.lockRequest())); String errorMessage = String.format( logMessage.replace("{}", "%s"), blockingTimeLimitMillis, specification.method(), specification.client()); return new BlockingTimeoutException(errorMessage); }