public void registerClassDefinitions(Collection<ClassDefinition> classDefinitions, boolean checkClassDefErrors) { final Map<Integer, ClassDefinition> classDefMap = createHashMap(classDefinitions.size()); for (ClassDefinition cd : classDefinitions) { if (classDefMap.containsKey(cd.getClassId())) { throw new HazelcastSerializationException("Duplicate registration found for class-id[" + cd.getClassId() + "]!"); } classDefMap.put(cd.getClassId(), cd); } for (ClassDefinition classDefinition : classDefinitions) { registerClassDefinition(classDefinition, classDefMap, checkClassDefErrors); } }
public void registerClassDefinitions(Collection<ClassDefinition> classDefinitions, boolean checkClassDefErrors) { final Map<Integer, ClassDefinition> classDefMap = createHashMap(classDefinitions.size()); for (ClassDefinition cd : classDefinitions) { if (classDefMap.containsKey(cd.getClassId())) { throw new HazelcastSerializationException("Duplicate registration found for class-id[" + cd.getClassId() + "]!"); } classDefMap.put(cd.getClassId(), cd); } for (ClassDefinition classDefinition : classDefinitions) { registerClassDefinition(classDefinition, classDefMap, checkClassDefErrors); } }
/** * @param classDefinition the class definition to be registered * @return configured {@link com.hazelcast.config.SerializerConfig} for chaining * @see ClassDefinition */ public SerializationConfig addClassDefinition(ClassDefinition classDefinition) { if (!getClassDefinitions().add(classDefinition)) { throw new IllegalArgumentException("ClassDefinition for class-id[" + classDefinition.getClassId() + "] already exists!"); } return this; }
/** * @param classDefinition the class definition to be registered * @return configured {@link com.hazelcast.config.SerializerConfig} for chaining * @see ClassDefinition */ public SerializationConfig addClassDefinition(ClassDefinition classDefinition) { if (!getClassDefinitions().add(classDefinition)) { throw new IllegalArgumentException("ClassDefinition for class-id[" + classDefinition.getClassId() + "] already exists!"); } return this; }
public ClassDefinitionBuilder addPortableField(String fieldName, ClassDefinition def) { check(); if (def.getClassId() == 0) { throw new IllegalArgumentException("Portable class ID cannot be zero!"); } fieldDefinitions.add(new FieldDefinitionImpl(index++, fieldName, FieldType.PORTABLE, def.getFactoryId(), def.getClassId(), def.getVersion())); return this; }
public ClassDefinitionBuilder addPortableArrayField(String fieldName, ClassDefinition def) { check(); if (def.getClassId() == 0) { throw new IllegalArgumentException("Portable class ID cannot be zero!"); } fieldDefinitions.add(new FieldDefinitionImpl(index++, fieldName, FieldType.PORTABLE_ARRAY, def.getFactoryId(), def.getClassId(), def.getVersion())); return this; }
public ClassDefinitionBuilder addPortableField(String fieldName, ClassDefinition def) { check(); if (def.getClassId() == 0) { throw new IllegalArgumentException("Portable class ID cannot be zero!"); } fieldDefinitions.add(new FieldDefinitionImpl(index++, fieldName, FieldType.PORTABLE, def.getFactoryId(), def.getClassId(), def.getVersion())); return this; }
public ClassDefinitionBuilder addPortableArrayField(String fieldName, ClassDefinition def) { check(); if (def.getClassId() == 0) { throw new IllegalArgumentException("Portable class ID cannot be zero!"); } fieldDefinitions.add(new FieldDefinitionImpl(index++, fieldName, FieldType.PORTABLE_ARRAY, def.getFactoryId(), def.getClassId(), def.getVersion())); return this; }
/** * @param cd given classDefinition to validate against * @param fd given fieldDefinition to validate against * @param fullPath full path - just for output * @throws IllegalArgumentException if the current field definition is not of an array type */ static void validateArrayType(ClassDefinition cd, FieldDefinition fd, String fullPath) { if (!fd.getType().isArrayType()) { throw new IllegalArgumentException("Wrong use of array operator: '" + fullPath + "' for ClassDefinition {id: " + cd.getClassId() + ", version: " + cd.getVersion() + "}"); } }
/** * @param cd given classDefinition to validate against * @param fd given fieldDefinition to validate against * @param fullPath full path - just for output * @throws IllegalArgumentException if the current field definition is not of an array type */ static void validateArrayType(ClassDefinition cd, FieldDefinition fd, String fullPath) { if (!fd.getType().isArrayType()) { throw new IllegalArgumentException("Wrong use of array operator: '" + fullPath + "' for ClassDefinition {id: " + cd.getClassId() + ", version: " + cd.getVersion() + "}"); } }
/** * @param ctx portable navigation context * @param fullPath full path - just for output * @return initialised IllegalArgumentException with a wrong use of any operator at the current path token */ static IllegalArgumentException createWrongUseOfAnyOperationException(PortableNavigatorContext ctx, String fullPath) { return new IllegalArgumentException("Wrong use of any operator: '" + fullPath + "' for ClassDefinition {id: " + ctx.getCurrentClassDefinition().getClassId() + ", version: " + ctx.getCurrentClassDefinition().getVersion() + "}"); }
/** * @param ctx portable navigation context * @param fullPath full path - just for output * @return initialised IllegalArgumentException with a wrong use of any operator at the current path token */ static IllegalArgumentException createWrongUseOfAnyOperationException(PortableNavigatorContext ctx, String fullPath) { return new IllegalArgumentException("Wrong use of any operator: '" + fullPath + "' for ClassDefinition {id: " + ctx.getCurrentClassDefinition().getClassId() + ", version: " + ctx.getCurrentClassDefinition().getVersion() + "}"); }
/** * @param ctx portable navigation context * @param fullPath full path - just for output * @return initialised HazelcastSerializationException with an unknown field at the current path token */ static HazelcastSerializationException createUnknownFieldException(PortableNavigatorContext ctx, String fullPath) { return new HazelcastSerializationException("Unknown field name: '" + fullPath + "' for ClassDefinition {id: " + ctx.getCurrentClassDefinition().getClassId() + ", version: " + ctx.getCurrentClassDefinition().getVersion() + "}"); }
/** * @param ctx portable navigation context * @param fullPath full path - just for output * @return initialised HazelcastSerializationException with an unknown field at the current path token */ static HazelcastSerializationException createUnknownFieldException(PortableNavigatorContext ctx, String fullPath) { return new HazelcastSerializationException("Unknown field name: '" + fullPath + "' for ClassDefinition {id: " + ctx.getCurrentClassDefinition().getClassId() + ", version: " + ctx.getCurrentClassDefinition().getVersion() + "}"); }
ClassDefinition register(ClassDefinition cd) { if (cd == null) { return null; } if (cd.getFactoryId() != factoryId) { throw new HazelcastSerializationException("Invalid factory-id! " + factoryId + " -> " + cd); } if (cd instanceof ClassDefinitionImpl) { final ClassDefinitionImpl cdImpl = (ClassDefinitionImpl) cd; cdImpl.setVersionIfNotSet(getVersion()); } final long versionedClassId = combineToLong(cd.getClassId(), cd.getVersion()); final ClassDefinition currentCd = versionedDefinitions.putIfAbsent(versionedClassId, cd); if (currentCd == null) { return cd; } if (currentCd instanceof ClassDefinitionImpl) { if (!currentCd.equals(cd)) { throw new HazelcastSerializationException( "Incompatible class-definitions with same class-id: " + cd + " VS " + currentCd); } return currentCd; } versionedDefinitions.put(versionedClassId, cd); return cd; }
ClassDefinition register(ClassDefinition cd) { if (cd == null) { return null; } if (cd.getFactoryId() != factoryId) { throw new HazelcastSerializationException("Invalid factory-id! " + factoryId + " -> " + cd); } if (cd instanceof ClassDefinitionImpl) { final ClassDefinitionImpl cdImpl = (ClassDefinitionImpl) cd; cdImpl.setVersionIfNotSet(getVersion()); } final long versionedClassId = combineToLong(cd.getClassId(), cd.getVersion()); final ClassDefinition currentCd = versionedDefinitions.putIfAbsent(versionedClassId, cd); if (currentCd == null) { return cd; } if (currentCd instanceof ClassDefinitionImpl) { if (!currentCd.equals(cd)) { throw new HazelcastSerializationException( "Incompatible class-definitions with same class-id: " + cd + " VS " + currentCd); } return currentCd; } versionedDefinitions.put(versionedClassId, cd); return cd; }
private FieldDefinition setPosition(String fieldName, FieldType fieldType) throws IOException { if (raw) { throw new HazelcastSerializationException("Cannot write Portable fields after getRawDataOutput() is called!"); } FieldDefinition fd = cd.getField(fieldName); if (fd == null) { throw new HazelcastSerializationException("Invalid field name: '" + fieldName + "' for ClassDefinition {id: " + cd.getClassId() + ", version: " + cd.getVersion() + "}"); } if (writtenFields.add(fieldName)) { int pos = out.position(); int index = fd.getIndex(); out.writeInt(offset + index * INT_SIZE_IN_BYTES, pos); out.writeShort(fieldName.length()); out.writeBytes(fieldName); out.writeByte(fieldType.getId()); } else { throw new HazelcastSerializationException("Field '" + fieldName + "' has already been written!"); } return fd; }
private FieldDefinition setPosition(String fieldName, FieldType fieldType) throws IOException { if (raw) { throw new HazelcastSerializationException("Cannot write Portable fields after getRawDataOutput() is called!"); } FieldDefinition fd = cd.getField(fieldName); if (fd == null) { throw new HazelcastSerializationException("Invalid field name: '" + fieldName + "' for ClassDefinition {id: " + cd.getClassId() + ", version: " + cd.getVersion() + "}"); } if (writtenFields.add(fieldName)) { int pos = out.position(); int index = fd.getIndex(); out.writeInt(offset + index * INT_SIZE_IN_BYTES, pos); out.writeShort(fieldName.length()); out.writeBytes(fieldName); out.writeByte(fieldType.getId()); } else { throw new HazelcastSerializationException("Field '" + fieldName + "' has already been written!"); } return fd; }