@Override public R get() { return fn.apply(host.get()); }
/** * A supplier capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return Supplier with a retry strategy */ public FluentSupplier<R> retry(final int times, final int backoffStartTime) { return FluentFunctions.of(() -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { return fn.get(); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())) .run(); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
/** * A Function capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return Function with a retry strategy */ public FluentFunction<T, R> retry(final int times, final int backoffStartTime) { return FluentFunctions.of(t -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { return fn.apply(t); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
/** * A BiFunction capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return BiFunction with a retry strategy */ public FluentBiFunction<T1, T2, R> retry(final int times, final int backoffStartTime) { return FluentFunctions.of((t1, t2) -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { return fn.apply(t1, t2); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
/** * A supplier capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return Supplier with a retry strategy */ public FluentRunnable retry(final int times, final int backoffStartTime) { return FluentFunctions.ofRunnable(() -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { run(); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())) .run(); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
@Test public void externalGet(){ value = 100; MutableInt ext = MutableInt.fromExternal(()->value,v->this.value=v); assertThat(ext.get(),equalTo(100)); } @Test
/** * A TriFunction capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return TriFunction with a retry strategy */ public FluentTriFunction<T1, T2, T3, R> retry(final int times, final int backoffStartTime) { return FluentFunctions.of((t1, t2, t3) -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { return fn.apply(t1, t2, t3); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
@Test public void externalMapOutput(){ value = 200; MutableInt ext = MutableInt.fromExternal(()->value,v->this.value=v) .mapOutput(s->s*2); assertThat(ext.get(),equalTo(400)); } }
@Override public R get() { return fn.apply(host.get()); }
/** * A supplier capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return Supplier with a retry strategy */ public FluentSupplier<R> retry(final int times, final int backoffStartTime) { return FluentFunctions.of(() -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { return fn.get(); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())) .run(); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
/** * A Function capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return Function with a retry strategy */ public FluentFunction<T, R> retry(final int times, final int backoffStartTime) { return FluentFunctions.of(t -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { return fn.apply(t); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
/** * A BiFunction capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return BiFunction with a retry strategy */ public FluentBiFunction<T1, T2, R> retry(final int times, final int backoffStartTime) { return FluentFunctions.of((t1, t2) -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { return fn.apply(t1, t2); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
/** * A supplier capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return Supplier with a retry strategy */ public FluentRunnable retry(final int times, final int backoffStartTime) { return FluentFunctions.ofRunnable(() -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { run(); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())) .run(); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }
/** * A TriFunction capable of retrying on failure using an exponential backoff strategy * * @param times Number of times to retry * @param backoffStartTime Wait time before first retry * @return TriFunction with a retry strategy */ public FluentTriFunction<T1, T2, T3, R> retry(final int times, final int backoffStartTime) { return FluentFunctions.of((t1, t2, t3) -> { int count = times; final MutableInt sleep = MutableInt.of(backoffStartTime); Throwable exception = null; while (count-- > 0) { try { return fn.apply(t1, t2, t3); } catch (final Throwable e) { exception = e; } ExceptionSoftener.softenRunnable(() -> Thread.sleep(sleep.get())); sleep.mutate(s -> s * 2); } throw ExceptionSoftener.throwSoftenedException(exception); }); }