Module convex.peer
Package convex.net

Class Message

java.lang.Object
convex.net.Message

public class Message extends Object

Class representing a message to / from a specific connection

Encapsulates both message content and a means of return communication

.

This class is an immutable data structure, but NOT a representable on-chain data structure, as it is part of the peer protocol layer.

Messages may contain a Payload, which can be any Data Value.

  • Field Details

    • log

      protected static final org.slf4j.Logger log
    • payload

      protected ACell payload
    • messageData

      protected Blob messageData
    • type

      protected MessageType type
    • returnHandler

      protected Predicate<Message> returnHandler
  • Constructor Details

  • Method Details

    • create

      public static Message create(Connection conn, MessageType type, Blob data)
    • create

      public static Message create(MessageType type, ACell payload)
    • create

      public static Message create(MessageType type, ACell payload, Blob data)
    • createDataResponse

      public static Message createDataResponse(CVMLong id, ACell... cells)
    • createDataRequest

      public static Message createDataRequest(CVMLong id, Hash... hashes)
    • createBelief

      public static Message createBelief(Belief belief)
    • createBeliefRequest

      public static Message createBeliefRequest()
      Create a Belief request message
      Returns:
      Message instance
    • createChallenge

      public static Message createChallenge(SignedData<ACell> challenge)
    • createResponse

      public static Message createResponse(SignedData<ACell> response)
    • createGoodBye

      public static Message createGoodBye()
    • getPayload

      public <T extends ACell> T getPayload() throws BadFormatException
      Throws:
      BadFormatException
    • getMessageData

      public Blob getMessageData()
      Gets the encoded data for this message. Generates a single cell encoding if required.
      Returns:
      Blob containing message data
    • getType

      public MessageType getType()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • getID

      public CVMLong getID()
      Gets the message ID for correlation, assuming this message type supports IDs.
      Returns:
      Message ID, or null if the message does not have a message ID
    • withID

      public Message withID(CVMLong id)
      Sets the message ID, if supported
      Parameters:
      id - ID to set for message
      Returns:
      Message with updated ID, or null if message does not support IDs
    • returnResult

      public boolean returnResult(Result res)
      Reports a result back to the originator of the message. Will set a Result ID if necessary.
      Parameters:
      res - Result record
      Returns:
      True if reported successfully, false otherwise
    • returnMessage

      public boolean returnMessage(Message m)
      Returns a message back to the originator of the message. Will set response ID if necessary.
      Parameters:
      m - Message
      Returns:
      True if sent successfully, false otherwise
    • hasData

      public boolean hasData()
    • createResult

      public static Message createResult(Result res)
    • createResult

      public static Message createResult(CVMLong id, ACell value, ACell error)
    • closeConnection

      public void closeConnection()
      Closes any connection associated with this message, probably because of bad behaviour
    • makeDataResponse

      public Message makeDataResponse(AStore store) throws BadFormatException
      Throws:
      BadFormatException
    • toResult

      public Result toResult()
    • create

      public static Message create(MessageType type, ACell payload, Predicate<Message> handler)
      Create an instance with the given message data
      Parameters:
      type - Message type
      payload - Message payload
      handler - Handler for Results
      Returns:
      New MessageLocal instance