Record Class BatchOperation

java.lang.Object
java.lang.Record
com.loomcache.common.protocol.BatchOperation
Record Components:
opcode - the MessageType code for the individual operation
structureName - the target data structure name (e.g. "users", "order-count")
key - operation key (nullable for keyless ops like counter.increment)
value - operation value (nullable for read-only or keyless ops)

public record BatchOperation(byte opcode, String structureName, byte[] key, byte[] value) extends Record
A single operation within a batch (see LoomBatch in the client module).

Each BatchOperation encodes one data-structure command (e.g. MAP_PUT on "users") together with its key/value payload. A list of these is serialized into a single MessageType.BATCH_EXECUTE message and sent to the server for execution.

Wire format per operation:

  [1 byte  opcode]
  [2 bytes structureNameLen][structureName bytes]
  [2 bytes keyLen][key bytes]            — may be 0
  [4 bytes valueLen][value bytes]        — may be 0
Since:
1.3
  • Constructor Details

    • BatchOperation

      public BatchOperation(byte opcode, String structureName, byte @Nullable [] key, byte @Nullable [] value)
      Creates an instance of a BatchOperation record class.
      Parameters:
      opcode - the value for the opcode record component
      structureName - the value for the structureName record component
      key - the value for the key record component
      value - the value for the value record component
  • Method Details

    • key

      public byte[] key()
      Returns a clone of the key bytes (defensive copy).
      Returns:
      cloned key bytes (never null; empty array if not set)
    • value

      public byte[] value()
      Returns a clone of the value bytes (defensive copy).
      Returns:
      cloned value bytes (never null; empty array if not set)
    • mapPut

      public static BatchOperation mapPut(String mapName, String key, byte[] value)
      Build a MAP_PUT batch operation.

      UTF-8 only: value bytes must be valid UTF-8. Non-UTF-8 payloads are rejected by the server with RESPONSE_ERROR; use the dedicated single-op map API for binary blobs.

    • mapDelete

      public static BatchOperation mapDelete(String mapName, String key)
    • mapPutIfAbsent

      public static BatchOperation mapPutIfAbsent(String mapName, String key, byte[] value)
      Build a MAP_PUT_IF_ABSENT batch operation.

      UTF-8 only: value bytes must be valid UTF-8. Non-UTF-8 payloads are rejected by the server with RESPONSE_ERROR; use the dedicated single-op map API for binary blobs.

    • setAdd

      public static BatchOperation setAdd(String setName, String member)
    • setRemove

      public static BatchOperation setRemove(String setName, String member)
    • queueOffer

      public static BatchOperation queueOffer(String queueName, byte[] value)
      Build a QUEUE_OFFER batch operation.

      UTF-8 only: value bytes must be valid UTF-8. Non-UTF-8 payloads are rejected by the server with RESPONSE_ERROR; use the dedicated single-op queue API for binary blobs.

    • serializeBatch

      public static byte[] serializeBatch(List<BatchOperation> ops, boolean atomic, boolean replicated)
      Serialize a list of operations into a byte array for the batch message body.

      Format:

        [1 byte  flags: bit0=atomic, bit1=replicated]
        [4 bytes operation count]
        [operations...]
      
    • deserializeBatch

      public static BatchOperation.DeserializedBatch deserializeBatch(byte[] data)
      Deserialize a batch from the message body.
      Returns:
      a BatchOperation.DeserializedBatch containing flags and operations
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • opcode

      public byte opcode()
      Returns the value of the opcode record component.
      Returns:
      the value of the opcode record component
    • structureName

      public String structureName()
      Returns the value of the structureName record component.
      Returns:
      the value of the structureName record component