Search in sources :

Example 31 with HazelcastSerializationException

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;
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) PortableFactory(com.hazelcast.nio.serialization.PortableFactory)

Example 32 with HazelcastSerializationException

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);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 33 with HazelcastSerializationException

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;
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)

Example 34 with HazelcastSerializationException

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);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Example 35 with HazelcastSerializationException

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();
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) IOException(java.io.IOException)

Aggregations

HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)50 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)10 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)10 IOException (java.io.IOException)9 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 Config (com.hazelcast.config.Config)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 JavaSerializationFilterConfig (com.hazelcast.config.JavaSerializationFilterConfig)4 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)4 Portable (com.hazelcast.nio.serialization.Portable)4 TestDeserialized (example.serialization.TestDeserialized)4 Map (java.util.Map)4 HazelcastException (com.hazelcast.core.HazelcastException)3 FieldKind (com.hazelcast.nio.serialization.FieldKind)3 HashMap (java.util.HashMap)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)2