com.hedera.hapi.block.EndOfStream Maven / Gradle / Ivy
package com.hedera.hapi.block;
import com.hedera.hapi.block.*;
import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.*;
import com.hedera.pbj.runtime.io.buffer.*;
import com.hedera.pbj.runtime.io.stream.*;
import edu.umd.cs.findbugs.annotations.*;
import com.hedera.pbj.runtime.Codec;
import java.util.function.Consumer;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.NonNull;
import static java.util.Objects.requireNonNull;
/**
* A message sent to end a stream.
*
* This response message SHALL be sent from a block node to a block
* stream source system when a `publishBlockStream` stream ends.
* This message SHALL be sent exactly once for each `publishBlockStream`
* call.
* The source system SHALL cease sending block items upon receiving
* this response, and MAY determine the ending state of the stream from
* the `status` enumeration and the `block_number` returned.
* A source system SHOULD verify that the `block_number` value matches the
* last block sent, and SHOULD resend one or more blocks if the value
* here does not match the expected value.
*
* @param status (1) A response code.
*
* This code indicates the reason the stream ended.
* This value MUST be set to a non-default value.
* @param blockNumber (2) The number of the last completed and _verified_ block.
*
* Nodes SHOULD only end a stream after a block state proof to avoid
* the need to resend items.
* If status is a failure code, the source node MUST start a new
* stream at the beginning of the first block _following_ this number
* (e.g. if this is 91827362983, then the new stream must start with
* the _header_ for block 91827362984).
*/
public record EndOfStream(
PublishStreamResponseCode status,
long blockNumber
) {
/** Protobuf codec for reading and writing in protobuf format */
public static final Codec PROTOBUF = new com.hedera.hapi.block.codec.EndOfStreamProtoCodec();
/** JSON codec for reading and writing in JSON format */
public static final JsonCodec JSON = new com.hedera.hapi.block.codec.EndOfStreamJsonCodec();
/** Default instance with all fields set to default values */
public static final EndOfStream DEFAULT = newBuilder().build();
/**
* Create a pre-populated EndOfStream.
*
* @param status (1) A response code.
*
* This code indicates the reason the stream ended.
* This value MUST be set to a non-default value.,
* @param blockNumber (2) The number of the last completed and _verified_ block.
*
* Nodes SHOULD only end a stream after a block state proof to avoid
* the need to resend items.
* If status is a failure code, the source node MUST start a new
* stream at the beginning of the first block _following_ this number
* (e.g. if this is 91827362983, then the new stream must start with
* the _header_ for block 91827362984).
*/
public EndOfStream(PublishStreamResponseCode status, long blockNumber) {
this.status = status;
this.blockNumber = blockNumber;
}
/**
* Override the default hashCode method for
* all other objects to make hashCode
*/
@Override
public int hashCode() {
int result = 1;
if (status != null && !status.equals(DEFAULT.status)) {
result = 31 * result + Integer.hashCode(status.protoOrdinal());
}
if (blockNumber != DEFAULT.blockNumber) {
result = 31 * result + Long.hashCode(blockNumber);
}
long hashCode = result;
// Shifts: 30, 27, 16, 20, 5, 18, 10, 24, 30
hashCode += hashCode << 30;
hashCode ^= hashCode >>> 27;
hashCode += hashCode << 16;
hashCode ^= hashCode >>> 20;
hashCode += hashCode << 5;
hashCode ^= hashCode >>> 18;
hashCode += hashCode << 10;
hashCode ^= hashCode >>> 24;
hashCode += hashCode << 30;
return (int)hashCode;
}
/**
* Override the default equals method for
*/
@Override
public boolean equals(Object that) {
if (that == null || this.getClass() != that.getClass()) {
return false;
}
EndOfStream thatObj = (EndOfStream)that;
if (status == null && thatObj.status != null) {
return false;
}
if (status != null && !status.equals(thatObj.status)) {
return false;
}
if (blockNumber != thatObj.blockNumber) {
return false;
}
return true;
}
/**
* Return a builder for building a copy of this model object. It will be pre-populated with all the data from this
* model object.
*
* @return a pre-populated builder
*/
public Builder copyBuilder() {
return new Builder(status, blockNumber);
}
/**
* Return a new builder for building a model object. This is just a shortcut for new Model.Builder()
.
*
* @return a new builder
*/
public static Builder newBuilder() {
return new Builder();
}
/**
* Builder class for easy creation, ideal for clean code where performance is not critical. In critical performance
* paths use the constructor directly.
*/
public static final class Builder {
private PublishStreamResponseCode status = PublishStreamResponseCode.fromProtobufOrdinal(0);
private long blockNumber = 0;
/**
* Create an empty builder
*/
public Builder() {}
/**
* Create a pre-populated Builder.
*
* @param status (1) A response code.
*
* This code indicates the reason the stream ended.
* This value MUST be set to a non-default value.,
* @param blockNumber (2) The number of the last completed and _verified_ block.
*
* Nodes SHOULD only end a stream after a block state proof to avoid
* the need to resend items.
* If status is a failure code, the source node MUST start a new
* stream at the beginning of the first block _following_ this number
* (e.g. if this is 91827362983, then the new stream must start with
* the _header_ for block 91827362984).
*/
public Builder(PublishStreamResponseCode status, long blockNumber) {
this.status = status;
this.blockNumber = blockNumber;
}
/**
* Build a new model record with data set on builder
*
* @return new model record with data set
*/
public EndOfStream build() {
return new EndOfStream(status, blockNumber);
}
/**
* (1) A response code.
*
* This code indicates the reason the stream ended.
* This value MUST be set to a non-default value.
*
* @param status value to set
* @return builder to continue building with
*/
public Builder status(PublishStreamResponseCode status) {
this.status = status;
return this;
}
/**
* (2) The number of the last completed and _verified_ block.
*
* Nodes SHOULD only end a stream after a block state proof to avoid
* the need to resend items.
* If status is a failure code, the source node MUST start a new
* stream at the beginning of the first block _following_ this number
* (e.g. if this is 91827362983, then the new stream must start with
* the _header_ for block 91827362984).
*
* @param blockNumber value to set
* @return builder to continue building with
*/
public Builder blockNumber(long blockNumber) {
this.blockNumber = blockNumber;
return this;
}
}
}