Record Class SocketExchange

java.lang.Object
java.lang.Record
de.craftsblock.craftsnet.api.websocket.SocketExchange
All Implemented Interfaces:
BaseExchange, AutoCloseable

public record SocketExchange(@NotNull ProtocolVersion protocolVersion, @NotNull WebSocketServer server, @NotNull WebSocketClient client) extends Record implements BaseExchange
The SocketExchange record represents an exchange object that provides a way to interact with the WebSocket server and client within the context of a WebSocket connection. It allows sending broadcast messages to all clients connected to the same WebSocket path.
Since:
2.1.1-SNAPSHOT
See Also:
  • Constructor Details

    • SocketExchange

      public SocketExchange(@NotNull @NotNull ProtocolVersion protocolVersion, @NotNull @NotNull WebSocketServer server, @NotNull @NotNull WebSocketClient client)
      Creates an instance of a SocketExchange record class.
      Parameters:
      protocolVersion - the value for the protocolVersion record component
      server - the value for the server record component
      client - the value for the client record component
  • Method Details

    • server

      public WebSocketServer server()
      Gets the WebSocketServer object associated with this exchange the websocket client connected to.
      Returns:
      The WebSocketServer object.
    • client

      public WebSocketClient client()
      Gets the WebSocketClient object associated with this exchange representing the websocket connection.
      Returns:
      The WebSocketClient object.
    • broadcast

      public void broadcast(String data)
      Broadcasts the given data to all WebSocket clients connected to the same path as the current client. If the current client does not have a WebSocket path associated, the broadcast is not performed.
      Parameters:
      data - The data to be broadcasted to the WebSocket clients.
    • close

      public void close() throws Exception
      Performs last actions before the exchange is closed.
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • 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.
    • protocolVersion

      @NotNull public @NotNull ProtocolVersion protocolVersion()
      Returns the value of the protocolVersion record component.
      Specified by:
      protocolVersion in interface BaseExchange
      Returns:
      the value of the protocolVersion record component