Search in sources :

Example 56 with MapOperation

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

the class MapProxySupport method getInternal.

protected Object getInternal(Object key) {
    // TODO: action for read-backup true is not well tested
    Data keyData = toDataWithStrategy(key);
    if (mapConfig.isReadBackupData()) {
        Object fromBackup = readBackupDataOrNull(keyData);
        if (fromBackup != null) {
            return fromBackup;
        }
    }
    MapOperation operation = operationProvider.createGetOperation(name, keyData);
    operation.setThreadId(getThreadId());
    return invokeOperation(keyData, operation);
}
Also used : Data(com.hazelcast.internal.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 57 with MapOperation

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

the class MapProxySupport method getEntryViewInternal.

protected EntryView getEntryViewInternal(Data key) {
    int partitionId = partitionService.getPartitionId(key);
    MapOperation operation = operationProvider.createGetEntryViewOperation(name, key);
    operation.setThreadId(getThreadId());
    operation.setServiceName(SERVICE_NAME);
    try {
        Future future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
        return (EntryView) toObject(future.get());
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : EntryView(com.hazelcast.core.EntryView) Future(java.util.concurrent.Future) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 58 with MapOperation

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

the class MapProxySupport method getAsyncInternal.

protected InternalCompletableFuture<Data> getAsyncInternal(Object key) {
    Data keyData = toDataWithStrategy(key);
    int partitionId = partitionService.getPartitionId(keyData);
    MapOperation operation = operationProvider.createGetOperation(name, keyData);
    try {
        long startTimeNanos = Timer.nanos();
        InvocationFuture<Data> future = operationService.createInvocationBuilder(SERVICE_NAME, operation, partitionId).setResultDeserialized(false).setAsync().invoke();
        if (statisticsEnabled) {
            future.whenCompleteAsync(new IncrementStatsExecutionCallback<>(operation, startTimeNanos), CALLER_RUNS);
        }
        return future;
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : Data(com.hazelcast.internal.serialization.Data) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 59 with MapOperation

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

the class MapProxySupport method putIfAbsentInternal.

protected Data putIfAbsentInternal(Object key, Data value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) {
    Data keyData = toDataWithStrategy(key);
    MapOperation operation = newPutIfAbsentOperation(keyData, value, ttl, ttlUnit, maxIdle, maxIdleUnit);
    return (Data) invokeOperation(keyData, operation);
}
Also used : Data(com.hazelcast.internal.serialization.Data) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 60 with MapOperation

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

the class MapProxySupport method flush.

@Override
public void flush() {
    // TODO: add a feature to Management Center to sync cache to db completely
    try {
        MapOperation mapFlushOperation = operationProvider.createMapFlushOperation(name);
        BinaryOperationFactory operationFactory = new BinaryOperationFactory(mapFlushOperation, getNodeEngine());
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, operationFactory);
        List<Future> futures = new ArrayList<>();
        for (Entry<Integer, Object> entry : results.entrySet()) {
            Integer partitionId = entry.getKey();
            Long count = ((Long) entry.getValue());
            if (count != 0) {
                Operation operation = new AwaitMapFlushOperation(name, count);
                futures.add(operationService.invokeOnPartition(MapService.SERVICE_NAME, operation, partitionId));
            }
        }
        for (Future future : futures) {
            future.get();
        }
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : ArrayList(java.util.ArrayList) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MutableLong(com.hazelcast.internal.util.MutableLong) Future(java.util.concurrent.Future) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation)

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