use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class AbstractCacheProxy method size.
@Override
public int size() {
ensureOpen();
try {
OperationFactory operationFactory = operationProvider.createSizeOperationFactory();
Map<Integer, Object> results = getNodeEngine().getOperationService().invokeOnAllPartitions(getServiceName(), operationFactory);
int total = 0;
for (Object result : results.values()) {
//noinspection RedundantCast
total += (Integer) getNodeEngine().toObject(result);
}
return total;
} catch (Throwable t) {
throw rethrowAllowedTypeFirst(t, CacheException.class);
}
}
use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class AbstractCacheProxy method getAll.
@Override
public Map<K, V> getAll(Set<? extends K> keys, ExpiryPolicy expiryPolicy) {
ensureOpen();
validateNotNull(keys);
if (keys.isEmpty()) {
return Collections.EMPTY_MAP;
}
Set<Data> ks = new HashSet<Data>(keys.size());
for (K key : keys) {
Data dataKey = serializationService.toData(key);
ks.add(dataKey);
}
Map<K, V> result = new HashMap<K, V>();
Collection<Integer> 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.OperationFactory in project hazelcast by hazelcast.
the class AbstractInternalCacheProxy method removeAllInternal.
void removeAllInternal(Set<? extends K> keys) {
Set<Data> keysData = null;
if (keys != null) {
keysData = new HashSet<Data>();
for (K key : keys) {
keysData.add(serializationService.toData(key));
}
}
int partitionCount = getNodeEngine().getPartitionService().getPartitionCount();
Integer completionId = registerCompletionLatch(partitionCount);
OperationService operationService = getNodeEngine().getOperationService();
OperationFactory operationFactory = operationProvider.createRemoveAllOperationFactory(keysData, completionId);
try {
Map<Integer, Object> results = operationService.invokeOnAllPartitions(getServiceName(), operationFactory);
int completionCount = 0;
for (Object result : results.values()) {
if (result != null && result instanceof CacheClearResponse) {
Object response = ((CacheClearResponse) result).getResponse();
if (response instanceof Boolean) {
completionCount++;
}
if (response instanceof Throwable) {
throw (Throwable) response;
}
}
}
waitCompletionLatch(completionId, partitionCount - completionCount);
} catch (Throwable t) {
deregisterCompletionLatch(completionId);
throw rethrowAllowedTypeFirst(t, CacheException.class);
}
}
use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class AbstractMultiPartitionMessageTask method call.
@Override
protected Object call() throws Exception {
ClientEndpoint endpoint = getEndpoint();
OperationFactory operationFactory = new OperationFactoryWrapper(createOperationFactory(), endpoint.getUuid());
final InternalOperationService operationService = nodeEngine.getOperationService();
Map<Integer, Object> map = operationService.invokeOnPartitions(getServiceName(), operationFactory, getPartitions());
return reduce(map);
}
use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.
the class OperationDescriptors method toOperationDesc.
public static String toOperationDesc(Operation op) {
Class<? extends Operation> operationClass = op.getClass();
if (PartitionIteratingOperation.class.isAssignableFrom(operationClass)) {
PartitionIteratingOperation partitionIteratingOperation = (PartitionIteratingOperation) op;
OperationFactory operationFactory = partitionIteratingOperation.getOperationFactory();
String desc = DESCRIPTORS.get(operationFactory.getClass().getName());
if (desc == null) {
desc = PartitionIteratingOperation.class.getSimpleName() + "(" + operationFactory.getClass().getName() + ")";
DESCRIPTORS.put(operationFactory.getClass().getName(), desc);
}
return desc;
} else if (Backup.class.isAssignableFrom(operationClass)) {
Backup backup = (Backup) op;
Operation backupOperation = backup.getBackupOp();
String desc = DESCRIPTORS.get(backupOperation.getClass().getName());
if (desc == null) {
desc = Backup.class.getSimpleName() + "(" + backup.getBackupOp().getClass().getName() + ")";
DESCRIPTORS.put(backupOperation.getClass().getName(), desc);
}
return desc;
} else {
return operationClass.getName();
}
}
Aggregations