use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class DefaultSerializationServiceBuilder method buildPortableFactories.
private void buildPortableFactories(Map<Integer, PortableFactory> portableFactories, SerializationConfig config, ClassLoader cl) {
final Map<Integer, String> portableFactoryClasses = config.getPortableFactoryClasses();
for (Map.Entry<Integer, String> entry : portableFactoryClasses.entrySet()) {
int factoryId = entry.getKey();
String factoryClassName = entry.getValue();
if (factoryId <= 0) {
throw new IllegalArgumentException("PortableFactory factoryId must be positive! -> " + factoryClassName);
}
if (portableFactories.containsKey(factoryId)) {
throw new IllegalArgumentException("PortableFactory with factoryId '" + factoryId + "' is already registered!");
}
PortableFactory factory;
try {
factory = ClassLoaderUtil.newInstance(cl, factoryClassName);
} catch (Exception e) {
throw new HazelcastSerializationException(e);
}
portableFactories.put(factoryId, factory);
}
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writeNullPortable.
@Override
public void writeNullPortable(String fieldName, int factoryId, int classId) throws IOException {
final ClassDefinition nestedClassDef = context.lookupClassDefinition(factoryId, classId, context.getVersion());
if (nestedClassDef == null) {
throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!");
}
builder.addPortableField(fieldName, nestedClassDef);
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writePortableArray.
@Override
public void writePortableArray(String fieldName, Portable[] portables) throws IOException {
if (portables == null || portables.length == 0) {
throw new HazelcastSerializationException("Cannot write null portable array without explicitly " + "registering class definition!");
}
Portable p = portables[0];
int classId = p.getClassId();
for (int i = 1; i < portables.length; i++) {
if (portables[i].getClassId() != classId) {
throw new IllegalArgumentException("Detected different class-ids in portable array!");
}
}
int version = SerializationUtil.getPortableVersion(p, context.getVersion());
ClassDefinition nestedClassDef = createNestedClassDef(p, new ClassDefinitionBuilder(p.getFactoryId(), classId, version));
builder.addPortableArrayField(fieldName, nestedClassDef);
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class DefaultPortableWriter method setPosition.
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;
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class PortableUtilsTest method unknownFieldException.
@Test
public void unknownFieldException() {
// GIVEN
BufferObjectDataInput in = mock(BufferObjectDataInput.class);
ClassDefinition cd = mock(ClassDefinition.class);
PortableNavigatorContext ctx = new PortableNavigatorContext(in, cd, null);
// WHEN
HazelcastSerializationException ex = PortableUtils.createUnknownFieldException(ctx, "person.brain");
// THEN
assertNotNull(ex);
}
Aggregations