Package io.atomix.utils.serializer
Class NamespaceImpl
- java.lang.Object
-
- io.atomix.utils.serializer.NamespaceImpl
-
- All Implemented Interfaces:
com.esotericsoftware.kryo.pool.KryoFactory,com.esotericsoftware.kryo.pool.KryoPool,Namespace
public class NamespaceImpl extends Object implements Namespace, com.esotericsoftware.kryo.pool.KryoFactory, com.esotericsoftware.kryo.pool.KryoPool
Pool of Kryo instances, with classes pre-registered.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNamespaceImpl.BuilderKryoNamespace builder.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEDefault buffer size used for serialization.static intFLOATING_IDID to use if this KryoNamespace does not define registration id.static intINITIAL_IDSmallest ID free to use for user defined registrations.static intMAX_BUFFER_SIZEMaximum allowed buffer size.
-
Constructor Summary
Constructors Constructor Description NamespaceImpl(List<io.atomix.utils.serializer.NamespaceImpl.RegistrationBlock> registeredTypes, ClassLoader classLoader, boolean registrationRequired, boolean compatible, String friendlyName)Creates a Kryo instance pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.esotericsoftware.kryo.Kryoborrow()com.esotericsoftware.kryo.Kryocreate()Creates a Kryo instance.<T> Tdeserialize(byte[] bytes)Deserializes given byte array to Object using Kryo instance in pool.<T> Tdeserialize(byte[] bytes, int offset)Deserializes given byte array to Object using Kryo instance in pool.<T> Tdeserialize(ByteBuffer buffer)Deserializes given byte buffer to Object using Kryo instance in pool.com.google.common.collect.ImmutableList<io.atomix.utils.serializer.NamespaceImpl.RegistrationBlock>getRegisteredBlocks()NamespaceImplpopulate(int instances)Populates the Kryo pool.voidrelease(com.esotericsoftware.kryo.Kryo kryo)<T> Trun(com.esotericsoftware.kryo.pool.KryoCallback<T> callback)byte[]serialize(Object obj)Serializes given object to byte array using Kryo instance in pool.voidserialize(Object obj, ByteBuffer buffer)Serializes given object to byte buffer using Kryo instance in pool.StringtoString()
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Default buffer size used for serialization.- See Also:
serialize(Object), Constant Field Values
-
MAX_BUFFER_SIZE
public static final int MAX_BUFFER_SIZE
Maximum allowed buffer size.- See Also:
- Constant Field Values
-
FLOATING_ID
public static final int FLOATING_ID
ID to use if this KryoNamespace does not define registration id.- See Also:
- Constant Field Values
-
INITIAL_ID
public static final int INITIAL_ID
Smallest ID free to use for user defined registrations.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NamespaceImpl
public NamespaceImpl(List<io.atomix.utils.serializer.NamespaceImpl.RegistrationBlock> registeredTypes, ClassLoader classLoader, boolean registrationRequired, boolean compatible, String friendlyName)
Creates a Kryo instance pool.- Parameters:
registeredTypes- types to registerregistrationRequired- whether registration is requiredcompatible- whether compatible serialization is enabledfriendlyName- friendly name for the namespace
-
-
Method Detail
-
populate
public NamespaceImpl populate(int instances)
Populates the Kryo pool.- Parameters:
instances- to add to the pool- Returns:
- this
-
serialize
public byte[] serialize(Object obj)
Serializes given object to byte array using Kryo instance in pool.Note: Serialized bytes must be smaller than
MAX_BUFFER_SIZE.
-
serialize
public void serialize(Object obj, ByteBuffer buffer)
Serializes given object to byte buffer using Kryo instance in pool.
-
deserialize
public <T> T deserialize(byte[] bytes)
Deserializes given byte array to Object using Kryo instance in pool.- Specified by:
deserializein interfaceNamespace- Type Parameters:
T- deserialized Object type- Parameters:
bytes- serialized bytes- Returns:
- deserialized Object
-
deserialize
public <T> T deserialize(ByteBuffer buffer)
Deserializes given byte buffer to Object using Kryo instance in pool.- Specified by:
deserializein interfaceNamespace- Type Parameters:
T- deserialized Object type- Parameters:
buffer- input with serialized bytes- Returns:
- deserialized Object
-
getRegisteredBlocks
public com.google.common.collect.ImmutableList<io.atomix.utils.serializer.NamespaceImpl.RegistrationBlock> getRegisteredBlocks()
- Specified by:
getRegisteredBlocksin interfaceNamespace
-
deserialize
public <T> T deserialize(byte[] bytes, int offset)Deserializes given byte array to Object using Kryo instance in pool.- Type Parameters:
T- deserialized Object type- Parameters:
bytes- serialized bytesoffset- offset in serialized bytes- Returns:
- deserialized Object
-
create
public com.esotericsoftware.kryo.Kryo create()
Creates a Kryo instance.- Specified by:
createin interfacecom.esotericsoftware.kryo.pool.KryoFactory- Returns:
- Kryo instance
-
borrow
public com.esotericsoftware.kryo.Kryo borrow()
- Specified by:
borrowin interfacecom.esotericsoftware.kryo.pool.KryoPool
-
release
public void release(com.esotericsoftware.kryo.Kryo kryo)
- Specified by:
releasein interfacecom.esotericsoftware.kryo.pool.KryoPool
-
run
public <T> T run(com.esotericsoftware.kryo.pool.KryoCallback<T> callback)
- Specified by:
runin interfacecom.esotericsoftware.kryo.pool.KryoPool
-
-