@Override public Task<T> apply(Entity it) { return attributeWhenReady(it, sensor, readiness); } }));
public static <T,V> Task<V> valueWhenAttributeReady(Entity source, AttributeSensor<T> sensor, Function<? super T,V> valueProvider) { return attributePostProcessedWhenReady(source, sensor, GroovyJavaMethods.truthPredicate(), valueProvider); }
/** returns a task for parallel execution returning a list of values for the given sensor for the given entity list, * optionally when the values satisfy a given readiness predicate (defaulting to groovy truth if not supplied) */ public static <T> Task<List<T>> listAttributesWhenReady(AttributeSensor<T> sensor, Iterable<Entity> entities) { return listAttributesWhenReady(sensor, entities, GroovyJavaMethods.truthPredicate()); }
@Override public void initApp() { RedisStore redis = addChild(EntitySpec.create(RedisStore.class) .configure(SoftwareProcess.SUGGESTED_VERSION, "3.0.0")); addChild(EntitySpec.create(NodeJsWebAppService.class) .configure(NodeJsWebAppService.APP_GIT_REPOSITORY_URL, "https://github.com/grkvlt/nodejs-todo/") .configure(NodeJsWebAppService.APP_FILE, "server.js") .configure(NodeJsWebAppService.APP_NAME, "nodejs-todo") .configure(NodeJsWebAppService.NODE_PACKAGE_LIST, ImmutableList.of("express", "ejs", "jasmine-node", "underscore", "method-override", "cookie-parser", "express-session", "body-parser", "cookie-session", "redis", "redis-url", "connect")) .configure(SoftwareProcess.SHELL_ENVIRONMENT, ImmutableMap.<String, Object>of("REDISTOGO_URL", DependentConfiguration.formatString("redis://%s/", attributeWhenReady(redis, DockerUtils.mappedPortSensor(RedisStore.REDIS_PORT))))) .configure(SoftwareProcess.LAUNCH_LATCH, attributeWhenReady(redis, Startable.SERVICE_UP))); }
/** @see #transformMultiple(Function, Task...) */ public static <U,T> Task<T> transformMultiple(Map flags, final Function<List<U>,T> transformer, TaskAdaptable<U> ...tasks) { return transformMultiple(flags, transformer, Arrays.asList(tasks)); } public static <U,T> Task<T> transformMultiple(Map flags, final Function<List<U>,T> transformer, List<? extends TaskAdaptable<U>> tasks) {
public static <U,T> Task<T> transformMultiple(Map flags, final Function<List<U>,T> transformer, List<? extends TaskAdaptable<U>> tasks) { if (tasks.size()==1) { return transform(flags, tasks.get(0), new Function<U,T>() { @Override @Nullable public T apply(@Nullable U input) { return transformer.apply(ImmutableList.of(input)); } }); } return transform(flags, new ParallelTask<U>(tasks), transformer); }
/** @see #waitForTask(Task, Entity, String) */ public static <T> T waitForTask(Task<T> t, Entity context) throws InterruptedException { return waitForTask(t, context, null); }
.configure(JavaWebAppService.ROOT_WAR, Entities.getRequiredUrlConfig(this, WAR_PATH)) .configure(javaSysProp("brooklyn.example.db.url"), formatString("jdbc:%s%s?user=%s&password=%s", attributeWhenReady(mysql, mappedDatastoreUrl), DB_TABLE, DB_USERNAME, DB_PASSWORD))) .configure(ControlledDynamicWebAppCluster.CONTROLLER_SPEC, EntitySpec.create(NginxController.class)
/** Returns a task which waits for multiple other tasks (submitting if necessary) * and performs arbitrary computation over the List of results. * @see #transform(Task, Function) but note argument order is reversed (counterintuitive) to allow for varargs */ public static <U,T> Task<T> transformMultiple(Function<List<U>,T> transformer, TaskAdaptable<U> ...tasks) { return transformMultiple(MutableMap.of("displayName", "transforming multiple"), transformer, tasks); }
/** @see #transform(Task, Function) */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <U,T> Task<T> transform(Task<U> task, Closure transformer) { return transform(task, GroovyJavaMethods.functionFromClosure(transformer)); }
@SuppressWarnings({ "unchecked", "serial" }) public static <T> Supplier<T> attributeSupplierWhenReady(final Entity entity, final AttributeSensor<T> sensor) { final Task<T> task = DependentConfiguration.attributeWhenReady(entity, sensor); return new Supplier<T>() { @Override public T get() { try { TypeToken<T> type = new TypeToken<T>(sensor.getType()) {}; return Tasks.resolveValue(task, (Class<T>) type.getRawType(), ((EntityInternal) entity).getExecutionContext(), "attributeSupplierWhenReady"); } catch (Exception e) { throw Exceptions.propagate(e); } } }; }
public static <T,V> Task<V> valueWhenAttributeReady(Entity source, AttributeSensor<T> sensor, Closure<V> valueProvider) { return attributePostProcessedWhenReady(source, sensor, GroovyJavaMethods.truthPredicate(), valueProvider); }
/** @see #transformMultiple(Function, Task...) */ public static <U,T> Task<T> transformMultiple(Map flags, Closure transformer, TaskAdaptable<U> ...tasks) { return transformMultiple(flags, GroovyJavaMethods.functionFromClosure(transformer), tasks); }
/** * Returns a {@link Task} which waits for the result of first parameter, then applies the function in the second * parameter to it, returning that result. * * Particular useful in Entity configuration where config will block until Tasks have completed, * allowing for example an {@link #attributeWhenReady(Entity, AttributeSensor, Predicate)} expression to be * passed in the first argument then transformed by the function in the second argument to generate * the value that is used for the configuration */ public static <U,T> Task<T> transform(final Task<U> task, final Function<U,T> transformer) { return transform(MutableMap.of("displayName", "transforming "+task), task, transformer); }
public static <T> Task<List<T>> listAttributesWhenReady(AttributeSensor<T> sensor, Iterable<Entity> entities, Closure readiness) { Predicate<T> readinessPredicate = (readiness != null) ? GroovyJavaMethods.predicateFromClosure(readiness) : GroovyJavaMethods.truthPredicate(); return listAttributesWhenReady(sensor, entities, readiness); }
/** * Default readiness is Groovy truth. * * @see #attributeWhenReady(Entity, AttributeSensor, Predicate) */ public static <T> Task<T> attributeWhenReady(Entity source, AttributeSensor<T> sensor) { return attributeWhenReady(source, sensor, GroovyJavaMethods.truthPredicate()); }
public static <T,V> Task<V> attributePostProcessedWhenReady(final Entity source, final AttributeSensor<T> sensor, final Predicate<? super T> ready, final Closure<V> postProcess) { return attributePostProcessedWhenReady(source, sensor, ready, GroovyJavaMethods.<T,V>functionFromClosure(postProcess)); }
/** @see #transformMultiple(Function, Task...) */ public static <U,T> Task<T> transformMultiple(Closure transformer, TaskAdaptable<U> ...tasks) { return transformMultiple(GroovyJavaMethods.functionFromClosure(transformer), tasks); }
public static <T> Task<T> attributeWhenReady(Entity source, AttributeSensor<T> sensor, Closure ready) { Predicate<T> readyPredicate = (ready != null) ? GroovyJavaMethods.predicateFromClosure(ready) : GroovyJavaMethods.truthPredicate(); return attributeWhenReady(source, sensor, readyPredicate); }
public static <T,V> Task<V> attributePostProcessedWhenReady(Entity source, AttributeSensor<T> sensor, Closure<V> postProcess) { return attributePostProcessedWhenReady(source, sensor, GroovyJavaMethods.truthPredicate(), GroovyJavaMethods.<T,V>functionFromClosure(postProcess)); }