Interface GenericRecord
@Beta public interface GenericRecord
IMap
,IQueue
etc.
On remote calls like distributed executor service or EntryProcessors, you may need to access to the domain object. In case class of the domain object is not available on the cluster, GenericRecord allows to access, read and write the objects back without the class of the domain object on the classpath. Here is an read example with EntryProcessor:
map.executeOnKey(key, (EntryProcessorAnother example with EntryProcessor to demonstrate how to read, modify and set back to the map:
map.executeOnKey("key", (EntryProcessor
GenericRecord also allows to read from a cluster without having the classes on the client side.
For Portable
, when PortableFactory
is not provided in the config at the start,
a HazelcastSerializationException
was thrown stating that a factory could not be found. Starting from 4.1,
the objects will be returned as GenericRecord
. This way, the clients can be read and write the objects back to
the cluster without needing the classes of the domain objects on the classpath.
Currently this is valid for Portable
objects.
- Since:
- 4.1
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
GenericRecord.Builder
Interface for creatingGenericRecord
instances. -
Method Summary
Modifier and Type Method Description GenericRecord.Builder
cloneWithBuilder()
ReturnedGenericRecord.Builder
can be used to have exact copy and also just to update a couple of fields.FieldType
getFieldType(String fieldName)
boolean
hasField(String fieldName)
GenericRecord.Builder
newBuilder()
Creates aGenericRecord.Builder
allows to create a new object.boolean
readBoolean(String fieldName)
boolean[]
readBooleanArray(String fieldName)
byte
readByte(String fieldName)
byte[]
readByteArray(String fieldName)
char
readChar(String fieldName)
char[]
readCharArray(String fieldName)
double
readDouble(String fieldName)
double[]
readDoubleArray(String fieldName)
float
readFloat(String fieldName)
float[]
readFloatArray(String fieldName)
GenericRecord
readGenericRecord(String fieldName)
GenericRecord[]
readGenericRecordArray(String fieldName)
int
readInt(String fieldName)
int[]
readIntArray(String fieldName)
long
readLong(String fieldName)
long[]
readLongArray(String fieldName)
short
readShort(String fieldName)
short[]
readShortArray(String fieldName)
String
readUTF(String fieldName)
String[]
readUTFArray(String fieldName)
-
Method Details
-
newBuilder
Creates aGenericRecord.Builder
allows to create a new object. This method is a convenience method to get a builder, without creating the class definition for this type. Here you can see a new object is constructed from an existing GenericRecord with its class definition:GenericRecord newGenericRecord = genericRecord.newBuilder() .writeUTF("name", "bar") .writeInt("id", 4).build();
see
GenericRecord.Builder.portable(ClassDefinition)
to create a GenericRecord in Portable format with a different class definition.- Returns:
- an empty generic record builder with same class definition as this one
-
cloneWithBuilder
ReturnedGenericRecord.Builder
can be used to have exact copy and also just to update a couple of fields. By default, it will copy all the fields. So instead of following where only the `id` field is updated,GenericRecord modifiedGenericRecord = genericRecord.newBuilder() .writeUTF("name", genericRecord.readUTF("name")) .writeLong("id", 4) .writeUTF("surname", genericRecord.readUTF("surname")) .writeInt("age", genericRecord.readInt("age")).build();
`cloneWithBuilder` used as follows:GenericRecord modifiedGenericRecord = genericRecord.cloneWithBuilder().writeInt("id", 4).build();
- Returns:
- a generic record builder with same class definition as this one and populated with same values.
-
getFieldType
- Parameters:
fieldName
- the name of the field- Returns:
- field type for the given field name
- Throws:
IllegalArgumentException
- if the field name does not exist in the class definition
-
hasField
- Parameters:
fieldName
- the name of the field- Returns:
- true if field exists in the definition of the class. Note that returns true even if the field is null.
-
readBoolean
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readByte
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readChar
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readDouble
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readFloat
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readInt
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readLong
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readShort
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readUTF
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readGenericRecord
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readBooleanArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readByteArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readCharArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readDoubleArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readFloatArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readIntArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readLongArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readShortArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readUTFArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
readGenericRecordArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-