Top Description Fields Constructors Methods
net.sf.ehcache.distribution

pack-priv final Class PayloadUtil

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, java.rmi.RemoteException, java.util.ArrayList, .Arrays, .Collections, .List, org.slf4j.Logger, .LoggerFactory, java.util.zip.GZIPInputStream, .GZIPOutputStream

This class provides utility methods for assembling and disassembling a heartbeat payload.

Care is taken to fit the payload into the MTU of ethernet, which is 1500 bytes. The algorithms in this class are capable of creating payloads for CacheManagers containing approximately 500 cache peers to be replicated.

Author
Greg Luck
Version
$Id: PayloadUtil.java 10789 2018-04-26 02:08:13Z adahanne $

Field Summary

Modifier and TypeField and Description
private static final Logger
public static final int
MTU

The maximum transmission unit.

public static final String
URL_DELIMITER

Delmits URLS sent via heartbeats over sockets

pack-priv static final String
URL_DELIMITER_REGEXP

URL_DELIMITER as a regular expression.

Constructor Summary

AccessConstructor and Description
private
PayloadUtil()

Utility class therefore precent construction

Method Summary

Modifier and TypeMethod and Description
public static byte[]

Returns:

an uncompressed payload with catenated rmiUrls.
assembleUrlList
(List<E> localCachePeers)

Assembles a list of URLs

private static List<byte[]>

Returns:

A list of compressed urlList's, each compressed entry not exceeding maxSizePerPayload
createCompressedPayload
(final List<CachePeer>
The list of CachePeers whose payload needs to be generated
list
,
final int
The maximum size each payload can have
maxSizePerPayload
)

Generates a list of compressed urlList's for the input CachePeers list.

public static List<byte[]>

Returns:

List of compressed entries containing the peers urlList
createCompressedPayloadList
(final List<CachePeer>
List containing the peers
localCachePeers
,
final int
The maximum number of peers that can be present in one compressed entry
maximumPeersPerSend
)

Creates a list of compressed (using gzip) url list.

public static byte[]

Returns:

gzipped bytes
gzip
(byte[]
the bytes to be gzipped
ungzipped
)

Gzips a byte[].

public static byte[]

Returns:

a plain, uncompressed byte[]
ungzip
(final byte[] gzipped)

The fastest Ungzip implementation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Logger LOG
MTUback to summary
public static final int MTU

The maximum transmission unit. This varies by link layer. For ethernet, fast ethernet and gigabit ethernet it is 1500 bytes, the value chosen.

Payloads are limited to this so that there is no fragmentation and no necessity for a complex reassembly protocol.

URL_DELIMITERback to summary
public static final String URL_DELIMITER

Delmits URLS sent via heartbeats over sockets

URL_DELIMITER_REGEXPback to summary
pack-priv static final String URL_DELIMITER_REGEXP

URL_DELIMITER as a regular expression. Package protected, used in tests only

Constructor Detail

PayloadUtilback to summary
private PayloadUtil()

Utility class therefore precent construction

Method Detail

assembleUrlListback to summary
public static byte[] assembleUrlList(List<E> localCachePeers)

Assembles a list of URLs

Returns:byte[]

an uncompressed payload with catenated rmiUrls.

createCompressedPayloadback to summary
private static List<byte[]> createCompressedPayload(final List<CachePeer> list, final int maxSizePerPayload)

Generates a list of compressed urlList's for the input CachePeers list. Each compressed payload is limited by size by the maxSizePerPayload parameter and will break up into multiple payloads if necessary to limit the payload size

Parameters
list:List<CachePeer>

The list of CachePeers whose payload needs to be generated

maxSizePerPayload:int

The maximum size each payload can have

Returns:List<byte[]>

A list of compressed urlList's, each compressed entry not exceeding maxSizePerPayload

createCompressedPayloadListback to summary
public static List<byte[]> createCompressedPayloadList(final List<CachePeer> localCachePeers, final int maximumPeersPerSend)

Creates a list of compressed (using gzip) url list. Breaks up the list of urlList such that size of each compressed entry in the list does not exceed the MTU and the number of url's in each compressed entry does not exceed the maximumPeersPerSend parameter

Parameters
localCachePeers:List<CachePeer>

List containing the peers

maximumPeersPerSend:int

The maximum number of peers that can be present in one compressed entry

Returns:List<byte[]>

List of compressed entries containing the peers urlList

gzipback to summary
public static byte[] gzip(byte[] ungzipped)

Gzips a byte[]. For text, approximately 10:1 compression is achieved.

Parameters
ungzipped:byte[]

the bytes to be gzipped

Returns:byte[]

gzipped bytes

ungzipback to summary
public static byte[] ungzip(final byte[] gzipped)

The fastest Ungzip implementation. See PageInfoTest in ehcache-constructs. A high performance implementation, although not as fast as gunzip3. gunzips 100000 of ungzipped content in 9ms on the reference machine. It does not use a fixed size buffer and is therefore suitable for arbitrary length arrays.

Returns:byte[]

a plain, uncompressed byte[]