com.mysql.cj.protocol

## Interface MessageSender<M extends Message>

Type Parameters:
  `M` - Message type

    public interface MessageSender<M extends Message>

This interface provides a facility for sending messages to server. The destination, transmission method, etc are determined by the implementation.

### Method Summary

All Methods Instance Methods Default Methods
`default void` `send(byte[] message, int messageLen, byte messageSequence)` Synchronously send the message to server.
`default void` `send(M message)` Synchronously send the message to server.
`default CompletableFuture<?>` `send(M message, CompletableFuture<?> future, Runnable callback)` Asynchronously write a message with a notification being delivered to `callback` upon completion of write of entire message.
`default void` `setMaxAllowedPacket(int maxAllowedPacket)` Set max allowed packet size.
`default MessageSender<M>` `undecorate()` Return the previous PacketSender instance from the decorators chain or the current PacketSender if it is the first entry in a chain.
`default MessageSender<M>` `undecorateAll()` Return a PacketSender instance free of decorators.

### Method Detail

#### send

    default void send(byte[] message,
                      int messageLen,
                      byte messageSequence)
               throws IOException

Synchronously send the message to server.

Parameters:
  `message` - byte array containing a message
  `messageLen` - length of the message
  `messageSequence` - message sequence index (used in a native protocol)
Throws:
  `IOException` - if an error occurs

#### send

    default void send(M message)

Synchronously send the message to server.

Parameters:
  `message` - `Message` instance

#### send

    default CompletableFuture<?> send(M message,
                                      CompletableFuture<?> future,
                                      Runnable callback)

Asynchronously write a message with a notification being delivered to `callback` upon completion of write of entire message.

Parameters:
  `message` - message extending `Message`
  `future` - a Future returning operation result
  `callback` - a callback to receive notification of when the message is completely written
Returns:
  result

#### setMaxAllowedPacket

    default void setMaxAllowedPacket(int maxAllowedPacket)

Set max allowed packet size.

Parameters:
  `maxAllowedPacket` - max allowed packet size

#### undecorateAll

    default MessageSender<M> undecorateAll()

Return a PacketSender instance free of decorators.

Returns:
  `MessageSender` instance

#### undecorate

    default MessageSender<M> undecorate()

Return the previous PacketSender instance from the decorators chain or the current PacketSender if it is the first entry in a chain.

Returns:
  `MessageSender` instance

Copyright © 2016, 2026, Oracle and/or its affiliates.