Class CompressedPacketSender

java.lang.Object
com.mysql.cj.protocol.a.CompressedPacketSender
All Implemented Interfaces:
MessageSender<NativePacketPayload>

public class CompressedPacketSender
extends java.lang.Object
implements MessageSender<NativePacketPayload>
A MessageSender for the compressed protocol. TODO: add support for pre-allocated buffer for large packets (if there's a demonstrable perf improvement)
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int COMP_HEADER_LENGTH  
    static int MIN_COMPRESS_LEN  
  • Constructor Summary

    Constructors 
    Constructor Description
    CompressedPacketSender​(java.io.BufferedOutputStream outputStream)  
  • Method Summary

    Modifier and Type Method Description
    void send​(byte[] packet, int packetLen, byte packetSequence)
    Packet sender implementation for the compressed MySQL protocol.
    void stop()
    Shut down this packet sender and deallocate any resources.
    MessageSender<NativePacketPayload> undecorate()
    Return the previous PacketSender instance from the decorators chain or the current PacketSender if it is the first entry in a chain.
    MessageSender<NativePacketPayload> undecorateAll()
    Return a PacketSender instance free of decorators.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.mysql.cj.protocol.MessageSender

    send, send, setMaxAllowedPacket
  • Field Details

  • Constructor Details

  • Method Details

    • stop

      public void stop()
      Shut down this packet sender and deallocate any resources.
    • send

      public void send​(byte[] packet, int packetLen, byte packetSequence) throws java.io.IOException
      Packet sender implementation for the compressed MySQL protocol. For compressed transmission of multi-packets, split the packets up in the same way as the uncompressed protocol. We fit up to MAX_PACKET_SIZE bytes of split uncompressed packet, including the header, into an compressed packet. The first packet of the multi-packet is 4 bytes of header and MAX_PACKET_SIZE - 4 bytes of the payload. The next packet must send the remaining four bytes of the payload followed by a new header and payload. If the second split packet is also around MAX_PACKET_SIZE in length, then only MAX_PACKET_SIZE - 4 (from the previous packet) - 4 (for the new header) can be sent. This means the payload will be limited by 8 bytes and this will continue to increase by 4 at every iteration.
      Specified by:
      send in interface MessageSender<NativePacketPayload>
      Parameters:
      packet - data bytes
      packetLen - packet length
      packetSequence - sequence id
      Throws:
      java.io.IOException - if i/o exception occurs
    • undecorateAll

      public MessageSender<NativePacketPayload> undecorateAll()
      Description copied from interface: MessageSender
      Return a PacketSender instance free of decorators.
      Specified by:
      undecorateAll in interface MessageSender<NativePacketPayload>
      Returns:
      MessageSender instance
    • undecorate

      public MessageSender<NativePacketPayload> undecorate()
      Description copied from interface: MessageSender
      Return the previous PacketSender instance from the decorators chain or the current PacketSender if it is the first entry in a chain.
      Specified by:
      undecorate in interface MessageSender<NativePacketPayload>
      Returns:
      MessageSender instance