Class DeflaterSerializer
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.serializer.Serializer
services.moleculer.serializer.ChainedSerializer
services.moleculer.serializer.DeflaterSerializer
- All Implemented Interfaces:
MoleculerLifecycle
Message compressor / decompressor. Sample of usage:
Transporter trans = new NatsTransporter("localhost");
trans.setSerializer(new DeflaterSerializer());
ServiceBroker broker = ServiceBroker.builder().nodeID("node1").transporter(trans).build();
Chaining Serializers (serialize then compress then encrypt packets):
Transporter trans = new NatsTransporter("localhost");
MsgPackSerializer msgPack = new MsgPackSerializer();
DeflaterSerializer deflater = new DeflaterSerializer(msgPack);
BlockCipherSerializer cipher = new BlockCipherSerializer(deflater);
trans.setSerializer(cipher);
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intCompression level (best speed = 1, best compression = 9)protected intCompress key and/or value above this size (BYTES), 0 = disable compressionFields inherited from class ChainedSerializer
parentFields inherited from class Serializer
debug, format, reader, writerFields inherited from class MoleculerComponent
broker, logger, name -
Constructor Summary
ConstructorsConstructorDescriptionCreates a JSON-based Serializer that compresses content above 1024 bytes with compression level "1".DeflaterSerializer(int threshold) Creates a JSON-based Serializer that compresses content above a specified size (see the "compressAbove" parameter).DeflaterSerializer(int threshold, int compressionLevel) Creates a JSON-based Serializer that compresses content above a specified size with the specified compression level (1-9).DeflaterSerializer(Serializer parent) Creates a custom Serializer that compresses content above 1024 bytes size with the compression level "1".DeflaterSerializer(Serializer parent, int threshold, int compressionLevel) Creates a custom Serializer that compresses content above a specified size with the specified compression level (1-9). -
Method Summary
Modifier and TypeMethodDescriptionintintio.datatree.Treeread(byte[] source) voidsetCompressionLevel(int compressionLevel) voidsetThreshold(int threshold) byte[]write(io.datatree.Tree value) Methods inherited from class ChainedSerializer
getFormat, setDebug, started, stoppedMethods inherited from class Serializer
isDebugMethods inherited from class MoleculerComponent
getBroker, getLogger, getName
-
Field Details
-
threshold
protected int thresholdCompress key and/or value above this size (BYTES), 0 = disable compression -
compressionLevel
protected int compressionLevelCompression level (best speed = 1, best compression = 9)
-
-
Constructor Details
-
DeflaterSerializer
public DeflaterSerializer()Creates a JSON-based Serializer that compresses content above 1024 bytes with compression level "1". -
DeflaterSerializer
public DeflaterSerializer(int threshold) Creates a JSON-based Serializer that compresses content above a specified size (see the "compressAbove" parameter).- Parameters:
threshold- Compress key and/or value above this size (BYTES), 0 = disable compression
-
DeflaterSerializer
public DeflaterSerializer(int threshold, int compressionLevel) Creates a JSON-based Serializer that compresses content above a specified size with the specified compression level (1-9).- Parameters:
threshold- Compress key and/or value above this size (BYTES), 0 = disable compressioncompressionLevel- Compression level (best speed = 1, best compression = 9)
-
DeflaterSerializer
Creates a custom Serializer that compresses content above 1024 bytes size with the compression level "1".- Parameters:
parent- parent Serializer (eg. a JsonSerializer)
-
DeflaterSerializer
Creates a custom Serializer that compresses content above a specified size with the specified compression level (1-9).- Parameters:
parent- parent Serializer (eg. a JsonSerializer)threshold- Compress key and/or value above this size (BYTES), 0 = disable compressioncompressionLevel- Compression level (best speed = 1, best compression = 9)
-
-
Method Details
-
write
- Overrides:
writein classSerializer- Throws:
Exception
-
read
- Overrides:
readin classSerializer- Throws:
Exception
-
getCompressionLevel
public int getCompressionLevel() -
setCompressionLevel
public void setCompressionLevel(int compressionLevel) -
getThreshold
public int getThreshold() -
setThreshold
public void setThreshold(int threshold)
-