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
public class GzipInterceptor extends ChannelInterceptorBase implements GzipInterceptorMBean
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 org.apache.catalina.tribes.ChannelInterceptor
ChannelInterceptor.InterceptorEvent
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEDefault buffer size for compression/decompression operations.static intDEFAULT_OPTION_COMPRESSION_ENABLEDefault option flag to enable compression.protected static StringManagersmStringManager for this class.-
Fields inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBase
optionFlag
-
-
Constructor Summary
Constructors Constructor Description GzipInterceptor()Default constructor for GzipInterceptor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static byte[]compress(byte[] data)Compresses the given data using GZIP compression.static byte[]decompress(byte[] data)Decompresses the given data using GZIP decompression.longgetCompressedSizeRX()Returns the total compressed received data size in bytes.longgetCompressedSizeTX()Returns the total compressed transmitted data size in bytes.intgetCompressionMinSize()Returns the minimum payload size for compression to be enabled.intgetCount()Returns the total message count.intgetCountCompressedRX()Returns the count of compressed received messages.intgetCountCompressedTX()Returns the count of compressed transmitted messages.intgetCountUncompressedRX()Returns the count of uncompressed received messages.intgetCountUncompressedTX()Returns the count of uncompressed transmitted messages.intgetInterval()Returns the number of messages between statistics reports being written to the log.longgetSizeRX()Returns the total received data size in bytes.longgetSizeTX()Returns the total transmitted data size in bytes.booleangetStatsEnabled()Returns whether the interceptor is configured to collect statistics.longgetUncompressedSizeRX()Returns the total uncompressed received data size in bytes.longgetUncompressedSizeTX()Returns the total uncompressed transmitted data size in bytes.voidmessageReceived(ChannelMessage msg)ThemessageReceivedis 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 org.apache.catalina.tribes.group.ChannelInterceptorBase
fireInterceptorEvent, getChannel, getLocalMember, getMember, getMembers, getNext, getOptionFlag, getPrevious, hasMembers, heartbeat, memberAdded, memberDisappeared, okToProcess, setChannel, setNext, setOptionFlag, setPrevious, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.catalina.tribes.group.interceptors.GzipInterceptorMBean
getOptionFlag, setOptionFlag
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
StringManager for this class.
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Default buffer size for compression/decompression operations.- See Also:
- Constant Field Values
-
DEFAULT_OPTION_COMPRESSION_ENABLE
public static final int DEFAULT_OPTION_COMPRESSION_ENABLE
Default option flag to enable compression.- See Also:
- Constant Field Values
-
-
Method Detail
-
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:
ErrorHandler,InterceptorPayload
-
messageReceived
public void messageReceived(ChannelMessage msg)
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
public static byte[] compress(byte[] data) throws java.io.IOExceptionCompresses the given data using GZIP compression.- Parameters:
data- The data to compress- Returns:
- The compressed data
- Throws:
java.io.IOException- If a compression error occurs
-
decompress
public static byte[] decompress(byte[] data) throws java.io.IOExceptionDecompresses the given data using GZIP decompression.- Parameters:
data- The compressed data to decompress- Returns:
- The decompressed data
- Throws:
java.io.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
-
-