Record Class PeerMessage

java.lang.Object
java.lang.Record
nl.colorize.multimedialib.renderer.teavm.PeerMessage

public record PeerMessage(String type, String value) extends Record
Data structure for messages received from a peer-to-peer connection. Messages are always in text-based form, even if the underlying protocol is based on binary messages.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Message type for when a new peer has connected.
    static final String
    Message type for when a data message has been received.
    static final String
    Message type for when a previously connected peer has been disconnected, for whatever reason.
    static final String
    Message type used for connection errors.
    static final String
    Message type for when this peer connection has completed initialization.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PeerMessage(String type, String value)
    Creates an instance of a PeerMessage record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    final String
    Returns a string representation of this record class.
    Returns the value of the type record component.
    Returns the value of the value record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • TYPE_INIT

      public static final String TYPE_INIT
      Message type for when this peer connection has completed initialization. The message value is this peer's connection ID, which can be used by other peers to connect.
      See Also:
    • TYPE_CONNECT

      public static final String TYPE_CONNECT
      Message type for when a new peer has connected. The message value is the peer's connection ID.
      See Also:
    • TYPE_DISCONNECT

      public static final String TYPE_DISCONNECT
      Message type for when a previously connected peer has been disconnected, for whatever reason. The message value is the peer's connection ID.
      See Also:
    • TYPE_DATA

      public static final String TYPE_DATA
      Message type for when a data message has been received. The message value is the plain text version of the data that has been received.
      See Also:
    • TYPE_ERROR

      public static final String TYPE_ERROR
      Message type used for connection errors. The message value provides details on the error.
      See Also:
  • Constructor Details

    • PeerMessage

      public PeerMessage(String type, String value)
      Creates an instance of a PeerMessage record class.
      Parameters:
      type - the value for the type record component
      value - the value for the value record component
  • Method Details

    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • type

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

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