/** * Supplies the value to be returned by each poll. * <p> * Note this <em>must</em> use generics, otherwise the return type of subsequent chained * calls will (e.g. to {@link FeedConfig#onException(com.google.common.base.Function)} will * return the wrong type. */ @SuppressWarnings("unchecked") public <newS> FunctionPollConfig<newS, T> supplier(final Supplier<? extends newS> val) { this.callable = Functionals.callable( checkNotNull(val, "supplier") ); return (FunctionPollConfig<newS, T>) this; }
public static <T,U> Callable<U> callable(Function<T,U> f, T x) { return callable(Suppliers.compose(f, Suppliers.ofInstance(x))); }
@Override public V2 call() throws Exception { List<V> prePostProgress = DynamicTasks.queue(parallelTask).get(); return DynamicTasks.queue( Tasks.<V2>builder().displayName("post-processing").description("Applying "+postProcessFromMultiple) .body(Functionals.callable(postProcessFromMultiple, prePostProgress)) .build()).get(); } })
private Maybe<Entity> getResolvedConfigInTask(final Entity entity, final ConfigKey<Entity> key) { return Tasks.resolving(Tasks.<Entity>builder().body( Functionals.callable(Suppliers.compose(EntityFunctions.config(key), Suppliers.ofInstance(entity))) ).build()) .as(Entity.class) .context(entity).embedResolutionInTask(true) .getMaybe(); }
@Test public void testErrorsResolvingPropagatesOrSwallowedAllCorrectly() throws Exception { app.config().set(TestEntity.CONF_OBJECT, ValueResolverTest.newThrowTask(Duration.ZERO)); Task<Object> t = Tasks.builder().body(Functionals.callable(EntityFunctions.config(TestEntity.CONF_OBJECT), app)).build(); ValueResolver<Object> v = Tasks.resolving(t).as(Object.class).context(app); ValueResolverTest.assertThrowsOnGetMaybe(v); ValueResolverTest.assertThrowsOnGet(v); v.swallowExceptions(); ValueResolverTest.assertMaybeIsAbsent(v); ValueResolverTest.assertThrowsOnGet(v); v.defaultValue("foo"); ValueResolverTest.assertMaybeIsAbsent(v); assertEquals(v.clone().get(), "foo"); assertResolvesValue(v, Object.class, "foo"); }