Search in sources :

Example 21 with Portable

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

the class QueryEntryTest method getAttribute_whenValueIsPortableObject_thenConvertedToData.

// ========================== getAttribute ===========================================
@Test
public void getAttribute_whenValueIsPortableObject_thenConvertedToData() {
    Data key = serializationService.toData("indexedKey");
    Portable value = new SampleObjects.PortableEmployee(30, "peter");
    QueryableEntry queryEntry = entry(key, value, Extractors.empty());
    // in the portable-data, the attribute 'name' is called 'n'. So if we can retrieve on n
    // correctly it shows that we have used the Portable data, not the actual Portable object
    Object result = queryEntry.getAttributeValue("n");
    assertEquals("peter", result);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with Portable

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

the class PortableSerializer method read.

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

Example 23 with Portable

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

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

the class DefaultPortableWriter method writePortableArray.

@Override
public void writePortableArray(String fieldName, Portable[] portables) throws IOException {
    FieldDefinition fd = setPosition(fieldName, FieldType.PORTABLE_ARRAY);
    final int len = portables == null ? NULL_ARRAY_LENGTH : portables.length;
    out.writeInt(len);
    out.writeInt(fd.getFactoryId());
    out.writeInt(fd.getClassId());
    if (len > 0) {
        final int offset = out.position();
        out.writeZeroBytes(len * 4);
        for (int i = 0; i < portables.length; i++) {
            Portable portable = portables[i];
            checkPortableAttributes(fd, portable);
            int position = out.position();
            out.writeInt(offset + i * INT_SIZE_IN_BYTES, position);
            serializer.writeInternal(out, portable);
        }
    }
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Example 25 with Portable

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

the class ClientRegressionWithMockNetworkTest method testClientPortableWithoutRegisteringToNode.

@Test
public void testClientPortableWithoutRegisteringToNode() {
    hazelcastFactory.newHazelcastInstance();
    final SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.addPortableFactory(5, new PortableFactory() {

        public Portable create(int classId) {
            return new SamplePortable();
        }
    });
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.setSerializationConfig(serializationConfig);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final IMap<Integer, SamplePortable> sampleMap = client.getMap(randomString());
    sampleMap.put(1, new SamplePortable(666));
    final SamplePortable samplePortable = sampleMap.get(1);
    assertEquals(666, samplePortable.a);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Portable (com.hazelcast.nio.serialization.Portable)26 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 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 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 Config (com.hazelcast.config.Config)4 MapStoreConfig (com.hazelcast.config.MapStoreConfig)4 SqlPredicate (com.hazelcast.query.SqlPredicate)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 SerializationConfig (com.hazelcast.config.SerializationConfig)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2