Search in sources :

Example 41 with Portable

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

the class SampleMetadataResolver method resolve.

@Nullable
@SuppressWarnings("checkstyle:returncount")
static Metadata resolve(InternalSerializationService ss, Object target, boolean key) {
    try {
        if (target instanceof Data) {
            Data data = (Data) target;
            if (data.isPortable()) {
                ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(data);
                return resolvePortable(classDefinition, key);
            } else if (data.isCompact()) {
                return resolveCompact(ss.extractSchemaFromData(data), key);
            } else if (data.isJson()) {
                return null;
            } else {
                return resolveJava(ss.toObject(data).getClass(), key);
            }
        } else if (target instanceof VersionedPortable) {
            VersionedPortable portable = (VersionedPortable) target;
            ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), portable.getClassVersion());
            return resolvePortable(classDefinition, key);
        } else if (target instanceof Portable) {
            Portable portable = (Portable) target;
            ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), 0);
            return resolvePortable(classDefinition, key);
        } else if (target instanceof PortableGenericRecord) {
            return resolvePortable(((PortableGenericRecord) target).getClassDefinition(), key);
        } else if (target instanceof CompactGenericRecord) {
            return resolveCompact(((CompactGenericRecord) target).getSchema(), key);
        } else if (ss.isCompactSerializable(target)) {
            Schema schema = ss.extractSchemaFromObject(target);
            return resolveCompact(schema, key);
        } else if (target instanceof HazelcastJsonValue) {
            return null;
        } else {
            return resolveJava(target.getClass(), key);
        }
    } catch (Exception e) {
        return null;
    }
}
Also used : VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable) Portable(com.hazelcast.nio.serialization.Portable) PortableGenericRecord(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) CompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord) Data(com.hazelcast.internal.serialization.Data) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable) Nullable(javax.annotation.Nullable)

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