use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class PortableSerializer method createNewPortableInstance.
private Portable createNewPortableInstance(int factoryId, int classId) {
final PortableFactory portableFactory = factories.get(factoryId);
if (portableFactory == null) {
throw new HazelcastSerializationException("Could not find PortableFactory for factory-id: " + factoryId);
}
final Portable portable = portableFactory.create(classId);
if (portable == null) {
throw new HazelcastSerializationException("Could not create Portable for class-id: " + classId);
}
return portable;
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class SerializationServiceV1 method registerClassDefinition.
protected void registerClassDefinition(ClassDefinition cd, Map<Integer, ClassDefinition> classDefMap, boolean checkClassDefErrors) {
final 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 classId = fd.getClassId();
ClassDefinition nestedCd = classDefMap.get(classId);
if (nestedCd != null) {
registerClassDefinition(nestedCd, classDefMap, checkClassDefErrors);
portableContext.registerClassDefinition(nestedCd);
} else if (checkClassDefErrors) {
throw new HazelcastSerializationException("Could not find registered ClassDefinition for class-id: " + classId);
}
}
}
portableContext.registerClassDefinition(cd);
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class AbstractSerializationService method serializerFor.
protected final SerializerAdapter serializerFor(Object object) {
//1-NULL serializer
if (object == null) {
return nullSerializerAdapter;
}
Class type = object.getClass();
//2-Default serializers, Dataserializable, Portable, primitives, arrays, String and some helper Java types(BigInteger etc)
SerializerAdapter serializer = lookupDefaultSerializer(type);
//3-Custom registered types by user
if (serializer == null) {
serializer = lookupCustomSerializer(type);
}
//4-JDK serialization ( Serializable and Externalizable )
if (serializer == null && !overrideJavaSerialization) {
serializer = lookupJavaSerializer(type);
}
//5-Global serializer if registered by user
if (serializer == null) {
serializer = lookupGlobalSerializer(type);
}
if (serializer == null) {
if (active) {
throw new HazelcastSerializationException("There is no suitable serializer for " + type);
}
throw new HazelcastInstanceNotActiveException();
}
return serializer;
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writePortable.
@Override
public void writePortable(String fieldName, Portable portable) throws IOException {
if (portable == null) {
throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!");
}
int version = SerializationUtil.getPortableVersion(portable, context.getVersion());
ClassDefinition nestedClassDef = createNestedClassDef(portable, new ClassDefinitionBuilder(portable.getFactoryId(), portable.getClassId(), version));
builder.addPortableField(fieldName, nestedClassDef);
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class PortableNavigatorContext method initFinalPositionAndOffset.
/**
* Initialises the finalPosition and offset and validates the fieldCount against the given class definition
*/
private void initFinalPositionAndOffset(BufferObjectDataInput in, ClassDefinition cd) {
int fieldCount;
try {
// final position after portable is read
finalPosition = in.readInt();
fieldCount = in.readInt();
} catch (IOException e) {
throw new HazelcastSerializationException(e);
}
if (fieldCount != cd.getFieldCount()) {
throw new IllegalStateException("Field count[" + fieldCount + "] in stream does not match " + cd);
}
offset = in.position();
}
Aggregations