Search in sources :

Example 1 with MapMergePolicy

use of com.hazelcast.map.merge.MapMergePolicy in project hazelcast by hazelcast.

the class MapReplicationSupportingService method handleUpdate.

private void handleUpdate(MapReplicationUpdate replicationUpdate) {
    EntryView entryView = replicationUpdate.getEntryView();
    MapMergePolicy mergePolicy = replicationUpdate.getMergePolicy();
    String mapName = replicationUpdate.getMapName();
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    MapOperationProvider operationProvider = mapServiceContext.getMapOperationProvider(mapName);
    Data dataKey = mapServiceContext.toData(entryView.getKey(), mapContainer.getPartitioningStrategy());
    MapOperation operation = operationProvider.createMergeOperation(mapName, dataKey, entryView, mergePolicy, true);
    try {
        int partitionId = nodeEngine.getPartitionService().getPartitionId(entryView.getKey());
        Future f = nodeEngine.getOperationService().invokeOnPartition(SERVICE_NAME, operation, partitionId);
        f.get();
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
}
Also used : EntryView(com.hazelcast.core.EntryView) Future(java.util.concurrent.Future) Data(com.hazelcast.nio.serialization.Data) MapOperationProvider(com.hazelcast.map.impl.operation.MapOperationProvider) MapMergePolicy(com.hazelcast.map.merge.MapMergePolicy) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 2 with MapMergePolicy

use of com.hazelcast.map.merge.MapMergePolicy in project hazelcast by hazelcast.

the class MergePolicySerializationTest method testIssue2665.

@Test
public void testIssue2665() {
    String name = randomString();
    String serviceName = "hz:impl:mapService";
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, MyObject> map = instance.getMap(name);
    MyObject myObjectExisting = new MyObject();
    map.put("key", myObjectExisting);
    NodeEngineImpl nodeEngine = HazelcastTestSupport.getNode(instance).getNodeEngine();
    MapService mapService = nodeEngine.getService(serviceName);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    int partitionId = nodeEngine.getPartitionService().getPartitionId("key");
    Data dataKey = mapServiceContext.toData("key");
    RecordStore recordStore = mapServiceContext.getRecordStore(partitionId, name);
    MapMergePolicy mergePolicy = mapServiceContext.getMergePolicyProvider().getMergePolicy(PutIfAbsentMapMergePolicy.class.getName());
    EntryView<String, MyObject> mergingEntryView = new SimpleEntryView<String, MyObject>("key", new MyObject());
    recordStore.merge(dataKey, mergingEntryView, mergePolicy);
    int deSerializedCount = MyObject.deserializedCount;
    assertEquals(0, deSerializedCount);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Data(com.hazelcast.nio.serialization.Data) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) MapService(com.hazelcast.map.impl.MapService) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) MapMergePolicy(com.hazelcast.map.merge.MapMergePolicy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapMergePolicy (com.hazelcast.map.merge.MapMergePolicy)2 Data (com.hazelcast.nio.serialization.Data)2 EntryView (com.hazelcast.core.EntryView)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 SimpleEntryView (com.hazelcast.map.impl.SimpleEntryView)1 MapOperation (com.hazelcast.map.impl.operation.MapOperation)1 MapOperationProvider (com.hazelcast.map.impl.operation.MapOperationProvider)1 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)1 PutIfAbsentMapMergePolicy (com.hazelcast.map.merge.PutIfAbsentMapMergePolicy)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Future (java.util.concurrent.Future)1 Test (org.junit.Test)1