Class GzipInterceptor
java.lang.Object
org.apache.catalina.tribes.group.ChannelInterceptorBase
org.apache.catalina.tribes.group.interceptors.GzipInterceptor
- All Implemented Interfaces:
ChannelInterceptor, GzipInterceptorMBean, Heartbeat, MembershipListener
Channel interceptor that compresses messages using GZIP before transmission and decompresses
received messages. This reduces bandwidth usage for cluster communication.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelInterceptor
ChannelInterceptor.InterceptorEvent -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault buffer size for compression/decompression operations.static final intDefault option flag to enable compression.protected static final StringManagerStringManager for this class.Fields inherited from class ChannelInterceptorBase
optionFlag -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]compress(byte[] data) Compresses the given data using GZIP compression.static byte[]decompress(byte[] data) Decompresses the given data using GZIP decompression.longReturns the total compressed received data size in bytes.longReturns the total compressed transmitted data size in bytes.intReturns the minimum payload size for compression to be enabled.intgetCount()Returns the total message count.intReturns the count of compressed received messages.intReturns the count of compressed transmitted messages.intReturns the count of uncompressed received messages.intReturns the count of uncompressed transmitted messages.intReturns the number of messages between statistics reports being written to the log.longReturns the total received data size in bytes.longReturns the total transmitted data size in bytes.booleanReturns whether the interceptor is configured to collect statistics.longReturns the total uncompressed received data size in bytes.longReturns the total uncompressed transmitted data size in bytes.voidThemessageReceivedis invoked when a message is received.voidreport()Writes the current statistics report to the log.voidreset()Resets all statistics counters to zero.voidsendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) ThesendMessagemethod is called when a message is being sent to one more destinations.voidsetCompressionMinSize(int compressionMinSize) Set the minimum payload size for compression to be enabled.voidsetInterval(int interval) If statistics collection is enabled, set the number of messages between statistics reports being written to the log.voidsetStatsEnabled(boolean statsEnabled) Configure whether the interceptor collects statistics.Methods inherited from class ChannelInterceptorBase
fireInterceptorEvent, getChannel, getLocalMember, getMember, getMembers, getNext, getOptionFlag, getPrevious, hasMembers, heartbeat, memberAdded, memberDisappeared, okToProcess, setChannel, setNext, setOptionFlag, setPrevious, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GzipInterceptorMBean
getOptionFlag, setOptionFlag
-
Field Details
-
sm
StringManager for this class. -
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size for compression/decompression operations.- See Also:
-
DEFAULT_OPTION_COMPRESSION_ENABLE
public static final int DEFAULT_OPTION_COMPRESSION_ENABLEDefault option flag to enable compression.- See Also:
-
-
Constructor Details
-
GzipInterceptor
public GzipInterceptor()Default constructor for GzipInterceptor.
-
-
Method Details
-
sendMessage
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException Description copied from interface:ChannelInterceptorThesendMessagemethod is called when a message is being sent to one more destinations. The interceptor can modify any of the parameters and then pass on the message down the stack by invokinggetNext().sendMessage(destination,msg,payload).Alternatively the interceptor can stop the message from being sent by not invoking
getNext().sendMessage(destination,msg,payload).If the message is to be sent asynchronous the application can be notified of completion and errors by passing in an error handler attached to a payload object.
The ChannelMessage.getAddress contains Channel.getLocalMember, and can be overwritten to simulate a message sent from another node.
- Specified by:
sendMessagein interfaceChannelInterceptor- Overrides:
sendMessagein classChannelInterceptorBase- Parameters:
destination- Member[] - the destination for this messagemsg- ChannelMessage - the message to be sentpayload- InterceptorPayload - the payload, carrying an error handler and future useful data, can be null- Throws:
ChannelException- if a serialization error happens.- See Also:
-
messageReceived
Description copied from interface:ChannelInterceptorThemessageReceivedis invoked when a message is received.ChannelMessage.getAddress()is the sender, or the reply-to address if it has been overwritten.- Specified by:
messageReceivedin interfaceChannelInterceptor- Overrides:
messageReceivedin classChannelInterceptorBase- Parameters:
msg- ChannelMessage
-
compress
Compresses the given data using GZIP compression.- Parameters:
data- The data to compress- Returns:
- The compressed data
- Throws:
IOException- If a compression error occurs
-
decompress
Decompresses the given data using GZIP decompression.- Parameters:
data- The compressed data to decompress- Returns:
- The decompressed data
- Throws:
IOException- If a decompression error occurs
-
report
public void report()Description copied from interface:GzipInterceptorMBeanWrites the current statistics report to the log.- Specified by:
reportin interfaceGzipInterceptorMBean
-
getCompressionMinSize
public int getCompressionMinSize()Description copied from interface:GzipInterceptorMBeanReturns the minimum payload size for compression to be enabled.- Specified by:
getCompressionMinSizein interfaceGzipInterceptorMBean- Returns:
- The minimum payload size in bytes
-
setCompressionMinSize
public void setCompressionMinSize(int compressionMinSize) Description copied from interface:GzipInterceptorMBeanSet the minimum payload size for compression to be enabled. A value of zero or less means compression will always be used. If not explicitly configured, a default of zero will be used.- Specified by:
setCompressionMinSizein interfaceGzipInterceptorMBean- Parameters:
compressionMinSize- The new minimum payload size
-
getStatsEnabled
public boolean getStatsEnabled()Description copied from interface:GzipInterceptorMBeanReturns whether the interceptor is configured to collect statistics.- Specified by:
getStatsEnabledin interfaceGzipInterceptorMBean- Returns:
trueif statistics collection is enabled, otherwisefalse
-
setStatsEnabled
public void setStatsEnabled(boolean statsEnabled) Description copied from interface:GzipInterceptorMBeanConfigure whether the interceptor collects statistics.- Specified by:
setStatsEnabledin interfaceGzipInterceptorMBean- Parameters:
statsEnabled-trueto enable statistics collections, otherwisefalse
-
getInterval
public int getInterval()Description copied from interface:GzipInterceptorMBeanReturns the number of messages between statistics reports being written to the log.- Specified by:
getIntervalin interfaceGzipInterceptorMBean- Returns:
- The interval between statistics reports
-
setInterval
public void setInterval(int interval) Description copied from interface:GzipInterceptorMBeanIf statistics collection is enabled, set the number of messages between statistics reports being written to the log. A value of zero or less means no statistics reports are written.- Specified by:
setIntervalin interfaceGzipInterceptorMBean- Parameters:
interval- The new interval between reports
-
getCount
public int getCount()Description copied from interface:GzipInterceptorMBeanReturns the total message count.- Specified by:
getCountin interfaceGzipInterceptorMBean- Returns:
- Total number of messages processed
-
getCountCompressedTX
public int getCountCompressedTX()Description copied from interface:GzipInterceptorMBeanReturns the count of compressed transmitted messages.- Specified by:
getCountCompressedTXin interfaceGzipInterceptorMBean- Returns:
- Number of compressed TX messages
-
getCountUncompressedTX
public int getCountUncompressedTX()Description copied from interface:GzipInterceptorMBeanReturns the count of uncompressed transmitted messages.- Specified by:
getCountUncompressedTXin interfaceGzipInterceptorMBean- Returns:
- Number of uncompressed TX messages
-
getCountCompressedRX
public int getCountCompressedRX()Description copied from interface:GzipInterceptorMBeanReturns the count of compressed received messages.- Specified by:
getCountCompressedRXin interfaceGzipInterceptorMBean- Returns:
- Number of compressed RX messages
-
getCountUncompressedRX
public int getCountUncompressedRX()Description copied from interface:GzipInterceptorMBeanReturns the count of uncompressed received messages.- Specified by:
getCountUncompressedRXin interfaceGzipInterceptorMBean- Returns:
- Number of uncompressed RX messages
-
getSizeTX
public long getSizeTX()Description copied from interface:GzipInterceptorMBeanReturns the total transmitted data size in bytes.- Specified by:
getSizeTXin interfaceGzipInterceptorMBean- Returns:
- Total TX size in bytes
-
getCompressedSizeTX
public long getCompressedSizeTX()Description copied from interface:GzipInterceptorMBeanReturns the total compressed transmitted data size in bytes.- Specified by:
getCompressedSizeTXin interfaceGzipInterceptorMBean- Returns:
- Total compressed TX size in bytes
-
getUncompressedSizeTX
public long getUncompressedSizeTX()Description copied from interface:GzipInterceptorMBeanReturns the total uncompressed transmitted data size in bytes.- Specified by:
getUncompressedSizeTXin interfaceGzipInterceptorMBean- Returns:
- Total uncompressed TX size in bytes
-
getSizeRX
public long getSizeRX()Description copied from interface:GzipInterceptorMBeanReturns the total received data size in bytes.- Specified by:
getSizeRXin interfaceGzipInterceptorMBean- Returns:
- Total RX size in bytes
-
getCompressedSizeRX
public long getCompressedSizeRX()Description copied from interface:GzipInterceptorMBeanReturns the total compressed received data size in bytes.- Specified by:
getCompressedSizeRXin interfaceGzipInterceptorMBean- Returns:
- Total compressed RX size in bytes
-
getUncompressedSizeRX
public long getUncompressedSizeRX()Description copied from interface:GzipInterceptorMBeanReturns the total uncompressed received data size in bytes.- Specified by:
getUncompressedSizeRXin interfaceGzipInterceptorMBean- Returns:
- Total uncompressed RX size in bytes
-
reset
public void reset()Description copied from interface:GzipInterceptorMBeanResets all statistics counters to zero.- Specified by:
resetin interfaceGzipInterceptorMBean
-