use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class CollectionTestUtil method getBackupSet.
/**
* Returns all backup items of an {@link ISet} by a given set name.
* <p>
* Note: You have to provide the {@link HazelcastInstance} you want to retrieve the backups from.
* Use {@link getBackupInstance} to retrieve the backup instance for a given replica index.
*
* @param backupInstance the {@link HazelcastInstance} to retrieve the backups from
* @param setName the set name
* @return a {@link Set} with the backup items
*/
public static <E> Set<E> getBackupSet(HazelcastInstance backupInstance, String setName) {
NodeEngineImpl nodeEngine = getNodeEngineImpl(backupInstance);
CollectionService service = nodeEngine.getService(SetService.SERVICE_NAME);
CollectionContainer collectionContainer = service.getContainerMap().get(setName);
if (collectionContainer == null) {
return emptySet();
}
// the replica items are retrieved via `getMap()`, the primary items via `getCollection()`
Map<Long, CollectionItem> map = collectionContainer.getMap();
Set<E> backupSet = new HashSet<E>();
SerializationService serializationService = nodeEngine.getSerializationService();
for (CollectionItem collectionItem : map.values()) {
E value = serializationService.toObject(collectionItem.getValue());
backupSet.add(value);
}
return backupSet;
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class WanReplicationConfigTest method testSerialization.
@Test
public void testSerialization() {
Map<String, Comparable> properties = new HashMap<>();
properties.put("key", "value");
WanConsumerConfig wanConsumerConfig = new WanConsumerConfig();
wanConsumerConfig.setProperties(properties);
wanConsumerConfig.setClassName("className");
wanConsumerConfig.setImplementation(new DummyWanConsumer());
WanBatchPublisherConfig wanPublisherConfig1 = new WanBatchPublisherConfig();
WanBatchPublisherConfig wanPublisherConfig2 = new WanBatchPublisherConfig();
List<WanBatchPublisherConfig> publisherConfigs = new LinkedList<>();
publisherConfigs.add(wanPublisherConfig1);
config.setName("name");
config.setConsumerConfig(wanConsumerConfig);
config.setBatchPublisherConfigs(publisherConfigs);
config.addBatchReplicationPublisherConfig(wanPublisherConfig2);
ArrayList<WanCustomPublisherConfig> customPublishers = new ArrayList<>(1);
customPublishers.add(new WanCustomPublisherConfig());
config.setCustomPublisherConfigs(customPublishers);
config.addCustomPublisherConfig(new WanCustomPublisherConfig());
SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
Data serialized = serializationService.toData(config);
WanReplicationConfig deserialized = serializationService.toObject(serialized);
assertWanReplicationConfig(config, deserialized);
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class MergePolicyConfigTest method testSerialization.
@Test
public void testSerialization() {
config.setPolicy(DiscardMergePolicy.class.getName());
config.setBatchSize(1234);
SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
Data serialized = serializationService.toData(config);
MergePolicyConfig deserialized = serializationService.toObject(serialized);
assertEquals(config.getPolicy(), deserialized.getPolicy());
assertEquals(config.getBatchSize(), deserialized.getBatchSize());
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class AbstractCollectionProxyImpl method getAll.
private Collection<E> getAll() {
CollectionGetAllOperation operation = new CollectionGetAllOperation(name);
SerializableList result = invoke(operation);
List<Data> collection = result.getCollection();
SerializationService serializationService = getNodeEngine().getSerializationService();
return new UnmodifiableLazyList(collection, serializationService);
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class MapChunk method writeChunk.
/**
* This method writes a map's main data, which is key-value
* pairs, to output stream.
* <p>
* If number of written bytes exceeds chunk limit, it stops writing.
* Next key-values pairs are written in subsequent chunks later.
*/
protected final void writeChunk(ObjectDataOutput out, MapChunkContext context) throws IOException {
SerializationService ss = context.getSerializationService();
long recordCount = 0;
out.writeString(context.getMapName());
Iterator<Map.Entry<Data, Record>> entries = context.getIterator();
while (entries.hasNext()) {
Map.Entry<Data, Record> entry = entries.next();
Data dataKey = entry.getKey();
Record record = entry.getValue();
Data dataValue = ss.toData(record.getValue());
IOUtil.writeData(out, dataKey);
Records.writeRecord(out, record, dataValue);
Records.writeExpiry(out, context.getExpiryMetadata(dataKey));
recordCount++;
if (isEndOfChunk.getAsBoolean()) {
break;
}
}
incrementReplicationRecordCount(recordCount);
if (!entries.hasNext()) {
incrementReplicationCount();
}
// indicates end of chunk
IOUtil.writeData(out, null);
}
Aggregations