use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class MapProxySupport method invokePutAllOperationFactory.
protected void invokePutAllOperationFactory(Address address, final long size, int[] partitions, MapEntries[] entries) throws Exception {
OperationFactory factory = operationProvider.createPutAllOperationFactory(name, partitions, entries);
final long time = System.currentTimeMillis();
operationService.invokeOnPartitions(SERVICE_NAME, factory, partitions);
localMapStats.incrementPuts(size, System.currentTimeMillis() - time);
}
use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class MapProxySupport method getAllObjectInternal.
protected void getAllObjectInternal(List<Data> keys, List<Object> resultingKeyValuePairs) {
if (keys == null || keys.isEmpty()) {
return;
}
if (keys.isEmpty()) {
return;
}
Collection<Integer> partitions = getPartitionsForKeys(keys);
Map<Integer, Object> responses;
try {
OperationFactory operationFactory = operationProvider.createGetAllOperationFactory(name, keys);
long time = System.currentTimeMillis();
responses = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitions);
for (Object response : responses.values()) {
MapEntries entries = toObject(response);
for (int i = 0; i < entries.size(); i++) {
resultingKeyValuePairs.add(toObject(entries.getKey(i)));
resultingKeyValuePairs.add(toObject(entries.getValue(i)));
}
}
localMapStats.incrementGets(keys.size(), System.currentTimeMillis() - time);
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class MapProxySupport method size.
public int size() {
try {
OperationFactory sizeOperationFactory = operationProvider.createMapSizeOperationFactory(name);
Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, sizeOperationFactory);
int total = 0;
for (Object result : results.values()) {
Integer size = toObject(result);
total += size;
}
return total;
} catch (Throwable t) {
throw rethrow(t);
}
}
use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class MapProxySupport method executeOnKeysInternal.
public Map executeOnKeysInternal(Set<Data> keys, EntryProcessor entryProcessor) {
// TODO: why are we not forwarding to executeOnKeysInternal(keys, entryProcessor, null) or some other kind of fake
// callback? now there is a lot of code duplication
Map<Object, Object> result = new HashMap<Object, Object>();
Collection<Integer> partitionsForKeys = getPartitionsForKeys(keys);
try {
OperationFactory operationFactory = operationProvider.createMultipleEntryOperationFactory(name, keys, entryProcessor);
Map<Integer, Object> results = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitionsForKeys);
for (Object object : results.values()) {
if (object != null) {
MapEntries mapEntries = (MapEntries) object;
mapEntries.putAllToMap(serializationService, result);
}
}
} catch (Throwable t) {
throw rethrow(t);
}
return result;
}
use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class MapProxySupport method waitUntilLoaded.
public void waitUntilLoaded() {
try {
int mapNamePartition = partitionService.getPartitionId(name);
// first we have to check if key-load finished - otherwise the loading on other partitions might not have started.
// In this case we can't invoke IsPartitionLoadedOperation -> they will return "true", but it won't be correct.
int sleepDurationMillis = INITIAL_WAIT_LOAD_SLEEP_MILLIS;
while (true) {
Operation op = new IsKeyLoadFinishedOperation(name);
Future<Boolean> loadingFuture = operationService.invokeOnPartition(SERVICE_NAME, op, mapNamePartition);
if (loadingFuture.get()) {
break;
}
// sleep with some back-off
TimeUnit.MILLISECONDS.sleep(sleepDurationMillis);
sleepDurationMillis = (sleepDurationMillis * 2 < MAXIMAL_WAIT_LOAD_SLEEP_MILLIS) ? sleepDurationMillis * 2 : MAXIMAL_WAIT_LOAD_SLEEP_MILLIS;
}
OperationFactory opFactory = new IsPartitionLoadedOperationFactory(name);
Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, opFactory);
// wait for all the data to be loaded on all partitions - wait forever
waitAllTrue(results, opFactory);
} catch (Throwable t) {
throw rethrow(t);
}
}
Aggregations