use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class SerializationServiceV1 method registerClassDefinition.
private void registerClassDefinition(ClassDefinition cd, Map<Integer, Map<Integer, ClassDefinition>> factoryMap) {
Set<String> fieldNames = cd.getFieldNames();
for (String fieldName : fieldNames) {
FieldDefinition fd = cd.getField(fieldName);
if (fd.getType() == FieldType.PORTABLE || fd.getType() == FieldType.PORTABLE_ARRAY) {
int factoryId = fd.getFactoryId();
int classId = fd.getClassId();
Map<Integer, ClassDefinition> classDefinitionMap = factoryMap.get(factoryId);
if (classDefinitionMap != null) {
ClassDefinition nestedCd = classDefinitionMap.get(classId);
if (nestedCd != null) {
registerClassDefinition(nestedCd, factoryMap);
portableContext.registerClassDefinition(nestedCd);
continue;
}
}
if (portableContext.shouldCheckClassDefinitionErrors()) {
throw new HazelcastSerializationException("Could not find registered ClassDefinition for factory-id : " + factoryId + ", class-id " + classId);
}
}
}
portableContext.registerClassDefinition(cd);
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableHookLoader method load.
private void load() {
try {
final Iterator<PortableHook> hooks = ServiceLoader.iterator(PortableHook.class, FACTORY_ID, classLoader);
while (hooks.hasNext()) {
PortableHook hook = hooks.next();
final PortableFactory factory = hook.createFactory();
if (factory != null) {
register(hook.getFactoryId(), factory);
}
final Collection<ClassDefinition> defs = hook.getBuiltinDefinitions();
if (defs != null && !defs.isEmpty()) {
definitions.addAll(defs);
}
}
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
if (configuredFactories != null) {
for (Map.Entry<Integer, ? extends PortableFactory> entry : configuredFactories.entrySet()) {
register(entry.getKey(), entry.getValue());
}
}
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableSerializer method readAsInternalGenericRecord.
public InternalGenericRecord readAsInternalGenericRecord(ObjectDataInput in) throws IOException {
int factoryId = in.readInt();
int classId = in.readInt();
int version = in.readInt();
BufferObjectDataInput input = (BufferObjectDataInput) in;
ClassDefinition cd = setupPositionAndDefinition(input, factoryId, classId, version);
return new PortableInternalGenericRecord(this, input, cd, true);
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableSerializer method writePortableGenericRecord.
// Portable Generic Record
private void writePortableGenericRecord(ObjectDataOutput out, PortableGenericRecord record) throws IOException {
ClassDefinition cd = record.getClassDefinition();
out.writeInt(cd.getFactoryId());
out.writeInt(cd.getClassId());
writePortableGenericRecordInternal(out, record);
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableSerializer method writePortableGenericRecordInternal.
@SuppressWarnings({ "checkstyle:MethodLength", "checkstyle:CyclomaticComplexity" })
void writePortableGenericRecordInternal(ObjectDataOutput out, PortableGenericRecord record) throws IOException {
ClassDefinition cd = record.getClassDefinition();
// Class definition compatibility will be checked implicitly on the
// register call below.
context.registerClassDefinition(cd, context.shouldCheckClassDefinitionErrors());
out.writeInt(cd.getVersion());
BufferObjectDataOutput output = (BufferObjectDataOutput) out;
DefaultPortableWriter writer = new DefaultPortableWriter(this, output, cd);
Set<String> fieldNames = cd.getFieldNames();
for (String fieldName : fieldNames) {
switch(cd.getFieldType(fieldName)) {
case PORTABLE:
writer.writeGenericRecord(fieldName, record.getGenericRecord(fieldName));
break;
case BYTE:
writer.writeByte(fieldName, record.getInt8(fieldName));
break;
case BOOLEAN:
writer.writeBoolean(fieldName, record.getBoolean(fieldName));
break;
case CHAR:
writer.writeChar(fieldName, record.getChar(fieldName));
break;
case SHORT:
writer.writeShort(fieldName, record.getInt16(fieldName));
break;
case INT:
writer.writeInt(fieldName, record.getInt32(fieldName));
break;
case LONG:
writer.writeLong(fieldName, record.getInt64(fieldName));
break;
case FLOAT:
writer.writeFloat(fieldName, record.getFloat32(fieldName));
break;
case DOUBLE:
writer.writeDouble(fieldName, record.getFloat64(fieldName));
break;
case UTF:
writer.writeString(fieldName, record.getString(fieldName));
break;
case DECIMAL:
writer.writeDecimal(fieldName, record.getDecimal(fieldName));
break;
case TIME:
writer.writeTime(fieldName, record.getTime(fieldName));
break;
case DATE:
writer.writeDate(fieldName, record.getDate(fieldName));
break;
case TIMESTAMP:
writer.writeTimestamp(fieldName, record.getTimestamp(fieldName));
break;
case TIMESTAMP_WITH_TIMEZONE:
writer.writeTimestampWithTimezone(fieldName, record.getTimestampWithTimezone(fieldName));
break;
case PORTABLE_ARRAY:
writer.writeGenericRecordArray(fieldName, record.getArrayOfGenericRecord(fieldName));
break;
case BYTE_ARRAY:
writer.writeByteArray(fieldName, record.getArrayOfInt8(fieldName));
break;
case BOOLEAN_ARRAY:
writer.writeBooleanArray(fieldName, record.getArrayOfBoolean(fieldName));
break;
case CHAR_ARRAY:
writer.writeCharArray(fieldName, record.getArrayOfChar(fieldName));
break;
case SHORT_ARRAY:
writer.writeShortArray(fieldName, record.getArrayOfInt16(fieldName));
break;
case INT_ARRAY:
writer.writeIntArray(fieldName, record.getArrayOfInt32(fieldName));
break;
case LONG_ARRAY:
writer.writeLongArray(fieldName, record.getArrayOfInt64(fieldName));
break;
case FLOAT_ARRAY:
writer.writeFloatArray(fieldName, record.getArrayOfFloat32(fieldName));
break;
case DOUBLE_ARRAY:
writer.writeDoubleArray(fieldName, record.getArrayOfFloat64(fieldName));
break;
case UTF_ARRAY:
writer.writeStringArray(fieldName, record.getArrayOfString(fieldName));
break;
case DECIMAL_ARRAY:
writer.writeDecimalArray(fieldName, record.getArrayOfDecimal(fieldName));
break;
case TIME_ARRAY:
writer.writeTimeArray(fieldName, record.getArrayOfTime(fieldName));
break;
case DATE_ARRAY:
writer.writeDateArray(fieldName, record.getArrayOfDate(fieldName));
break;
case TIMESTAMP_ARRAY:
writer.writeTimestampArray(fieldName, record.getArrayOfTimestamp(fieldName));
break;
case TIMESTAMP_WITH_TIMEZONE_ARRAY:
writer.writeTimestampWithTimezoneArray(fieldName, record.getArrayOfTimestampWithTimezone(fieldName));
break;
default:
throw new IllegalStateException("Unexpected field type: " + cd.getFieldType(fieldName));
}
}
writer.end();
}
Aggregations