Record Class ProtocolEnvelope

java.lang.Object
java.lang.Record
org.j7m.middleware.transport.api.ProtocolEnvelope
Record Components:
protocolVersion - supported major protocol version (currently 1)
requestId - stable idempotency/correlation key
schemaId - registered payload schema identifier
schemaVersion - positive payload version
deadline - absolute UTC execution deadline
traceContext - bounded public trace metadata, containing no credentials
cancellation - whether the request cancels the referenced operation
nodeId - claimed sender bound to authenticated transport identity at dispatch
payload - encoded payload, limited to 1 MiB and defensively copied

public record ProtocolEnvelope(int protocolVersion, String requestId, String schemaId, int schemaVersion, Instant deadline, Map<String,String> traceContext, boolean cancellation, String nodeId, byte[] payload) extends Record
Bounded transport-neutral command envelope. Authentication is supplied by the established transport, never inferred from the claimed node identity. Immutable and safe to share across threads.
  • Constructor Details

    • ProtocolEnvelope

      public ProtocolEnvelope(int protocolVersion, String requestId, String schemaId, int schemaVersion, Instant deadline, Map<String,String> traceContext, boolean cancellation, String nodeId, byte[] payload)
      Snapshots mutable input and rejects unsupported protocol versions or size limits before dispatch.
      Throws:
      IllegalArgumentException - if any identity, version or size is invalid
  • Method Details

    • payload

      public byte[] payload()
      Returns an independent copy of the bounded encoded payload.
      Returns:
      copied payload bytes
    • validateForDispatch

      public void validateForDispatch(String authenticatedNode, Clock clock)
      Validates identity and deadline before invoking handlers or mutating state.
      Parameters:
      authenticatedNode - trusted transport-authenticated peer identity
      clock - injected UTC clock
      Throws:
      MiddlewareException - if identity mismatches or deadline has expired
    • 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.
    • protocolVersion

      public int protocolVersion()
      Returns the value of the protocolVersion record component.
      Returns:
      the value of the protocolVersion record component
    • requestId

      public String requestId()
      Returns the value of the requestId record component.
      Returns:
      the value of the requestId record component
    • schemaId

      public String schemaId()
      Returns the value of the schemaId record component.
      Returns:
      the value of the schemaId record component
    • schemaVersion

      public int schemaVersion()
      Returns the value of the schemaVersion record component.
      Returns:
      the value of the schemaVersion record component
    • deadline

      public Instant deadline()
      Returns the value of the deadline record component.
      Returns:
      the value of the deadline record component
    • traceContext

      public Map<String,String> traceContext()
      Returns the value of the traceContext record component.
      Returns:
      the value of the traceContext record component
    • cancellation

      public boolean cancellation()
      Returns the value of the cancellation record component.
      Returns:
      the value of the cancellation record component
    • nodeId

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