use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class MapReduceUtil method executeOperation.
public static <V> List<V> executeOperation(Collection<Member> members, OperationFactory operationFactory, MapReduceService mapReduceService, NodeEngine nodeEngine) {
final OperationService operationService = nodeEngine.getOperationService();
final List<InternalCompletableFuture<V>> futures = new ArrayList<InternalCompletableFuture<V>>();
final List<V> results = new ArrayList<V>();
final List<Exception> exceptions = new ArrayList<Exception>(members.size());
for (Member member : members) {
try {
Operation operation = operationFactory.createOperation();
if (nodeEngine.getThisAddress().equals(member.getAddress())) {
// Locally we can call the operation directly
operation.setNodeEngine(nodeEngine);
operation.setCallerUuid(nodeEngine.getLocalMember().getUuid());
operation.setService(mapReduceService);
operation.run();
V response = (V) operation.getResponse();
if (response != null) {
results.add(response);
}
} else {
InvocationBuilder ib = operationService.createInvocationBuilder(SERVICE_NAME, operation, member.getAddress());
final InternalCompletableFuture<V> future = ib.invoke();
futures.add(future);
}
} catch (Exception e) {
exceptions.add(e);
}
}
for (InternalCompletableFuture<V> future : futures) {
try {
V response = future.join();
if (response != null) {
results.add(response);
}
} catch (Exception e) {
exceptions.add(e);
}
}
if (exceptions.size() > 0) {
throw new RemoteMapReduceException("Exception on mapreduce operation", exceptions);
}
return results;
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class TransactionalMultiMapProxySupport method nextId.
private long nextId(Data key) {
final NodeEngine nodeEngine = getNodeEngine();
TxnGenerateRecordIdOperation operation = new TxnGenerateRecordIdOperation(name, key);
try {
int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
final OperationService operationService = nodeEngine.getOperationService();
Future<Long> f = operationService.invokeOnPartition(MultiMapService.SERVICE_NAME, operation, partitionId);
return f.get();
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class TransactionalMultiMapProxySupport method size.
public int size() {
checkTransactionActive();
try {
final OperationService operationService = getNodeEngine().getOperationService();
final Map<Integer, Object> results = operationService.invokeOnAllPartitions(MultiMapService.SERVICE_NAME, new MultiMapOperationFactory(name, MultiMapOperationFactory.OperationFactoryType.SIZE));
int size = 0;
for (Object obj : results.values()) {
if (obj == null) {
continue;
}
Integer result = getNodeEngine().toObject(obj);
size += result;
}
for (Data key : txMap.keySet()) {
MultiMapTransactionLogRecord log = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key));
if (log != null) {
size += log.size();
}
}
return size;
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class TransactionalMultiMapProxySupport method lockAndGet.
private MultiMapResponse lockAndGet(Data key, long timeout, long ttl) {
final NodeEngine nodeEngine = getNodeEngine();
boolean blockReads = tx.getTransactionType() == TransactionType.ONE_PHASE;
TxnLockAndGetOperation operation = new TxnLockAndGetOperation(name, key, timeout, ttl, getThreadId(), blockReads);
try {
int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
final OperationService operationService = nodeEngine.getOperationService();
Future<MultiMapResponse> f = operationService.invokeOnPartition(MultiMapService.SERVICE_NAME, operation, partitionId);
return f.get();
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class RingbufferProxy method readManyAsync.
@Override
public ICompletableFuture<ReadResultSet<E>> readManyAsync(long startSequence, int minCount, int maxCount, IFunction<E, Boolean> filter) {
checkSequence(startSequence);
checkNotNegative(minCount, "minCount can't be smaller than 0");
checkTrue(maxCount >= minCount, "maxCount should be equal or larger than minCount");
checkTrue(minCount <= config.getCapacity(), "the minCount should be smaller than or equal to the capacity");
checkTrue(maxCount <= MAX_BATCH_SIZE, "maxCount can't be larger than " + MAX_BATCH_SIZE);
Operation op = new ReadManyOperation(name, startSequence, minCount, maxCount, filter).setPartitionId(partitionId);
OperationService operationService = getOperationService();
return operationService.createInvocationBuilder(null, op, partitionId).setCallTimeout(Long.MAX_VALUE).invoke();
}
Aggregations