MessageSender for the compressed protocol.
Todo
add support for pre-allocated buffer for large packets (if there's a demonstrable perf improvement)
| Modifier and Type | Field and Description |
|---|---|
| public static final int | |
| private byte[] | compressedPacket
Buffer to compress data to. |
| private int | compressedPayloadLen
Length of current compressed packet. |
| private byte | compressedSequenceId
Sequence id of compressed packet. |
| private Deflater | |
| public static final int | |
| private BufferedOutputStream |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | addPayload(byte[]
payload bytes payload, int offset payloadOffset, int length payloadLen)Add and compress the payload into the compressed packet. |
| private void | addUncompressedHeader(byte
sequence id packetSequence, int uncompressed packet length uncompressedPacketLen)Add and compress the header for the raw packet into the compressed packet. |
| private void | |
| private void | |
| public void | send(byte[]
data bytes packet, int packet length packetLen, byte sequence id packetSequence)Overrides default com. Packet sender implementation for the compressed MySQL protocol. |
| private void | |
| public void | |
| public MessageSender | undecorate()
Overrides default com. Return the previous PacketSender instance from the decorators chain or the current PacketSender if it is the first entry in a chain. |
| public MessageSender | undecorateAll()
Overrides default com. Return a PacketSender instance free of decorators. |
| private void | writeCompressedHeader(int
compressed data length compLen, byte sequence id seq, int uncompressed data length uncompLen)Write the compressed packet header. |
| private void | writeUncompressedHeader(int
packet length packetLen, byte sequence id packetSequence)Write an uncompressed packet header. |
| COMP_HEADER_LENGTH | back to summary |
|---|---|
| public static final int COMP_HEADER_LENGTH | |
| compressedPacket | back to summary |
|---|---|
| private byte[] compressedPacket Buffer to compress data to. Used only across one send() invocation. | |
| compressedPayloadLen | back to summary |
|---|---|
| private int compressedPayloadLen Length of current compressed packet. | |
| compressedSequenceId | back to summary |
|---|---|
| private byte compressedSequenceId Sequence id of compressed packet. Used only across one send() invocation. | |
| deflater | back to summary |
|---|---|
| private Deflater deflater | |
| MIN_COMPRESS_LEN | back to summary |
|---|---|
| public static final int MIN_COMPRESS_LEN | |
| outputStream | back to summary |
|---|---|
| private BufferedOutputStream outputStream | |
| CompressedPacketSender | back to summary |
|---|---|
| public CompressedPacketSender(BufferedOutputStream outputStream) | |
| addPayload | back to summary |
|---|---|
| private void addPayload(byte[] payload, int payloadOffset, int payloadLen) Add and compress the payload into the compressed packet.
| |
| addUncompressedHeader | back to summary |
|---|---|
| private void addUncompressedHeader(byte packetSequence, int uncompressedPacketLen) Add and compress the header for the raw packet into the compressed packet.
| |
| completeCompression | back to summary |
|---|---|
| private void completeCompression() Complete compression of the current payload contents to the compressed packet. | |
| resetPacket | back to summary |
|---|---|
| private void resetPacket() | |
| send | back to summary |
|---|---|
| public void send(byte[] packet, int packetLen, byte packetSequence) throws IOException Overrides default com. 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.
| |
| sendCompressedPacket | back to summary |
|---|---|
| private void sendCompressedPacket(int uncompressedPayloadLen) throws IOException Send a compressed packet.
| |
| stop | back to summary |
|---|---|
| public void stop() Shut down this packet sender and deallocate any resources. | |
| undecorate | back to summary |
|---|---|
| public MessageSender Overrides default com. Doc from com. Return the previous PacketSender instance from the decorators chain or the current PacketSender if it is the first entry in a chain.
| |
| undecorateAll | back to summary |
|---|---|
| public MessageSender Overrides default com. Doc from com. Return a PacketSender instance free of decorators.
| |
| writeCompressedHeader | back to summary |
|---|---|
| private void writeCompressedHeader(int compLen, byte seq, int uncompLen) throws IOException Write the compressed packet header.
| |
| writeUncompressedHeader | back to summary |
|---|---|
| private void writeUncompressedHeader(int packetLen, byte packetSequence) throws IOException Write an uncompressed packet header.
| |