/** * Set on stop handler for this actor * * @param onStop The code to invoke when stopping */ public final void onStop(final Closure onStop) { if (onStop != null) { this.onStop = (Closure) onStop.clone(); this.onStop.setDelegate(this); this.onStop.setResolveStrategy(Closure.DELEGATE_FIRST); } }
/** * Sends a message and execute continuation when reply became available. * * @param message message to send * @param closure closure to execute when reply became available * @return The message that came in reply to the original send. */ @SuppressWarnings({"AssignmentToMethodParameter"}) public final <T> MessageStream sendAndContinue(final T message, Closure closure) { closure = (Closure) closure.clone(); closure.setDelegate(this); closure.setResolveStrategy(Closure.DELEGATE_FIRST); return send(message, new DataCallback(closure, parallelGroup)); }
Object callClosure(Object entity, Closure callable) { if (cloneFirst) { callable = (Closure) callable.clone(); } callable.setResolveStrategy(Closure.DELEGATE_FIRST); callable.setDelegate(entity); return callable.call(); }
private static DocumentDefinitions applyDefinitionsClosure( @DelegatesTo(value = DocumentDefinitions.class, strategy = Closure.DELEGATE_FIRST) Closure<?> closure) { Closure<?> docDefClosure = (Closure<?>) closure.clone(); docDefClosure.setResolveStrategy(Closure.DELEGATE_FIRST); DocumentDefinitions definitions = new DocumentDefinitions(); docDefClosure.setDelegate(definitions); docDefClosure.call(); return definitions; }
@Override public boolean onNodeChildren( final FactoryBuilderSupport builder, final Object node, final Closure childContent) { if (node instanceof ImportCustomizer) { Closure clone = (Closure) childContent.clone(); clone.setDelegate(new ImportHelper((ImportCustomizer) node)); clone.call(); } return false; }
protected String evaluateNameForValue(Object value, GrailsWebRequest webRequest) { if (value == null) { return null; } String name; if (value instanceof Closure) { Closure callable = (Closure) value; final Closure cloned = (Closure) callable.clone(); cloned.setDelegate(webRequest); cloned.setResolveStrategy(Closure.DELEGATE_FIRST); Object result = cloned.call(); name = result != null ? result.toString() : null; } else if (value instanceof Map) { Map httpMethods = (Map) value; name = (String) httpMethods.get(webRequest.getCurrentRequest().getMethod()); } else { name = value.toString(); } return name != null ? name.trim() : null; }
public ComposedClosure(Closure first, Closure<V> second) { super(first.clone()); this.first = (Closure) getOwner(); this.second = (Closure<V>) second.clone(); maximumNumberOfParameters = first.getMaximumNumberOfParameters(); }