Interface MessageChannel.Sender<P extends ChannelPayload>

Type Parameters:
P - the payload type this sender dispatches; must extend ChannelPayload
Enclosing interface:
MessageChannel<P extends ChannelPayload>

public static interface MessageChannel.Sender<P extends ChannelPayload>
A target-bound sender created by MessageChannel.to(java.util.Collection) or MessageChannel.toAll(), used to dispatch payloads to the targeted servers.

Obtain a Sender by calling one of the MessageChannel target methods. Send a payload with send(ChannelPayload) for fire-and-forget delivery, or use request(ChannelPayload) for request-response patterns. Optional delivery conditions can be set with requirePlayer(UUID) and whenOnline(UUID).

  • Method Summary

    Modifier and Type
    Method
    Description
    request(P payload)
    Sends a payload and returns a future that completes with the remote server's response, using the default timeout.
    request(P payload, Duration timeout)
    Sends a payload and returns a future that completes with the remote server's response, using a custom timeout.
    Constrains this sender to only execute if the triggering player (if any) is present on the target server at the time of delivery.
    Constrains this sender to only execute if the specified player is present on the target server at the time of delivery.
    send(P payload)
    Sends a payload to the targeted servers without waiting for a response.
    Queues the payload for delivery to the target server when the triggering player (if any) is online.
    whenOnline(UUID player)
    Queues the payload for delivery to the target server when the specified player is online.
  • Method Details

    • send

      CompletableFuture<Void> send(P payload)
      Sends a payload to the targeted servers without waiting for a response.
      Parameters:
      payload - the payload to send; must not be null
      Returns:
      a CompletableFuture<Void> that completes when the payload has been dispatched (not when it has been received or processed by the remote server)
    • request

      CompletableFuture<P> request(P payload)
      Sends a payload and returns a future that completes with the remote server's response, using the default timeout.

      This method is only supported for single-target senders. Invoking it on a multi-target sender throws UnsupportedOperationException.

      Parameters:
      payload - the request payload; must not be null
      Returns:
      a CompletableFuture that completes with the response payload, or completes exceptionally if the default timeout elapses before a response is received
      Throws:
      UnsupportedOperationException - if this sender targets more than one server
      See Also:
    • request

      CompletableFuture<P> request(P payload, Duration timeout)
      Sends a payload and returns a future that completes with the remote server's response, using a custom timeout.

      This method is only supported for single-target senders. Invoking it on a multi-target sender throws UnsupportedOperationException.

      Parameters:
      payload - the request payload; must not be null
      timeout - the maximum duration to wait for a response; must not be null
      Returns:
      a CompletableFuture that completes with the response payload, or completes exceptionally if the timeout elapses
      Throws:
      UnsupportedOperationException - if this sender targets more than one server
      See Also:
    • requirePlayer

      default MessageChannel.Sender<P> requirePlayer(UUID player)
      Constrains this sender to only execute if the specified player is present on the target server at the time of delivery.

      If the player is not present, the command is not delivered to that server. Use whenOnline(UUID) instead if queued delivery when the player connects is desired.

      Parameters:
      player - the UUID of the player whose presence is required; must not be null
      Returns:
      this sender for method chaining
      Throws:
      UnsupportedOperationException - if this sender implementation does not support player-conditioned delivery (the default implementation always throws)
      See Also:
    • requirePlayer

      default MessageChannel.Sender<P> requirePlayer()
      Constrains this sender to only execute if the triggering player (if any) is present on the target server at the time of delivery.

      This is the no-argument variant of requirePlayer(UUID); it uses the player associated with the execution context rather than an explicit UUID.

      Returns:
      this sender for method chaining
      Throws:
      UnsupportedOperationException - if this sender implementation does not support player-conditioned delivery (the default implementation always throws)
      See Also:
    • whenOnline

      default MessageChannel.Sender<P> whenOnline(UUID player)
      Queues the payload for delivery to the target server when the specified player is online.

      Unlike requirePlayer(UUID), which skips delivery if the player is absent, this method queues the payload and delivers it once the player connects to the target server.

      Parameters:
      player - the UUID of the player to wait for; must not be null
      Returns:
      this sender for method chaining
      Throws:
      UnsupportedOperationException - if this sender implementation does not support queued delivery (the default implementation always throws)
      See Also:
    • whenOnline

      default MessageChannel.Sender<P> whenOnline()
      Queues the payload for delivery to the target server when the triggering player (if any) is online.

      This is the no-argument variant of whenOnline(UUID); it uses the player associated with the execution context rather than an explicit UUID.

      Returns:
      this sender for method chaining
      Throws:
      UnsupportedOperationException - if this sender implementation does not support queued delivery (the default implementation always throws)
      See Also: