Search in sources :

Example 1 with Portable

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

the class PortableSerializer method createMorphingReader.

DefaultPortableReader createMorphingReader(BufferObjectDataInput in) throws IOException {
    int factoryId = in.readInt();
    int classId = in.readInt();
    int version = in.readInt();
    Portable portable = createNewPortableInstance(factoryId, classId);
    int portableVersion = findPortableVersion(factoryId, classId, portable);
    return createReader(in, factoryId, classId, version, portableVersion);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable)

Example 2 with Portable

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

the class PortableSerializer method readAndInitialize.

Portable readAndInitialize(BufferObjectDataInput in, int factoryId, int classId) throws IOException {
    Portable p = read(in, factoryId, classId);
    final ManagedContext managedContext = context.getManagedContext();
    return managedContext != null ? (Portable) managedContext.initialize(p) : p;
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) ManagedContext(com.hazelcast.core.ManagedContext)

Example 3 with Portable

use of com.hazelcast.nio.serialization.Portable 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 4 with Portable

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

the class AbstractNearCacheSerializationCountTest method prepareSerializationConfig.

/**
     * Adds the serialization configuration for the used {@link Portable} domain object to the given {@link SerializationConfig}.
     *
     * @param serializationConfig the given {@link SerializationConfig} for the {@link DataStructureAdapter}
     */
protected static void prepareSerializationConfig(SerializationConfig serializationConfig) {
    ClassDefinition classDefinition = new ClassDefinitionBuilder(SerializationCountingData.FACTORY_ID, SerializationCountingData.CLASS_ID).build();
    serializationConfig.addClassDefinition(classDefinition);
    serializationConfig.addPortableFactory(SerializationCountingData.FACTORY_ID, new PortableFactory() {

        @Override
        public Portable create(int classId) {
            return new SerializationCountingData();
        }
    });
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Example 5 with Portable

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

the class DefaultPortableReaderPerformanceTest method setup.

@Setup
public void setup() throws Exception {
    ss = new DefaultSerializationServiceBuilder().addPortableFactory(DefaultPortableReaderQuickTest.TestPortableFactory.ID, new DefaultPortableReaderQuickTest.TestPortableFactory()).build();
    Portable primitive = new DefaultPortableReaderTestStructure.PrimitivePortable();
    primitiveReader = reader(primitive);
    reader = reader(PORSCHE);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) Portable(com.hazelcast.nio.serialization.Portable) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

Portable (com.hazelcast.nio.serialization.Portable)41 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)10 Data (com.hazelcast.internal.serialization.Data)6 GroupPortable (com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.GroupPortable)6 NestedGroupPortable (com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.NestedGroupPortable)6 PrimitivePortable (com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.PrimitivePortable)6 GroupPortable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.GroupPortable)6 Portable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.Method.Portable)6 NestedGroupPortable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.NestedGroupPortable)6 PrimitivePortable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.PrimitivePortable)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)5 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)4 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)4 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2