Top Description Fields Constructors Methods
com.mysql.cj.protocol.a

public Class CompressedPacketSender

extends Object
implements MessageSender<NativePacketPayload>
Class Inheritance
All Implemented Interfaces
com.mysql.cj.protocol.MessageSender
Imports
java.io.BufferedOutputStream, .IOException, java.util.zip.Deflater, com.mysql.cj.protocol.MessageSender

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

Modifier and TypeField 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

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod 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
completeCompression()

Complete compression of the current payload contents to the compressed packet.

private void
public void
send(byte[]
data bytes
packet
,
int
packet length
packetLen
,
byte
sequence id
packetSequence
)

Overrides default com.mysql.cj.protocol.MessageSender.send.

Packet sender implementation for the compressed MySQL protocol.

private void
sendCompressedPacket(int
uncompressed data length
uncompressedPayloadLen
)

Send a compressed packet.

public void
stop()

Shut down this packet sender and deallocate any resources.

public MessageSender<NativePacketPayload>
undecorate()

Overrides default com.mysql.cj.protocol.MessageSender.undecorate.

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

public MessageSender<NativePacketPayload>
undecorateAll()

Overrides default com.mysql.cj.protocol.MessageSender.undecorateAll.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COMP_HEADER_LENGTHback to summary
public static final int COMP_HEADER_LENGTH
compressedPacketback to summary
private byte[] compressedPacket

Buffer to compress data to. Used only across one send() invocation.

compressedPayloadLenback to summary
private int compressedPayloadLen

Length of current compressed packet.

compressedSequenceIdback to summary
private byte compressedSequenceId

Sequence id of compressed packet. Used only across one send() invocation.

deflaterback to summary
private Deflater deflater
MIN_COMPRESS_LENback to summary
public static final int MIN_COMPRESS_LEN
outputStreamback to summary
private BufferedOutputStream outputStream

Constructor Detail

CompressedPacketSenderback to summary
public CompressedPacketSender(BufferedOutputStream outputStream)

Method Detail

addPayloadback to summary
private void addPayload(byte[] payload, int payloadOffset, int payloadLen)

Add and compress the payload into the compressed packet.

Parameters
payload:byte[]

payload bytes

payloadOffset:int

offset

payloadLen:int

length

addUncompressedHeaderback to summary
private void addUncompressedHeader(byte packetSequence, int uncompressedPacketLen)

Add and compress the header for the raw packet into the compressed packet.

Parameters
packetSequence:byte

sequence id

uncompressedPacketLen:int

uncompressed packet length

completeCompressionback to summary
private void completeCompression()

Complete compression of the current payload contents to the compressed packet.

resetPacketback to summary
private void resetPacket()
sendback to summary
public void send(byte[] packet, int packetLen, byte packetSequence) throws IOException

Overrides default com.mysql.cj.protocol.MessageSender.send.

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.

Parameters
packet:byte[]

data bytes

packetLen:int

packet length

packetSequence:byte

sequence id

Annotations
@Override
Exceptions
IOException:
if i/o exception occurs
sendCompressedPacketback to summary
private void sendCompressedPacket(int uncompressedPayloadLen) throws IOException

Send a compressed packet.

Parameters
uncompressedPayloadLen:int

uncompressed data length

Exceptions
IOException:
if write exception occurs
stopback to summary
public void stop()

Shut down this packet sender and deallocate any resources.

undecorateback to summary
public MessageSender<NativePacketPayload> undecorate()

Overrides default com.mysql.cj.protocol.MessageSender.undecorate.

Doc from com.mysql.cj.protocol.MessageSender.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<NativePacketPayload>

MessageSender instance

Annotations
@Override
undecorateAllback to summary
public MessageSender<NativePacketPayload> undecorateAll()

Overrides default com.mysql.cj.protocol.MessageSender.undecorateAll.

Doc from com.mysql.cj.protocol.MessageSender.undecorateAll.

Return a PacketSender instance free of decorators.

Returns:MessageSender<NativePacketPayload>

MessageSender instance

Annotations
@Override
writeCompressedHeaderback to summary
private void writeCompressedHeader(int compLen, byte seq, int uncompLen) throws IOException

Write the compressed packet header.

Parameters
compLen:int

compressed data length

seq:byte

sequence id

uncompLen:int

uncompressed data length

Exceptions
IOException:
if write exception occurs
writeUncompressedHeaderback to summary
private void writeUncompressedHeader(int packetLen, byte packetSequence) throws IOException

Write an uncompressed packet header.

Parameters
packetLen:int

packet length

packetSequence:byte

sequence id

Exceptions
IOException:
if write exception occurs