Search in sources :

Example 6 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class SerializerHookLoader method load.

private void load() {
    try {
        final Iterator<SerializerHook> hooks = ServiceLoader.iterator(SerializerHook.class, FACTORY_ID, classLoader);
        while (hooks.hasNext()) {
            final SerializerHook hook = hooks.next();
            final Class serializationType = hook.getSerializationType();
            if (serializationType != null) {
                serializers.put(serializationType, hook);
            }
        }
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
    if (serializerConfigs != null) {
        for (SerializerConfig serializerConfig : serializerConfigs) {
            Serializer serializer = serializerConfig.getImplementation();
            Class serializationType = serializerConfig.getTypeClass();
            if (serializationType == null) {
                try {
                    serializationType = ClassLoaderUtil.loadClass(classLoader, serializerConfig.getTypeClassName());
                } catch (ClassNotFoundException e) {
                    throw new HazelcastSerializationException(e);
                }
            }
            if (serializer == null) {
                serializer = createSerializerInstance(serializerConfig, serializationType);
            }
            register(serializationType, serializer);
        }
    }
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializerHook(com.hazelcast.nio.serialization.SerializerHook) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) Serializer(com.hazelcast.nio.serialization.Serializer)

Example 7 with HazelcastSerializationException

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

Example 8 with HazelcastSerializationException

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

Example 9 with HazelcastSerializationException

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

Example 10 with HazelcastSerializationException

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);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)17 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)5 IOException (java.io.IOException)3 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)2 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 DataSerializableFactory (com.hazelcast.nio.serialization.DataSerializableFactory)2 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)2 Portable (com.hazelcast.nio.serialization.Portable)2 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)2 Serializer (com.hazelcast.nio.serialization.Serializer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)1 SerializerConfig (com.hazelcast.config.SerializerConfig)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 InputOutputFactory (com.hazelcast.internal.serialization.InputOutputFactory)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 SerializationUtil.isNullData (com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData)1