Package convex.core

Class Result

All Implemented Interfaces:
IValidated, IWriteable, Map<Keyword,​ACell>

public final class Result extends ARecordGeneric
Class representing the result of a Query or Transaction. A Result is typically used to communicate the outcome of a Query or a Transaction from a Peer to a Client.
  • Method Details

    • create

      public static Result create(CVMLong id, ACell value, ACell errorCode, ACell trace)
      Create a Result
      Parameters:
      id - ID of Result message
      value - Result Value
      errorCode - Error Code (may be null for success)
      trace - Error Trace
      Returns:
      Result instance
    • create

      public static Result create(CVMLong id, ACell value, ACell errorCode)
      Create a Result
      Parameters:
      id - ID of Result message
      value - Result Value
      errorCode - Error Code (may be null for success)
      Returns:
      Result instance
    • create

      public static Result create(CVMLong id, ACell value)
      Create a Result
      Parameters:
      id - ID of Result message
      value - Result Value
      Returns:
      Result instance
    • getID

      public ACell getID()
      Returns the message ID for this result. Message ID is an arbitrary ID assigned by a client requesting a transaction.
      Returns:
      ID from this result
    • getValue

      public <T extends ACell> T getValue()
      Returns the value for this result. The value is the result of transaction execution (may be an error message if the transaction failed)
      Type Parameters:
      T - Type of Value
      Returns:
      ID from this result
    • getTrace

      public AVector<AString> getTrace()
      Returns the stack trace for this result. May be null
      Returns:
      ID from this result
    • getErrorCode

      public ACell getErrorCode()
      Returns the Error Code from this Result. Normally this should be a Keyword. Will be null if no error occurred.
      Returns:
      ID from this result
    • values

      public AVector<ACell> values()
      Description copied from class: ARecord
      Gets a vector of values for this record, in format-determined order
      Specified by:
      values in interface Map<Keyword,​ACell>
      Overrides:
      values in class ARecordGeneric
      Returns:
      Vector of Values
    • withValues

      protected Result withValues(AVector<ACell> newValues)
      Description copied from class: ARecordGeneric
      Updates the record with a new set of values. Returns this if and only if values vector is identical.
      Specified by:
      withValues in class ARecordGeneric
      Parameters:
      newValues - New values to use
      Returns:
      Updated Record
    • validateCell

      public void validateCell() throws InvalidDataException
      Description copied from class: ACell
      Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.
      Overrides:
      validateCell in class ARecordGeneric
      Throws:
      InvalidDataException - If the Cell is invalid
    • encode

      public int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • read

      public static Result read(ByteBuffer bb) throws BadFormatException
      Reads a Result from a ByteBuffer encoding. Assumes tag byte already read.
      Parameters:
      bb - ByteBuffer to read from
      Returns:
      The Result read
      Throws:
      BadFormatException - If a Result could not be read
    • isError

      public boolean isError()
      Tests is the Result represents an Error
      Returns:
      True if error, false otherwise
    • fromContext

      public static Result fromContext(CVMLong id, Context<?> ctx)
      Constructs a Result from a Context
      Parameters:
      id - Id for Result
      ctx - Context
      Returns:
      New Result instance
    • withID

      public Result withID(ACell id)
      Updates result with a given message ID. Used to tag Results for return to Clients
      Parameters:
      id - New Result message ID
      Returns:
      Updated Result
    • getTag

      public byte getTag()
      Description copied from class: ARecord
      Gets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding.
      Specified by:
      getTag in class ARecordGeneric
      Returns:
      Record tag byte