Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event with handle #4952

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ protected JacksonEvent(final Builder builder) {
}

this.jsonNode = getInitialJsonNode(builder.data);
this.eventHandle = new DefaultEventHandle(eventMetadata.getTimeReceived());
if (builder.eventHandle != null) {
this.eventHandle = builder.eventHandle;
} else {
this.eventHandle = new DefaultEventHandle(eventMetadata.getTimeReceived());
}
final Instant externalOriginationTime = this.eventMetadata.getExternalOriginationTime();
if (externalOriginationTime != null) {
eventHandle.setExternalOriginationTime(externalOriginationTime);
Expand Down Expand Up @@ -532,10 +536,11 @@ public static JacksonEvent fromEvent(final Event event) {
public abstract static class Builder<T extends Builder<T>> {

private EventMetadata eventMetadata;
private Object data;
protected Object data;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to expose this further?

If you do need it, you should have a protected getter: protected Object getData().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I do need it because I am exposing it to derived classes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I need it so that I can modify it directly from derived classes, getData() does not work. I can add setData() but I think it makes sense to actually use protected member so that derived classes can directly modify it. I think it makes sense in this case. Let me know what you think. The current code is broken in the sense that JacksonMetric has it's own data which is different from parent class's data and that is problematic in some cases.

private String eventType;
private Instant timeReceived;
private Map<String, Object> eventMetadataAttributes;
protected transient EventHandle eventHandle;

public abstract T getThis();

Expand Down Expand Up @@ -575,6 +580,18 @@ public Builder<T> withTimeReceived(final Instant timeReceived) {
return this;
}

/**
* Sets the event handle
*
* @param eventHandle event handle
* @return returns the builder
* @since 2.10
*/
protected Builder<T> withEventHandle(final EventHandle eventHandle) {
this.eventHandle = eventHandle;
return this;
}

/**
* Sets the metadata.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public JacksonExponentialHistogram.Builder getThis() {
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withSum(double sum) {
data.put(SUM_KEY, sum);
put(SUM_KEY, sum);
return this;
}

Expand All @@ -137,7 +137,7 @@ public JacksonExponentialHistogram.Builder withSum(double sum) {
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withCount(long count) {
data.put(COUNT_KEY, count);
put(COUNT_KEY, count);
return this;
}

Expand All @@ -149,7 +149,7 @@ public JacksonExponentialHistogram.Builder withCount(long count) {
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withScale(int scale) {
data.put(SCALE_KEY, scale);
put(SCALE_KEY, scale);
return this;
}

Expand All @@ -162,7 +162,7 @@ public JacksonExponentialHistogram.Builder withScale(int scale) {
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withZeroCount(long zeroCount) {
data.put(ZERO_COUNT_KEY, zeroCount);
put(ZERO_COUNT_KEY, zeroCount);
return this;
}

Expand All @@ -174,7 +174,7 @@ public JacksonExponentialHistogram.Builder withZeroCount(long zeroCount) {
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withAggregationTemporality(String aggregationTemporality) {
data.put(AGGREGATION_TEMPORALITY_KEY, aggregationTemporality);
put(AGGREGATION_TEMPORALITY_KEY, aggregationTemporality);
return this;
}

Expand All @@ -186,7 +186,7 @@ public JacksonExponentialHistogram.Builder withAggregationTemporality(String agg
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withPositiveBuckets(List<Bucket> exponentialBuckets) {
data.put(POSITIVE_BUCKETS_KEY, exponentialBuckets);
put(POSITIVE_BUCKETS_KEY, exponentialBuckets);
return this;
}

Expand All @@ -198,7 +198,7 @@ public JacksonExponentialHistogram.Builder withPositiveBuckets(List<Bucket> exp
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withNegativeBuckets(List<Bucket> exponentialBuckets) {
data.put(NEGATIVE_BUCKETS_KEY, exponentialBuckets);
put(NEGATIVE_BUCKETS_KEY, exponentialBuckets);
return this;
}

Expand All @@ -210,7 +210,7 @@ public JacksonExponentialHistogram.Builder withNegativeBuckets(List<Bucket> expo
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withPositive(List<Long> bucketCountsList) {
data.put(POSITIVE_KEY, bucketCountsList);
put(POSITIVE_KEY, bucketCountsList);
return this;
}

Expand All @@ -222,7 +222,7 @@ public JacksonExponentialHistogram.Builder withPositive(List<Long> bucketCountsL
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withNegative(List<Long> bucketCountsList) {
data.put(NEGATIVE_KEY, bucketCountsList);
put(NEGATIVE_KEY, bucketCountsList);
return this;
}

Expand All @@ -234,7 +234,7 @@ public JacksonExponentialHistogram.Builder withNegative(List<Long> bucketCountsL
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withPositiveOffset(int offset) {
data.put(POSITIVE_OFFSET_KEY, offset);
put(POSITIVE_OFFSET_KEY, offset);
return this;
}

Expand All @@ -258,7 +258,7 @@ public JacksonExponentialHistogram.Builder withTimeReceived(final Instant timeRe
* @since 1.4
*/
public JacksonExponentialHistogram.Builder withNegativeOffset(int offset) {
data.put(NEGATIVE_OFFSET_KEY, offset);
put(NEGATIVE_OFFSET_KEY, offset);
return this;
}

Expand All @@ -284,13 +284,13 @@ public JacksonExponentialHistogram build(boolean flattenAttributes) {
this.withEventKind(KIND.EXPONENTIAL_HISTOGRAM.toString());
this.withEventType(EventType.METRIC.toString());
checkAndSetDefaultValues();
new ParameterValidator().validate(REQUIRED_KEYS, REQUIRED_NON_EMPTY_KEYS, REQUIRED_NON_NULL_KEYS, data);
new ParameterValidator().validate(REQUIRED_KEYS, REQUIRED_NON_EMPTY_KEYS, REQUIRED_NON_NULL_KEYS, (HashMap<String, Object>)data);

return new JacksonExponentialHistogram(this, flattenAttributes);
}

private void checkAndSetDefaultValues() {
data.computeIfAbsent(ATTRIBUTES_KEY, k -> new HashMap<>());
computeIfAbsent(ATTRIBUTES_KEY, k -> new HashMap<>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Builder getThis() {
*/
public Builder withValue(final Double value) {
if (value != null) {
data.put(VALUE_KEY, value);
put(VALUE_KEY, value);
}
return this;
}
Expand Down Expand Up @@ -100,12 +100,12 @@ public JacksonGauge build(boolean flattenAttributes) {
this.withData(data);
this.withEventType(EventType.METRIC.toString());
checkAndSetDefaultValues();
new ParameterValidator().validate(REQUIRED_KEYS, REQUIRED_NON_EMPTY_KEYS, REQUIRED_NON_NULL_KEYS, data);
new ParameterValidator().validate(REQUIRED_KEYS, REQUIRED_NON_EMPTY_KEYS, REQUIRED_NON_NULL_KEYS, (HashMap<String, Object>)data);
return new JacksonGauge(this, flattenAttributes);
}

private void checkAndSetDefaultValues() {
data.computeIfAbsent(ATTRIBUTES_KEY, k -> new HashMap<>());
computeIfAbsent(ATTRIBUTES_KEY, k -> new HashMap<>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public JacksonHistogram.Builder getThis() {
* @since 1.4
*/
public JacksonHistogram.Builder withSum(double sum) {
data.put(SUM_KEY, sum);
put(SUM_KEY, sum);
return this;
}

Expand All @@ -129,7 +129,7 @@ public JacksonHistogram.Builder withSum(double sum) {
*/
public JacksonHistogram.Builder withMin(Double min) {
if (min != null) {
data.put(MIN_KEY, min);
put(MIN_KEY, min);
}
return this;
}
Expand All @@ -142,7 +142,7 @@ public JacksonHistogram.Builder withMin(Double min) {
*/
public JacksonHistogram.Builder withMax(Double max) {
if (max != null) {
data.put(MAX_KEY, max);
put(MAX_KEY, max);
}
return this;
}
Expand All @@ -154,7 +154,7 @@ public JacksonHistogram.Builder withMax(Double max) {
* @since 1.4
*/
public JacksonHistogram.Builder withCount(long count) {
data.put(COUNT_KEY, count);
put(COUNT_KEY, count);
return this;
}

Expand All @@ -165,7 +165,7 @@ public JacksonHistogram.Builder withCount(long count) {
* @since 1.4
*/
public JacksonHistogram.Builder withBucketCount(int bucketCount) {
data.put(BUCKET_COUNTS_KEY, bucketCount);
put(BUCKET_COUNTS_KEY, bucketCount);
return this;
}

Expand All @@ -176,7 +176,7 @@ public JacksonHistogram.Builder withBucketCount(int bucketCount) {
* @since 1.4
*/
public JacksonHistogram.Builder withExplicitBoundsCount(int explicitBoundsCount) {
data.put(EXPLICIT_BOUNDS_COUNT_KEY, explicitBoundsCount);
put(EXPLICIT_BOUNDS_COUNT_KEY, explicitBoundsCount);
return this;
}

Expand All @@ -187,7 +187,7 @@ public JacksonHistogram.Builder withExplicitBoundsCount(int explicitBoundsCount)
* @since 1.4
*/
public JacksonHistogram.Builder withAggregationTemporality(String aggregationTemporality) {
data.put(AGGREGATION_TEMPORALITY_KEY, aggregationTemporality);
put(AGGREGATION_TEMPORALITY_KEY, aggregationTemporality);
return this;
}

Expand All @@ -210,7 +210,7 @@ public JacksonHistogram.Builder withTimeReceived(final Instant timeReceived) {
* @since 1.4
*/
public JacksonHistogram.Builder withBuckets(List<Bucket> buckets) {
data.put(BUCKETS_KEY, buckets);
put(BUCKETS_KEY, buckets);
return this;
}

Expand All @@ -221,7 +221,7 @@ public JacksonHistogram.Builder withBuckets(List<Bucket> buckets) {
* @since 1.4
*/
public JacksonHistogram.Builder withBucketCountsList(List<Long> bucketCountsList) {
data.put(BUCKET_COUNTS_LIST_KEY, bucketCountsList);
put(BUCKET_COUNTS_LIST_KEY, bucketCountsList);
return this;
}

Expand All @@ -232,7 +232,7 @@ public JacksonHistogram.Builder withBucketCountsList(List<Long> bucketCountsList
* @since 1.4
*/
public JacksonHistogram.Builder withExplicitBoundsList(List<Double> explicitBoundsList) {
data.put(EXPLICIT_BOUNDS_KEY, explicitBoundsList);
put(EXPLICIT_BOUNDS_KEY, explicitBoundsList);
return this;
}

Expand All @@ -256,13 +256,13 @@ public JacksonHistogram build(boolean flattenAttributes) {
this.withEventKind(KIND.HISTOGRAM.toString());
this.withEventType(EventType.METRIC.toString());
checkAndSetDefaultValues();
new ParameterValidator().validate(REQUIRED_KEYS, REQUIRED_NON_EMPTY_KEYS, REQUIRED_NON_NULL_KEYS, data);
new ParameterValidator().validate(REQUIRED_KEYS, REQUIRED_NON_EMPTY_KEYS, REQUIRED_NON_NULL_KEYS, (HashMap<String, Object>)data);

return new JacksonHistogram(this, flattenAttributes);
}

private void checkAndSetDefaultValues() {
data.computeIfAbsent(ATTRIBUTES_KEY, k -> new HashMap<>());
computeIfAbsent(ATTRIBUTES_KEY, k -> new HashMap<>());
}

}
Expand Down
Loading
Loading