io.leoplatform.sdk.payload.SimplePayload Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leo-api Show documentation
Show all versions of leo-api Show documentation
SDK for LEO Insights platform
The newest version!
package io.leoplatform.sdk.payload;
import javax.json.JsonObject;
import java.time.Instant;
import java.util.Objects;
import java.util.UUID;
public class SimplePayload implements EventPayload {
private final String id;
private final Instant eventTime;
private final JsonObject payload;
private final StreamCorrelation streamCorrelation;
public SimplePayload(JsonObject payload) {
this(Instant.now(), payload);
}
public SimplePayload(String id, JsonObject payload) {
this(id, Instant.now(), payload, null);
}
public SimplePayload(Instant eventTime, JsonObject payload) {
this(UUID.randomUUID().toString(), eventTime, payload, null);
}
public SimplePayload(String id, Instant eventTime, JsonObject payload, StreamCorrelation streamCorrelation) {
this.id = id;
this.eventTime = eventTime;
this.payload = payload;
this.streamCorrelation = streamCorrelation;
}
/**
* A unique identifier for this payload. This value may be used to omit duplicate payloads
* as they are being batched to the LEO bus.
*
* @return The unique ID given, or a {@code String} {@link UUID} generated by the SDK
*/
@Override
public String id() {
return id;
}
/**
* An optional, user-supplied claim indicating when this payload was originally created.
* This typically relates to a creation date/time in a persistent storage system.
* @return The original creation time in epoch milliseconds
*/
@Override
public Instant eventTime() {
return eventTime;
}
/**
* Metadata related to the contents of the payload allowing the entities to be traced back to their
* original source.
*
* @return A {@link StreamCorrelation} instance to help identify the payload's origin
*/
@Override
public StreamCorrelation streamCorrelation() {
return streamCorrelation;
}
/**
* A JSON object to be loaded to the LEO bus. There are typically limitations on the size of this
* value based on the destination within the bus. This value is serialized (and typically gzipped)
* before load.
* @return A {@link JsonObject} to be loaded onto the LEO bus
*/
@Override
public JsonObject payload() {
return payload;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SimplePayload that = (SimplePayload) o;
return Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return String.format("SimplePayload{id='%s', eventTime=%s, payload=%s}", id, eventTime, payload);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy