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);
}
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;
}
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;
}
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);
}
}
}
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);
}
Aggregations