private void handlePotentialStuckRepairs(LazyInitializer<Set<String>> busyHosts, String hostName) throws ConcurrentException { if (!busyHosts.get().contains(hostName) && context.storage instanceof IDistributedStorage) { try (JmxProxy hostProxy = context.jmxConnectionFactory.connect(hostName, context.config.getJmxConnectionTimeoutInSeconds())) { // We double check that repair is still running there before actually canceling repairs if (hostProxy.isRepairRunning()) { LOG.warn( "A host ({}) reported that it is involved in a repair, but there is no record " + "of any ongoing repair involving the host. Sending command to abort all repairs " + "on the host.", hostName); hostProxy.cancelAllRepairs(); hostProxy.close(); } } catch (ReaperException | RuntimeException | InterruptedException | JMException e) { LOG.debug("failed to cancel repairs on host {}", hostName, e); } } }
/** * Use a supplier to perform lazy instantiation of a value. Wraps the given * supplier in a new Supplier that has the lazy loading logic. */ public static <T> Supplier<T> lazy(Supplier<T> source) { return new Supplier<T>() { final LazyInitializer<T> init = new LazyInitializer<T>() { @Override protected T initialize() throws ConcurrentException { return source.get(); } }; @Override public T get() { try { return init.get(); } catch (ConcurrentException e) { throw new IllegalStateException(e); } } }; }
public Sum(int a, int b) { this.a = a; this.b = b; mSum = new LazyInitializer<Integer>() { @Override protected Integer initialize() throws ConcurrentException { return Sum.this.a + Sum.this.b; } }; }