Skip to content

Commit

Permalink
This closes #611
Browse files Browse the repository at this point in the history
  • Loading branch information
aledsage committed Mar 29, 2017
2 parents 5e0749e + 1d056d8 commit 9352396
Show file tree
Hide file tree
Showing 34 changed files with 335 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* where jobs can be:
* <ul>
* <li>Tracked with tags/buckets
* <li>Be {@link Runnable}s, {@link Callable}s, or {@link groovy.lang.Closure}s
* <li>Be {@link Runnable}s or {@link Callable}s, (support for {@link groovy.lang.Closure} is deprecated)
* <li>Remembered after completion
* <li>Treated as {@link Task} instances (see below)
* <li>Given powerful synchronization capabilities
Expand Down Expand Up @@ -104,11 +104,17 @@ public interface ExecutionManager {
* used for associating with contexts, mutex execution, and other purposes
* <li><em>synchId</em> - A string, or {@link Collection} of strings, representing a category on which an object should own a synch lock
* <li><em>synchObj</em> - A string, or {@link Collection} of strings, representing a category on which an object should own a synch lock
* <li><em>newTaskStartCallback</em> - A {@link groovy.lang.Closure} that will be invoked just before the task starts if it starts as a result of this call
* <li><em>newTaskEndCallback</em> - A {@link groovy.lang.Closure} that will be invoked when the task completes if it starts as a result of this call
* <li><em>newTaskStartCallback</em> - A callback that will be invoked just before the task starts if it starts as a result of this call.
* <li><em>newTaskEndCallback</em> - A callback that will be invoked when the task completes if it starts as a result of this call
* </ul>
*
* Callbacks run in the task's thread. It can be one of the following types:
* <ul>
* <li>{@link Runnable}
* <li>{@link Callable}
* <li>{@link com.google.common.base.Function} that matches the generics {@code <? super Task, ?>}
* <li>Support for {@link groovy.lang.Closure} is deprecated.
* </ul>
* Callbacks run in the task's thread, and if the callback is a {@link groovy.lang.Closure} it is passed the task for convenience. The closure can be any of the
* following types; either a {@link groovy.lang.Closure}, {@link Runnable} or {@link Callable}.
* <p>
* If a Map is supplied it must be modifiable (currently; may allow immutable maps in future).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@
*/
package org.apache.brooklyn.core.effector;

import groovy.lang.Closure;

import java.util.List;
import java.util.Map;

import org.apache.brooklyn.api.effector.ParameterType;
import org.apache.brooklyn.api.entity.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;

import groovy.lang.Closure;

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted
* (currently only used via {@link #create(String, Class, List, String, Closure)},
* so class is not deemed useful enough - extend {@link AbstractEffector} directly
* if really required).
*/
@Deprecated
public abstract class ExplicitEffector<I,T> extends AbstractEffector<T> {

private static final Logger LOG = LoggerFactory.getLogger(ExplicitEffector.class);

public ExplicitEffector(String name, Class<T> type, String description) {
this(name, type, ImmutableList.<ParameterType<?>>of(), description);
}
Expand All @@ -46,12 +58,20 @@ public T call(Entity entity, Map parameters) {

/** convenience to create an effector supplying a closure; annotations are preferred,
* and subclass here would be failback, but this is offered as
* workaround for bug GROOVY-5122, as discussed in test class CanSayHi
* workaround for bug GROOVY-5122, as discussed in test class CanSayHi.
*
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static <I,T> ExplicitEffector<I,T> create(String name, Class<T> type, List<ParameterType<?>> parameters, String description, Closure body) {
LOG.warn("Use of groovy.lang.Closure is deprecated, in ExplicitEffector.create()");
return new ExplicitEffectorFromClosure<I,T>(name, type, parameters, description, body);
}


/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
private static class ExplicitEffectorFromClosure<I,T> extends ExplicitEffector<I,T> {
private static final long serialVersionUID = -5771188171702382236L;
final Closure<T> body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public MethodEffector(Method method) {
this(new AnnotationsOnMethod(method.getDeclaringClass(), method), null);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public MethodEffector(MethodClosure mc) {
this(new AnnotationsOnMethod((Class<?>)mc.getDelegate(), mc.getMethod()), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,10 @@ public String getFirst(Map flags, String ...keys) {
}
if (flags.get("failIfNone")!=null && !Boolean.FALSE.equals(flags.get("failIfNone"))) {
Object f = flags.get("failIfNone");
if (f instanceof Closure)
if (f instanceof Closure) {
LOG.warn("Use of groovy.lang.Closure is deprecated as value for 'failIfNone', in BrooklynProperties.getFirst()");
((Closure)f).call((Object[])keys);
}
if (Boolean.TRUE.equals(f))
throw new NoSuchElementException("Brooklyn unable to find mandatory property "+keys[0]+
(keys.length>1 ? " (or "+(keys.length-1)+" other possible names, full list is "+Arrays.asList(keys)+")" : "") );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,24 @@ public BasicSubscriptionContext(Map<String, ?> flags, SubscriptionManager manage
if (flags!=null) this.flags.putAll(flags);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings("rawtypes")
public <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, Closure c) {
LOG.warn("Use of groovy.lang.Closure is deprecated in BasicSubscriptionContext.subscribe()");
return subscribe(Collections.<String,Object>emptyMap(), producer, sensor, c);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings("rawtypes")
public <T> SubscriptionHandle subscribe(Map<String, ?> newFlags, Entity producer, Sensor<T> sensor, Closure c) {
return subscribe(newFlags, producer, sensor, toSensorEventListener(c));
LOG.warn("Use of groovy.lang.Closure is deprecated in BasicSubscriptionContext.subscribe()");
return subscribe(newFlags, producer, sensor, toSensorEventListener(c));
}

@Override
Expand All @@ -88,13 +98,23 @@ public <T> SubscriptionHandle subscribe(Map<String, ?> newFlags, Entity producer
return manager.subscribe(subscriptionFlags, producer, sensor, listener);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings("rawtypes")
public <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, Closure c) {
LOG.warn("Use of groovy.lang.Closure is deprecated in BasicSubscriptionContext.subscribeToChildren()");
return subscribeToChildren(Collections.<String,Object>emptyMap(), parent, sensor, c);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings("rawtypes")
public <T> SubscriptionHandle subscribeToChildren(Map<String, Object> newFlags, Entity parent, Sensor<T> sensor, Closure c) {
LOG.warn("Use of groovy.lang.Closure is deprecated in BasicSubscriptionContext.subscribeToChildren()");
return subscribeToChildren(newFlags, parent, sensor, toSensorEventListener(c));
}

Expand All @@ -110,13 +130,23 @@ public <T> SubscriptionHandle subscribeToChildren(Map<String, Object> newFlags,
return manager.subscribeToChildren(subscriptionFlags, parent, sensor, listener);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings("rawtypes")
public <T> SubscriptionHandle subscribeToMembers(Group parent, Sensor<T> sensor, Closure c) {
LOG.warn("Use of groovy.lang.Closure is deprecated in BasicSubscriptionContext.subscribeToMembers()");
return subscribeToMembers(Collections.<String,Object>emptyMap(), parent, sensor, c);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings("rawtypes")
public <T> SubscriptionHandle subscribeToMembers(Map<String, Object> newFlags, Group parent, Sensor<T> sensor, Closure c) {
LOG.warn("Use of groovy.lang.Closure is deprecated in BasicSubscriptionContext.subscribeToMembers()");
return subscribeToMembers(newFlags, parent, sensor, toSensorEventListener(c));
}

Expand Down Expand Up @@ -171,6 +201,10 @@ public int unsubscribeAll() {
return count;
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings("rawtypes")
private <T> SensorEventListener<T> toSensorEventListener(final Closure c) {
return new SensorEventListener<T>() {
Expand Down
20 changes: 19 additions & 1 deletion core/src/main/java/org/apache/brooklyn/core/policy/Policies.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
import org.apache.brooklyn.core.policy.AbstractPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import groovy.lang.Closure;

@SuppressWarnings({"rawtypes","unchecked"})
public class Policies {

private static final Logger LOG = LoggerFactory.getLogger(Policies.class);

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static SensorEventListener listenerFromValueClosure(final Closure code) {
LOG.warn("Use of groovy.lang.Closure is deprecated in Policies.listenerFromValueClosure()");
return new SensorEventListener() {
@Override
public void onEvent(SensorEvent event) {
Expand All @@ -41,7 +49,12 @@ public void onEvent(SensorEvent event) {
};
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static <T> Policy newSingleSensorValuePolicy(final Sensor<T> sensor, final Closure code) {
LOG.warn("Use of groovy.lang.Closure is deprecated in Policies.newSingleSensorValuePolicy()");
return new AbstractPolicy() {
@Override
public void setEntity(EntityLocal entity) {
Expand All @@ -51,8 +64,13 @@ public void setEntity(EntityLocal entity) {
};
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static <S,T> Policy newSingleSensorValuePolicy(final Entity remoteEntity, final Sensor<T> remoteSensor,
final Closure code) {
LOG.warn("Use of groovy.lang.Closure is deprecated in Policies.newSingleSensorValuePolicy()");
return new AbstractPolicy() {
@Override
public void setEntity(EntityLocal entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public static <T> Task<T> attributeWhenReady(Entity source, AttributeSensor<T> s
return attributeWhenReady(source, sensor, GroovyJavaMethods.truthPredicate());
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static <T> Task<T> attributeWhenReady(Entity source, AttributeSensor<T> sensor, Closure<Boolean> ready) {
Predicate<Object> readyPredicate = (ready != null) ? GroovyJavaMethods.<Object>predicateFromClosure(ready) : GroovyJavaMethods.truthPredicate();
return attributeWhenReady(source, sensor, readyPredicate);
Expand All @@ -134,12 +138,20 @@ public static <T> Task<T> attributeWhenReady(final Entity source, final Attribut

}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static <T,V> Task<V> attributePostProcessedWhenReady(Entity source, AttributeSensor<T> sensor, Closure<Boolean> ready, Closure<V> postProcess) {
Predicate<? super T> readyPredicate = (ready != null) ? GroovyJavaMethods.predicateFromClosure(ready) : GroovyJavaMethods.truthPredicate();
Function<? super T, V> postProcessFunction = GroovyJavaMethods.<T,V>functionFromClosure(postProcess);
return attributePostProcessedWhenReady(source, sensor, readyPredicate, postProcessFunction);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
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));
}
Expand All @@ -152,10 +164,18 @@ public static <T,V> Task<V> valueWhenAttributeReady(Entity source, AttributeSens
return attributePostProcessedWhenReady(source, sensor, GroovyJavaMethods.truthPredicate(), valueProvider);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static <T,V> Task<V> valueWhenAttributeReady(Entity source, AttributeSensor<T> sensor, Closure<V> valueProvider) {
return attributePostProcessedWhenReady(source, sensor, GroovyJavaMethods.truthPredicate(), valueProvider);
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
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));
}
Expand Down Expand Up @@ -395,13 +415,20 @@ public static <U,T> Task<T> transform(final Task<U> task, final Function<U,T> tr
return transform(MutableMap.of("displayName", "transforming "+task), task, transformer);
}

/** @see #transform(Task, Function) */
/**
* @see #transform(Task, Function)
*
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <U,T> Task<T> transform(Task<U> task, Closure transformer) {
return transform(task, GroovyJavaMethods.functionFromClosure(transformer));
}

/** @see #transform(Task, Function) */
/**
* @see #transform(Task, Function)
*/
@SuppressWarnings({ "rawtypes" })
public static <U,T> Task<T> transform(final Map flags, final TaskAdaptable<U> task, final Function<U,T> transformer) {
return new BasicTask<T>(flags, new Callable<T>() {
Expand All @@ -421,13 +448,23 @@ public static <U,T> Task<T> transformMultiple(Function<List<U>,T> transformer, @
return transformMultiple(MutableMap.of("displayName", "transforming multiple"), transformer, tasks);
}

/** @see #transformMultiple(Function, TaskAdaptable...) */
/**
* @see #transformMultiple(Function, TaskAdaptable...)
*
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <U,T> Task<T> transformMultiple(Closure transformer, TaskAdaptable<U> ...tasks) {
return transformMultiple(GroovyJavaMethods.functionFromClosure(transformer), tasks);
}

/** @see #transformMultiple(Function, TaskAdaptable...) */
/**
* @see #transformMultiple(Function, TaskAdaptable...)
*
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <U,T> Task<T> transformMultiple(Map flags, Closure transformer, TaskAdaptable<U> ...tasks) {
return transformMultiple(flags, GroovyJavaMethods.functionFromClosure(transformer), tasks);
Expand Down Expand Up @@ -736,7 +773,11 @@ private static <T> T resolveArgument(Object argument, Iterator<?> taskArgsIterat
public static <T> Task<List<T>> listAttributesWhenReady(AttributeSensor<T> sensor, Iterable<Entity> entities) {
return listAttributesWhenReady(sensor, entities, GroovyJavaMethods.truthPredicate());
}


/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static <T> Task<List<T>> listAttributesWhenReady(AttributeSensor<T> sensor, Iterable<Entity> entities, Closure<Boolean> readiness) {
Predicate<Object> readinessPredicate = (readiness != null) ? GroovyJavaMethods.<Object>predicateFromClosure(readiness) : GroovyJavaMethods.truthPredicate();
return listAttributesWhenReady(sensor, entities, readinessPredicate);
Expand Down Expand Up @@ -850,6 +891,10 @@ public <T2> Builder<T2,T2> attributeWhenReady(Entity source, AttributeSensor<T2>
abortIfOnFire();
return (Builder<T2, T2>) this;
}
/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public Builder<T,V> readiness(Closure<Boolean> val) {
this.readiness = GroovyJavaMethods.predicateFromClosure(checkNotNull(val, "val"));
return this;
Expand All @@ -858,6 +903,10 @@ public Builder<T,V> readiness(Predicate<? super T> val) {
this.readiness = checkNotNull(val, "ready");
return this;
}
/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
public <V2> Builder<T,V2> postProcess(Closure<V2> val) {
this.postProcess = (Function) GroovyJavaMethods.<T,V2>functionFromClosure(checkNotNull(val, "postProcess"));
Expand Down Expand Up @@ -1008,6 +1057,10 @@ public MultiBuilder<T, V, Boolean> postProcessFromMultiple(final Predicate<? sup
return postProcessFromMultiple(Functions.forPredicate(val));
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public <V1> MultiBuilder<T, V1, V2> postProcess(Closure<V1> val) {
builder.postProcess(val);
return (MultiBuilder<T, V1, V2>) this;
Expand Down

0 comments on commit 9352396

Please sign in to comment.