use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class DelegatingSerializationService method serializerFor.
@Override
public SerializerAdapter serializerFor(Object object, boolean includeSchema) {
Class<?> clazz = object == null ? null : object.getClass();
SerializerAdapter serializer = null;
if (clazz != null) {
serializer = serializersByClass.get(clazz);
}
if (serializer == null) {
try {
serializer = delegate.serializerFor(object, includeSchema);
} catch (HazelcastSerializationException hse) {
throw serializationException(clazz, hse);
}
}
if (serializer == null) {
throw active ? serializationException(clazz) : new HazelcastInstanceNotActiveException();
}
return serializer;
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class AbstractSerializationService method serializerFor.
@SuppressWarnings("checkstyle:npathcomplexity")
public SerializerAdapter serializerFor(final Object object, boolean includeSchema) {
if (!active) {
throw notActiveExceptionSupplier.get();
}
// 1-NULL serializer
if (object == null) {
return nullSerializerAdapter;
}
final Class type = object.getClass();
// 2-Default serializers, Dataserializable, Compact, Portable, primitives, arrays, String and
// some helper Java types(BigInteger etc)
SerializerAdapter serializer = lookupDefaultSerializer(type, includeSchema);
// 3-Custom registered types by user
if (serializer == null || allowOverrideDefaultSerializers) {
SerializerAdapter customSerializer = lookupCustomSerializer(type);
if (customSerializer != null) {
serializer = customSerializer;
}
}
// 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);
}
// 6-Compact serializer
if (serializer == null && compactStreamSerializer.isEnabled()) {
serializer = getCompactSerializer(includeSchema);
}
if (serializer == null) {
throw new HazelcastSerializationException("There is no suitable serializer for " + type);
}
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 DataSerializableSerializer method readInternal.
private DataSerializable readInternal(ObjectDataInput in, Class aClass) throws IOException {
setInputVersion(in, version);
DataSerializable ds = null;
if (null != aClass) {
try {
ds = (DataSerializable) aClass.newInstance();
} catch (Exception e) {
e = tryClarifyInstantiationException(aClass, e);
throw new HazelcastSerializationException("Requested class " + aClass + " could not be instantiated.", e);
}
}
final byte header = in.readByte();
int id = 0;
int factoryId = 0;
String className = null;
try {
// BasicOperationService::extractOperationCallId
if (isFlagSet(header, IDS_FLAG)) {
factoryId = in.readInt();
final DataSerializableFactory dsf = factories.get(factoryId);
if (dsf == null) {
throw new HazelcastSerializationException("No DataSerializerFactory registered for namespace: " + factoryId);
}
id = in.readInt();
if (null == aClass) {
ds = dsf.create(id);
if (ds == null) {
throw new HazelcastSerializationException(dsf + " is not be able to create an instance for ID: " + id + " on factory ID: " + factoryId);
}
}
} else {
className = in.readString();
if (null == aClass) {
ds = ClassLoaderUtil.newInstance(in.getClassLoader(), className);
}
}
if (isFlagSet(header, EE_FLAG)) {
in.readByte();
in.readByte();
}
ds.readData(in);
return ds;
} catch (Exception e) {
e = tryClarifyNoSuchMethodException(in.getClassLoader(), className, e);
throw rethrowReadException(id, factoryId, className, e);
}
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException 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);
}
Aggregations