You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/04/28 10:36:30 UTC
[2/3] brooklyn-server git commit: HttpRequestSensor: avoid anonymous
inner class persistence
HttpRequestSensor: avoid anonymous inner class persistence
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/48271a4e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/48271a4e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/48271a4e
Branch: refs/heads/master
Commit: 48271a4e1f50d4d7f69b69085a7cba41f3b8dd8c
Parents: 94b0a3e
Author: Aled Sage <al...@gmail.com>
Authored: Thu Apr 27 21:42:57 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Apr 27 21:42:57 2017 +0100
----------------------------------------------------------------------
.../core/sensor/http/HttpRequestSensor.java | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/48271a4e/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java b/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java
index 966a88c..22e24f1 100644
--- a/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java
+++ b/core/src/main/java/org/apache/brooklyn/core/sensor/http/HttpRequestSensor.java
@@ -71,12 +71,16 @@ public final class HttpRequestSensor<T> extends AddSensor<T> {
}
final ConfigBag allConfig = ConfigBag.newInstanceCopying(this.params).putAll(params);
- final Supplier<URI> uri = new Supplier<URI>() {
+
+ // TODO Keeping anonymous inner class for backwards compatibility with persisted state
+ new Supplier<URI>() {
@Override
public URI get() {
return URI.create(EntityInitializers.resolve(allConfig, SENSOR_URI));
}
};
+
+ final Supplier<URI> uri = new UriSupplier(allConfig);
final String jsonPath = EntityInitializers.resolve(allConfig, JSON_PATH);
final String username = EntityInitializers.resolve(allConfig, USERNAME);
final String password = EntityInitializers.resolve(allConfig, PASSWORD);
@@ -102,4 +106,17 @@ public final class HttpRequestSensor<T> extends AddSensor<T> {
entity.addFeed(feed);
}
+ // TODO this will cause `allConfig` to be persisted inside the UriSupplier, which is not ideal.
+ // However, it's hard to avoid, given we don't know what config is needed to later resolve the URI.
+ static class UriSupplier implements Supplier<URI> {
+ private final ConfigBag allConfig;
+
+ public UriSupplier(ConfigBag allConfig) {
+ this.allConfig = allConfig;
+ }
+ @Override
+ public URI get() {
+ return URI.create(EntityInitializers.resolve(allConfig, SENSOR_URI));
+ }
+ }
}