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 ByteArraySerializerAdapter method read.
@Override
public Object read(ObjectDataInput in, Class aClass) throws IOException {
byte[] bytes = in.readByteArray();
if (bytes == null) {
return null;
}
if (!(serializer instanceof TypedByteArrayDeserializer)) {
throw new HazelcastSerializationException(serializer + " is not implementing the " + TypedByteArrayDeserializer.class + " interface. Please implement this interface to deserialize for class " + aClass);
}
TypedByteArrayDeserializer deserializer = (TypedByteArrayDeserializer) serializer;
return deserializer.read(bytes, aClass);
}
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);
}
Aggregations