use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.
the class MapProxySupport method size.
@Override
public int size() {
try {
OperationFactory sizeOperationFactory = operationProvider.createMapSizeOperationFactory(name);
Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, sizeOperationFactory);
incrementOtherOperationsStat();
long total = 0;
for (Object result : results.values()) {
Integer size = toObject(result);
total += size;
}
return toIntSize(total);
} catch (Throwable t) {
throw rethrow(t);
}
}
use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.
the class MapProxySupport method removeAllInternal.
protected void removeAllInternal(Predicate predicate) {
try {
if (predicate instanceof PartitionPredicate) {
PartitionPredicate partitionPredicate = (PartitionPredicate) predicate;
OperationFactory operation = operationProvider.createPartitionWideEntryWithPredicateOperationFactory(name, ENTRY_REMOVING_PROCESSOR, partitionPredicate.getTarget());
Data partitionKey = toDataWithStrategy(partitionPredicate.getPartitionKey());
int partitionId = partitionService.getPartitionId(partitionKey);
// invokeOnPartitions is used intentionally here, instead of invokeOnPartition, since
// the later one doesn't support PartitionAwareOperationFactory, which we need to use
// to speed up the removal operation using global indexes
// (see PartitionWideEntryWithPredicateOperationFactory.createFactoryOnRunner).
operationService.invokeOnPartitions(SERVICE_NAME, operation, singletonList(partitionId));
} else {
OperationFactory operation = operationProvider.createPartitionWideEntryWithPredicateOperationFactory(name, ENTRY_REMOVING_PROCESSOR, predicate);
operationService.invokeOnAllPartitions(SERVICE_NAME, operation);
}
} catch (Throwable t) {
throw rethrow(t);
}
}
use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.
the class MultiMapProxySupport method invokePutAllOperation.
// NB: this method is generally copied from MapProxySupport#invokePutAllOperation
private InternalCompletableFuture<Void> invokePutAllOperation(Address address, List<Integer> memberPartitions, MapEntries[] entriesPerPartition) {
int size = memberPartitions.size();
int[] partitions = new int[size];
int index = 0;
for (Integer partitionId : memberPartitions) {
if (entriesPerPartition[partitionId] != null) {
partitions[index++] = partitionId;
}
}
if (index == 0) {
return newCompletedFuture(null);
}
// trim partition array to real size
if (index < size) {
partitions = Arrays.copyOf(partitions, index);
size = index;
}
index = 0;
MapEntries[] entries = new MapEntries[size];
long totalSize = 0;
for (int partitionId : partitions) {
totalSize += entriesPerPartition[partitionId].size();
entries[index++] = entriesPerPartition[partitionId];
entriesPerPartition[partitionId] = null;
}
if (totalSize == 0) {
return newCompletedFuture(null);
}
OperationFactory factory = new MultiMapPutAllOperationFactory(name, partitions, entries);
long startTimeNanos = System.nanoTime();
CompletableFuture<Map<Integer, Object>> future = operationService.invokeOnPartitionsAsync(MultiMapService.SERVICE_NAME, factory, singletonMap(address, asIntegerList(partitions)));
InternalCompletableFuture<Void> resultFuture = new InternalCompletableFuture<>();
long finalTotalSize = totalSize;
future.whenCompleteAsync((response, t) -> {
if (t == null) {
getService().getLocalMultiMapStatsImpl(name).incrementPutLatencyNanos(finalTotalSize, System.nanoTime() - startTimeNanos);
resultFuture.complete(null);
} else {
resultFuture.completeExceptionally(t);
}
}, CALLER_RUNS);
return resultFuture;
}
use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.
the class CacheProxy method getAll.
@Override
public Map<K, V> getAll(Set<? extends K> keys, ExpiryPolicy expiryPolicy) {
ensureOpen();
validateNotNull(keys);
if (keys.isEmpty()) {
return emptyMap();
}
final int keyCount = keys.size();
final Set<Data> ks = createHashSet(keyCount);
for (K key : keys) {
validateNotNull(key);
Data dataKey = serializationService.toData(key);
ks.add(dataKey);
}
Map<K, V> result = createHashMap(keyCount);
PartitionIdSet partitions = getPartitionsForKeys(ks);
try {
OperationFactory factory = operationProvider.createGetAllOperationFactory(ks, expiryPolicy);
OperationService operationService = getNodeEngine().getOperationService();
Map<Integer, Object> responses = operationService.invokeOnPartitions(getServiceName(), factory, partitions);
for (Object response : responses.values()) {
MapEntries mapEntries = serializationService.toObject(response);
mapEntries.putAllToMap(serializationService, result);
}
} catch (Throwable e) {
throw rethrowAllowedTypeFirst(e, CacheException.class);
}
return result;
}
use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.
the class CacheProxy method size.
@Override
public int size() {
ensureOpen();
try {
OperationFactory operationFactory = operationProvider.createSizeOperationFactory();
Map<Integer, Object> results = getNodeEngine().getOperationService().invokeOnAllPartitions(getServiceName(), operationFactory);
long total = 0;
for (Object result : results.values()) {
total += (Integer) getNodeEngine().toObject(result);
}
return toIntSize(total);
} catch (Throwable t) {
throw rethrowAllowedTypeFirst(t, CacheException.class);
}
}
Aggregations