private <T> T performWaitingForAllInvalidation(Callable<T> c, Duration timeout) throws TimeoutException { LongSupplier nanosRemaining = nanosStartingFromNow(timeout); CountDownLatch newLatch = new CountDownLatch(1); while (true) { if (!entity.isConnected()) { throw new IllegalStateException("Cluster tier manager disconnected"); } if (invalidateAllLatch.compareAndSet(null, newLatch)) { break; } else { CountDownLatch existingLatch = invalidateAllLatch.get(); if (existingLatch != null) { awaitOnLatch(existingLatch, nanosRemaining); } } } try { T result = c.call(); awaitOnLatch(newLatch, nanosRemaining); LOGGER.debug("CLIENT: all invalidated on all clients, unblocking call"); return result; } catch (Exception ex) { invalidateAllLatch.set(null); newLatch.countDown(); if (ex instanceof TimeoutException) { throw (TimeoutException)ex; } throw new RuntimeException(ex); } }
private <T> T performWaitingForHashInvalidation(long key, Callable<T> c, Duration timeout) throws TimeoutException { LongSupplier nanosRemaining = nanosStartingFromNow(timeout); CountDownLatch latch = new CountDownLatch(1); while (true) { if (!entity.isConnected()) { throw new IllegalStateException("Cluster tier manager disconnected"); } CountDownLatch countDownLatch = hashInvalidationsInProgress.putIfAbsent(key, latch); if (countDownLatch == null) { break; } awaitOnLatch(countDownLatch, nanosRemaining); } try { T result = c.call(); LOGGER.debug("CLIENT: Waiting for invalidations on key {}", key); awaitOnLatch(latch, nanosRemaining); LOGGER.debug("CLIENT: key {} invalidated on all clients, unblocking call", key); return result; } catch (Exception ex) { hashInvalidationsInProgress.remove(key); latch.countDown(); if (ex instanceof TimeoutException) { throw (TimeoutException)ex; } throw new RuntimeException(ex); } }
private <T> T performWaitingForHashInvalidation(long key, Callable<T> c, Duration timeout) throws TimeoutException { LongSupplier nanosRemaining = nanosStartingFromNow(timeout); CountDownLatch latch = new CountDownLatch(1); while (true) { if (!entity.isConnected()) { throw new IllegalStateException("Cluster tier manager disconnected"); } CountDownLatch countDownLatch = hashInvalidationsInProgress.putIfAbsent(key, latch); if (countDownLatch == null) { break; } awaitOnLatch(countDownLatch, nanosRemaining); } try { T result = c.call(); LOGGER.debug("CLIENT: Waiting for invalidations on key {}", key); awaitOnLatch(latch, nanosRemaining); LOGGER.debug("CLIENT: key {} invalidated on all clients, unblocking call", key); return result; } catch (Exception ex) { hashInvalidationsInProgress.remove(key); latch.countDown(); if (ex instanceof TimeoutException) { throw (TimeoutException)ex; } throw new RuntimeException(ex); } }
private <T> T performWaitingForAllInvalidation(Callable<T> c, Duration timeout) throws TimeoutException { LongSupplier nanosRemaining = nanosStartingFromNow(timeout); CountDownLatch newLatch = new CountDownLatch(1); while (true) { if (!entity.isConnected()) { throw new IllegalStateException("Cluster tier manager disconnected"); } if (invalidateAllLatch.compareAndSet(null, newLatch)) { break; } else { CountDownLatch existingLatch = invalidateAllLatch.get(); if (existingLatch != null) { awaitOnLatch(existingLatch, nanosRemaining); } } } try { T result = c.call(); awaitOnLatch(newLatch, nanosRemaining); LOGGER.debug("CLIENT: all invalidated on all clients, unblocking call"); return result; } catch (Exception ex) { invalidateAllLatch.set(null); newLatch.countDown(); if (ex instanceof TimeoutException) { throw (TimeoutException)ex; } throw new RuntimeException(ex); } }