Skip to content

Commit f7f5484

Browse files
committed
[ML] adjusting for backport (#36117)
1 parent ff6c194 commit f7f5484

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.io.stream.StreamOutput;
1515
import org.elasticsearch.common.unit.TimeValue;
16-
import org.elasticsearch.common.util.CachedSupplier;
1716
import org.elasticsearch.common.xcontent.ObjectParser;
1817
import org.elasticsearch.common.xcontent.ToXContentObject;
1918
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -30,6 +29,7 @@
3029
import org.elasticsearch.xpack.core.ml.datafeed.extractor.ExtractorUtils;
3130
import org.elasticsearch.xpack.core.ml.job.config.Job;
3231
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
32+
import org.elasticsearch.xpack.core.ml.utils.CachedSupplier;
3333
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
3434
import org.elasticsearch.xpack.core.ml.utils.MlStrings;
3535
import org.elasticsearch.xpack.core.ml.utils.ToXContentParams;
@@ -256,7 +256,7 @@ public DatafeedConfig(StreamInput in) throws IOException {
256256
} else {
257257
this.types = null;
258258
}
259-
if (in.getVersion().before(Version.CURRENT)) {
259+
if (in.getVersion().before(Version.V_6_6_0)) {
260260
this.query = QUERY_TRANSFORMER.toMap(in.readNamedWriteable(QueryBuilder.class));
261261
this.aggregations = AGG_TRANSFORMER.toMap(in.readOptionalWriteable(AggregatorFactories.Builder::new));
262262
} else {
@@ -384,7 +384,7 @@ public void writeTo(StreamOutput out) throws IOException {
384384
} else {
385385
out.writeBoolean(false);
386386
}
387-
if (out.getVersion().before(Version.CURRENT)) {
387+
if (out.getVersion().before(Version.V_6_6_0)) {
388388
out.writeNamedWriteable(getParsedQuery());
389389
out.writeOptionalWriteable(getParsedAggregations());
390390
} else {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.elasticsearch.xpack.core.ml.utils;
2+
3+
import java.util.function.Supplier;
4+
5+
/**
6+
* A {@link Supplier} that caches its return value. This may be useful to make
7+
* a {@link Supplier} idempotent or for performance reasons if always returning
8+
* the same instance is acceptable.
9+
*/
10+
public final class CachedSupplier<T> implements Supplier<T> {
11+
12+
private Supplier<T> supplier;
13+
private T result;
14+
private boolean resultSet;
15+
16+
public CachedSupplier(Supplier<T> supplier) {
17+
this.supplier = supplier;
18+
}
19+
20+
@Override
21+
public synchronized T get() {
22+
if (resultSet == false) {
23+
result = supplier.get();
24+
resultSet = true;
25+
}
26+
return result;
27+
}
28+
29+
}

0 commit comments

Comments
 (0)