Github user aledsage commented on the issue:
https://github.com/apache/brooklyn-server/pull/586
@tbouron Thanks. My use-case for `deferred` is a bit unusual! The "general"
use-case is where you want to delay the creation/evaluation of the object until
it's actually needed. And to have it being called every time it is evaluated,
rather than evaluated only once and its value stored. One might want this for a
number of reasons:
1. If evaluated statically, then that result is persisted (which may
include confidential info). If `deferred`, then the persisted value will be the
DSL.
2. There is a difference in behaviour for if a `$brooklyn:object` has an
arg that is deferred (e.g. an arg that is `$brooklyn:config(...)`) versus if
all the args can be statically evaluated: with the former, the value is the
"deferred DSL"; with the latter, it is evaluated immediately. This allows one
to force the two ways to behave the same.
My use-case is a bit sneaky (and one could argue misusing config, because
the value changes each time you ask for it)! I am writing a yaml-based test for
a service, and am using `org.apache.brooklyn.test.framework.TestHttpCall`. When
constructing the URL, I need to include a timestamp (for "now") in the url
query parameters. I therefore want some way to get the current timestamp at the
time the url is being used (rather the time when the entity was constructed).
For example:
```
type: org.apache.brooklyn.test.framework.TestHttpCall
brooklyn.config:
url:
$brooklyn:formatString:
- "%s/usage/?startTime=2016-01-01T00:00:00Z&endTime=%s"
-
$brooklyn:component($brooklyn:config("targetId")).attributeWhenReady("main.uri")
- $brooklyn:formatString:
- "%sZ"
- $brooklyn:object:
type: org.apache.brooklyn.util.time.Time
factoryMethod.name: makeDateString
factoryMethod.args:
- $brooklyn:object:
deferred: true
type: java.lang.System
factoryMethod.name: currentTimeMillis
- yyyy-MM-dd'T'HH:mm:ss
- UTC
```
Without the `deferred: true`, the `endTime` is the time at which the entity
was constructed. With the `deferred`, it is the time at which the entity's
`start` effector is called (i.e. when it reads the `url` config value).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---