Search in sources :

Example 46 with MapOperation

use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.

the class WanMapSupportingService method handleAddOrUpdate.

private void handleAddOrUpdate(WanMapAddOrUpdateEvent replicationUpdate) {
    SplitBrainMergePolicy mergePolicy = replicationUpdate.getMergePolicy();
    String mapName = replicationUpdate.getObjectName();
    MapOperationProvider operationProvider = mapServiceContext.getMapOperationProvider(mapName);
    SerializationService serializationService = nodeEngine.getSerializationService();
    MapMergeTypes<Object, Object> mergingEntry = createMergingEntry(serializationService, replicationUpdate.getEntryView());
    // noinspection unchecked
    MapOperation operation = operationProvider.createMergeOperation(mapName, mergingEntry, (SplitBrainMergePolicy<Object, MapMergeTypes<Object, Object>, Object>) mergePolicy, true);
    try {
        int partitionId = nodeEngine.getPartitionService().getPartitionId(replicationUpdate.getEntryView().getKey());
        Future future = nodeEngine.getOperationService().invokeOnPartition(SERVICE_NAME, operation, partitionId);
        future.get();
        wanEventTypeCounters.incrementUpdate(mapName);
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) SerializationService(com.hazelcast.internal.serialization.SerializationService) Future(java.util.concurrent.Future) MapMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes) MapOperationProvider(com.hazelcast.map.impl.operation.MapOperationProvider) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 47 with MapOperation

use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.

the class MapPartitionIterator method fetch.

protected List fetch() {
    String name = mapProxy.getName();
    MapOperationProvider operationProvider = mapProxy.getOperationProvider();
    MapOperation operation = prefetchValues ? operationProvider.createFetchEntriesOperation(name, pointers, fetchSize) : operationProvider.createFetchKeysOperation(name, pointers, fetchSize);
    AbstractCursor cursor = invoke(operation);
    setIterationPointers(cursor.getBatch(), cursor.getIterationPointers());
    return cursor.getBatch();
}
Also used : MapOperationProvider(com.hazelcast.map.impl.operation.MapOperationProvider) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 48 with MapOperation

use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.

the class TransactionalMapProxySupport method replaceInternal.

Data replaceInternal(Data key, Data value, NearCachingHook hook) {
    boolean unlockImmediately = !valueMap.containsKey(key);
    VersionedValue versionedValue = lockAndGet(key, tx.getTimeoutMillis());
    if (versionedValue.value == null) {
        if (unlockImmediately) {
            unlock(key, versionedValue);
            return null;
        }
        addUnlockTransactionRecord(key, versionedValue.version);
        return null;
    }
    MapOperation operation = operationProvider.createTxnSetOperation(name, key, value, versionedValue.version, UNSET);
    tx.add(new MapTransactionLogRecord(name, key, getPartitionId(key), operation, tx.getOwnerUuid(), tx.getTxnId(), hook));
    return versionedValue.value;
}
Also used : MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 49 with MapOperation

use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.

the class TransactionalMapProxySupport method containsKeyInternal.

boolean containsKeyInternal(Data dataKey, Object objectKey, boolean skipNearCacheLookup) {
    if (!skipNearCacheLookup && nearCacheEnabled) {
        Object nearCacheKey = serializeKeys ? dataKey : objectKey;
        Object cachedValue = getCachedValue(nearCacheKey, false);
        if (cachedValue != NOT_CACHED) {
            return cachedValue != null;
        }
    }
    MapOperation operation = operationProvider.createContainsKeyOperation(name, dataKey);
    operation.setThreadId(ThreadUtil.getThreadId());
    int partitionId = partitionService.getPartitionId(dataKey);
    try {
        Future future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
        return (Boolean) future.get();
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : Future(java.util.concurrent.Future) TransactionalDistributedObject(com.hazelcast.spi.impl.TransactionalDistributedObject) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 50 with MapOperation

use of com.hazelcast.map.impl.operation.MapOperation in project hazelcast by hazelcast.

the class TransactionalMapProxySupport method replaceIfSameInternal.

boolean replaceIfSameInternal(Data key, Object oldValue, Data newValue, NearCachingHook hook) {
    boolean unlockImmediately = !valueMap.containsKey(key);
    VersionedValue versionedValue = lockAndGet(key, tx.getTimeoutMillis());
    if (!isEquals(oldValue, versionedValue.value)) {
        if (unlockImmediately) {
            unlock(key, versionedValue);
            return false;
        }
        addUnlockTransactionRecord(key, versionedValue.version);
        return false;
    }
    MapOperation operation = operationProvider.createTxnSetOperation(name, key, newValue, versionedValue.version, UNSET);
    tx.add(new MapTransactionLogRecord(name, key, getPartitionId(key), operation, tx.getOwnerUuid(), tx.getTxnId(), hook));
    return true;
}
Also used : MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Aggregations

MapOperation (com.hazelcast.map.impl.operation.MapOperation)80 MapOperationProvider (com.hazelcast.map.impl.operation.MapOperationProvider)25 Data (com.hazelcast.internal.serialization.Data)23 Future (java.util.concurrent.Future)16 Data (com.hazelcast.nio.serialization.Data)6 ArrayList (java.util.ArrayList)5 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 MapService (com.hazelcast.map.impl.MapService)3 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)3 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)3 AbstractDistributedObject (com.hazelcast.spi.impl.AbstractDistributedObject)3 InitializingObject (com.hazelcast.spi.impl.InitializingObject)3 InternalCompletableFuture.newCompletedFuture (com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture)3 InvocationFuture (com.hazelcast.spi.impl.operationservice.impl.InvocationFuture)3 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 EntryView (com.hazelcast.core.EntryView)2 EntryProcessor (com.hazelcast.map.EntryProcessor)2