Class GenericObjectMapper
java.lang.Object
org.apache.hadoop.yarn.server.timeline.GenericObjectMapper
A utility class providing methods for serializing and deserializing
objects. The
write(Object) and read(byte[]) methods are
used by the LeveldbTimelineStore to store and retrieve arbitrary
JSON, while the writeReverseOrderedLong(long) and readReverseOrderedLong(byte[], int) methods are used to sort entities in descending
start time order.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.fasterxml.jackson.databind.ObjectReaderstatic final com.fasterxml.jackson.databind.ObjectWriter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectread(byte[] b) Deserializes an Object from a byte array created withwrite(Object).static Objectread(byte[] b, int offset) Deserializes an Object from a byte array at a specified offset, assuming the bytes were created withwrite(Object).static longreadReverseOrderedLong(byte[] b, int offset) Reads 8 bytes from an array starting at the specified offset and converts them to a long.static byte[]Serializes an Object into a byte array.static byte[]writeReverseOrderedLong(long l) Converts a long to a 8-byte array so that lexicographic ordering of the produced byte arrays sort the longs in descending order.static byte[]writeReverseOrderedLong(long l, byte[] b, int offset)
-
Field Details
-
OBJECT_READER
public static final com.fasterxml.jackson.databind.ObjectReader OBJECT_READER -
OBJECT_WRITER
public static final com.fasterxml.jackson.databind.ObjectWriter OBJECT_WRITER
-
-
Constructor Details
-
GenericObjectMapper
public GenericObjectMapper()
-
-
Method Details
-
write
Serializes an Object into a byte array. Along withread(byte[]), can be used to serialize an Object and deserialize it into an Object of the same type without needing to specify the Object's type, as long as it is one of the JSON-compatible objects understood by ObjectMapper.- Parameters:
o- An Object- Returns:
- A byte array representation of the Object
- Throws:
IOException- if there is a write error
-
read
Deserializes an Object from a byte array created withwrite(Object).- Parameters:
b- A byte array- Returns:
- An Object
- Throws:
IOException- if there is a read error
-
read
Deserializes an Object from a byte array at a specified offset, assuming the bytes were created withwrite(Object).- Parameters:
b- A byte arrayoffset- Offset into the array- Returns:
- An Object
- Throws:
IOException- if there is a read error
-
writeReverseOrderedLong
public static byte[] writeReverseOrderedLong(long l) Converts a long to a 8-byte array so that lexicographic ordering of the produced byte arrays sort the longs in descending order.- Parameters:
l- A long- Returns:
- A byte array
-
writeReverseOrderedLong
public static byte[] writeReverseOrderedLong(long l, byte[] b, int offset) -
readReverseOrderedLong
public static long readReverseOrderedLong(byte[] b, int offset) Reads 8 bytes from an array starting at the specified offset and converts them to a long. The bytes are assumed to have been created withwriteReverseOrderedLong(long).- Parameters:
b- A byte arrayoffset- An offset into the byte array- Returns:
- A long
-