Class ImmutableRecord<T extends RecordValue>

java.lang.Object
io.camunda.zeebe.protocol.record.ImmutableRecord<T>
All Implemented Interfaces:
JsonSerializable, Record<T>

public final class ImmutableRecord<T extends RecordValue> extends Object implements Record<T>
Immutable implementation of Record.

Use the builder to create immutable instances: ImmutableRecord.builder().

  • Method Details

    • getPosition

      public long getPosition()
      Retrieves the position of the record. Positions are locally unique to the partition, and monotonically increasing. Records are then ordered on the partition by their positions, i.e. lower position means the record was published earlier.
      Specified by:
      getPosition in interface Record<T extends RecordValue>
      Returns:
      position the record
    • getSourceRecordPosition

      public long getSourceRecordPosition()
      Returns the position of the source record. The source record denotes the record which caused the current record. It can be unset (meaning there is no source record), at which point the position returned here will be -1. Anything >= 0 implies a source record.
      Specified by:
      getSourceRecordPosition in interface Record<T extends RecordValue>
      Returns:
      position of the source record
    • getKey

      public long getKey()
      Retrieves the key of the record.

      Multiple records can have the same key if they belongs to the same logical entity. Keys are unique for the combination of partition and record type.

      Specified by:
      getKey in interface Record<T extends RecordValue>
      Returns:
      the key of the record
    • getTimestamp

      public long getTimestamp()
      Specified by:
      getTimestamp in interface Record<T extends RecordValue>
      Returns:
      the unix timestamp at which the record was published on the partition.
    • getIntent

      public Intent getIntent()
      Specified by:
      getIntent in interface Record<T extends RecordValue>
      Returns:
      the intent of the record
    • getPartitionId

      public int getPartitionId()
      Specified by:
      getPartitionId in interface Record<T extends RecordValue>
      Returns:
      the partition ID on which the record was published
    • getRecordType

      public RecordType getRecordType()
      Specified by:
      getRecordType in interface Record<T extends RecordValue>
      Returns:
      the type of the record (event, command or command rejection)
    • getRejectionType

      public RejectionType getRejectionType()
      Specified by:
      getRejectionType in interface Record<T extends RecordValue>
      Returns:
      the type of rejection if getRecordType() returns RecordType.COMMAND_REJECTION or else null.
    • getRejectionReason

      public String getRejectionReason()
      Specified by:
      getRejectionReason in interface Record<T extends RecordValue>
      Returns:
      the reason why a command was rejected if getRecordType() returns RecordType.COMMAND_REJECTION or else null.
    • getBrokerVersion

      public String getBrokerVersion()
      Specified by:
      getBrokerVersion in interface Record<T extends RecordValue>
      Returns:
      the version of the broker that wrote this record
    • getAuthorizations

      public Map<String,Object> getAuthorizations()
      Provides the authorization data of the user the triggered the creation of this record. The following entries may be available:
      • Key: authorized_tenants; Value: a List of Strings defining the user's authorized tenants.
      Specified by:
      getAuthorizations in interface Record<T extends RecordValue>
      Returns:
      a Map of authorization data for this record or an empty Map if not set.
    • getRecordVersion

      public int getRecordVersion()
      A record version is an integer starting from 1. The version of a record is defined when it is written. It allows different versions of the same record to be processed or applied differently.

      For example, it allows us to apply an older event in the same way as when it was originally written, while allowing newer events to be applied differently.

      Specified by:
      getRecordVersion in interface Record<T extends RecordValue>
      Returns:
      the version of the record when written
    • getValueType

      public ValueType getValueType()
      Specified by:
      getValueType in interface Record<T extends RecordValue>
      Returns:
      the type of the record (e.g. job, process, process instance, etc.)
    • getValue

      public T getValue()
      Returns the raw value of the record, which should implement one of the interfaces in the io.camunda.zeebe.protocol.record.value package.

      The record value is essentially the record specific data, e.g. for a process instance creation event, it would contain information relevant to the process instance being created.

      Specified by:
      getValue in interface Record<T extends RecordValue>
      Returns:
      record value
    • getOperationReference

      public long getOperationReference()
      The operationReference is an id passed from clients to correlate operations with resulted records
      Specified by:
      getOperationReference in interface Record<T extends RecordValue>
      Returns:
      the reference for the operation that produced this record
    • withPosition

      public final ImmutableRecord<T> withPosition(long value)
      Copy the current immutable object by setting a value for the position attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for position
      Returns:
      A modified copy of the this object
    • withSourceRecordPosition

      public final ImmutableRecord<T> withSourceRecordPosition(long value)
      Copy the current immutable object by setting a value for the sourceRecordPosition attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for sourceRecordPosition
      Returns:
      A modified copy of the this object
    • withKey

      public final ImmutableRecord<T> withKey(long value)
      Copy the current immutable object by setting a value for the key attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for key
      Returns:
      A modified copy of the this object
    • withTimestamp

      public final ImmutableRecord<T> withTimestamp(long value)
      Copy the current immutable object by setting a value for the timestamp attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for timestamp
      Returns:
      A modified copy of the this object
    • withIntent

      public final ImmutableRecord<T> withIntent(Intent value)
      Copy the current immutable object by setting a value for the intent attribute. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for intent (can be null)
      Returns:
      A modified copy of the this object
    • withPartitionId

      public final ImmutableRecord<T> withPartitionId(int value)
      Copy the current immutable object by setting a value for the partitionId attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for partitionId
      Returns:
      A modified copy of the this object
    • withRecordType

      public final ImmutableRecord<T> withRecordType(RecordType value)
      Copy the current immutable object by setting a value for the recordType attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for recordType (can be null)
      Returns:
      A modified copy of the this object
    • withRejectionType

      public final ImmutableRecord<T> withRejectionType(RejectionType value)
      Copy the current immutable object by setting a value for the rejectionType attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for rejectionType (can be null)
      Returns:
      A modified copy of the this object
    • withRejectionReason

      public final ImmutableRecord<T> withRejectionReason(String value)
      Copy the current immutable object by setting a value for the rejectionReason attribute. An equals check used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for rejectionReason (can be null)
      Returns:
      A modified copy of the this object
    • withBrokerVersion

      public final ImmutableRecord<T> withBrokerVersion(String value)
      Copy the current immutable object by setting a value for the brokerVersion attribute. An equals check used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for brokerVersion (can be null)
      Returns:
      A modified copy of the this object
    • withAuthorizations

      public final ImmutableRecord<T> withAuthorizations(Map<String,? extends Object> entries)
      Copy the current immutable object by replacing the authorizations map with the specified map. Nulls are not permitted as keys or values. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      entries - The entries to be added to the authorizations map
      Returns:
      A modified copy of this object
    • withRecordVersion

      public final ImmutableRecord<T> withRecordVersion(int value)
      Copy the current immutable object by setting a value for the recordVersion attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for recordVersion
      Returns:
      A modified copy of the this object
    • withValueType

      public final ImmutableRecord<T> withValueType(ValueType value)
      Copy the current immutable object by setting a value for the valueType attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for valueType (can be null)
      Returns:
      A modified copy of the this object
    • withValue

      public final ImmutableRecord<T> withValue(T value)
      Copy the current immutable object by setting a value for the value attribute. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for value (can be null)
      Returns:
      A modified copy of the this object
    • withOperationReference

      public final ImmutableRecord<T> withOperationReference(long value)
      Copy the current immutable object by setting a value for the operationReference attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for operationReference
      Returns:
      A modified copy of the this object
    • equals

      public boolean equals(Object another)
      This instance is equal to all instances of ImmutableRecord that have equal attribute values.
      Overrides:
      equals in class Object
      Returns:
      true if this is equal to another instance
    • hashCode

      public int hashCode()
      Returns a lazily computed hash code from attributes: position, sourceRecordPosition, key, timestamp, intent, partitionId, recordType, rejectionType, rejectionReason, brokerVersion, authorizations, recordVersion, valueType, value, operationReference.
      Overrides:
      hashCode in class Object
      Returns:
      hashCode value
    • toString

      public String toString()
      Prints the immutable value Record with attribute values.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the value
    • copyOf

      public static <T extends RecordValue> ImmutableRecord<T> copyOf(Record<T> instance)
      Creates an immutable copy of a Record value. Uses accessors to get values to initialize the new immutable instance. If an instance is already immutable, it is returned as is.
      Type Parameters:
      T - generic parameter T
      Parameters:
      instance - The instance to copy
      Returns:
      A copied immutable Record instance
    • builder

      public static <T extends RecordValue> ImmutableRecord.Builder<T> builder()
      Creates a builder for ImmutableRecord.
       ImmutableRecord.&lt;T&gt;builder()
          .withPosition(long) // optional position
          .withSourceRecordPosition(long) // optional sourceRecordPosition
          .withKey(long) // optional key
          .withTimestamp(long) // optional timestamp
          .withIntent(io.camunda.zeebe.protocol.record.intent.Intent | null) // nullable intent
          .withPartitionId(int) // optional partitionId
          .withRecordType(io.camunda.zeebe.protocol.record.RecordType | null) // nullable recordType
          .withRejectionType(io.camunda.zeebe.protocol.record.RejectionType | null) // nullable rejectionType
          .withRejectionReason(String | null) // nullable rejectionReason
          .withBrokerVersion(String | null) // nullable brokerVersion
          .putAuthorization|putAllAuthorizations(String => Object) // authorizations mappings
          .withRecordVersion(int) // optional recordVersion
          .withValueType(io.camunda.zeebe.protocol.record.ValueType | null) // nullable valueType
          .withValue(T | null) // nullable value
          .withOperationReference(long) // optional operationReference
          .build();
       
      Type Parameters:
      T - generic parameter T
      Returns:
      A new ImmutableRecord builder