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); } } }; }
@Override protected JAXBContext initialize() throws ConcurrentException { try { return JAXBContext.newInstance(Process.class); } catch (JAXBException e) { throw new ConcurrentException("Can not create JAXBContext for Business Process XML.", e); } }
private Mapper<?> getTarget() { if (singleton) try { return singletonTarget.get(); } catch (ConcurrentException e) { throw Exceptions.propagate(e); } else return targetInitializer.get(); }
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; } }; }
/** * Gets the plugin. * * @return The plugin. */ public static SpoofaxIdeaPlugin plugin() { try { return pluginLazy.get(); } catch (final ConcurrentException e) { throw new UnhandledException("An unexpected unhandled exception occurred during object creation.", e); } }
public static BasicMetaDataImpl getInstance() { try { return initializer.get(); } catch (ConcurrentException e) { throw new NetSuiteException("Initialization error", e); } }
/** * Gets the LogMapManager for given {@link SharedLogObjectID}. * <p/> * If listener was not registered, it will create and register a listener. * * @param oid {@link SharedLogObjectID} * @return {@link LogMapManager} */ private LogMapManager getLogMapManager(final SharedLogObjectID oid) { LogMapManager listener = ConcurrentUtils.createIfAbsentUnchecked(listenerMap, oid, new ConcurrentInitializer<LogMapManager>() { @Override public LogMapManager get() throws ConcurrentException { IMap<SeqNum, LogValue> logMap = getLogMap(oid); return new LogMapManager(oid, logMap); } }); return listener; }
@Override protected T initialize() throws ConcurrentException { return initializer.get(); }
public int getSum() throws ConcurrentException { return mSum.get(); }
@When("^computing sum$") public void computingSum() throws ConcurrentException { miSum = moSum.getSum(); }
@Test public void thenShouldBeEqualTo4() throws ConcurrentException { assertThat(sum.getSum()).isEqualTo(4); }
@Test public void thenShouldBeEqualTo3() throws ConcurrentException { assertThat(multiply).isEqualTo(3); }
@Test public void addition_isCorrect() throws ConcurrentException { given().first_number_$(1).and().second_number_$(3); when().computing_sum(); then().it_should_be_$(4); }
public void it_should_be_$(final int piExpected) throws ConcurrentException { assertThat(mSum.getSum()).isEqualTo(piExpected); }
@Override protected SpoofaxIdeaPlugin initialize() throws ConcurrentException { return new SpoofaxIdeaPlugin(); }
@Override protected BasicMetaDataImpl initialize() throws ConcurrentException { return new BasicMetaDataImpl(); }
protected T initialize() throws ConcurrentException { return func.call(); }
public static void main(String[] args) throws ConcurrentException { LazyInitializerTest lazyInitializerTest = new LazyInitializerTest(); System.out.println(lazyInitializerTest.get()); System.out.println(lazyInitializerTest.get()); }
/** * Creates and initializes the object managed by this {@code * LazyInitializer}. This method is called by {@link #get()} when the object * is accessed for the first time. An implementation can focus on the * creation of the object. No synchronization is needed, as this is already * handled by {@code get()}. * * @return the managed data object * @throws ConcurrentException if an error occurs during object creation */ @Override protected String initialize() throws ConcurrentException { System.out.println("from the initialize method"); return "hello"; }