Search in sources :

Example 41 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class QueryDispatcher method dispatchPartitionScanQueryOnOwnerMemberOnPartitionThread.

protected Future<Result> dispatchPartitionScanQueryOnOwnerMemberOnPartitionThread(Query query, int partitionId) {
    Operation op = new QueryPartitionOperation(query);
    op.setPartitionId(partitionId);
    try {
        return operationService.invokeOnPartition(MapService.SERVICE_NAME, op, partitionId);
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : Operation(com.hazelcast.spi.Operation)

Example 42 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class BasicRecordStoreLoader method createOperation.

private Operation createOperation(List<Data> keyValueSequence, final AtomicInteger finishedBatchCounter) {
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    MapOperationProvider operationProvider = mapServiceContext.getMapOperationProvider(name);
    MapOperation operation = operationProvider.createPutFromLoadAllOperation(name, keyValueSequence);
    operation.setNodeEngine(nodeEngine);
    operation.setOperationResponseHandler(new OperationResponseHandler() {

        @Override
        public void sendResponse(Operation op, Object obj) {
            if (finishedBatchCounter.decrementAndGet() == 0) {
                loaded.set(true);
            }
        }
    });
    operation.setPartitionId(partitionId);
    OperationAccessor.setCallerAddress(operation, nodeEngine.getThisAddress());
    operation.setCallerUuid(nodeEngine.getLocalMember().getUuid());
    operation.setServiceName(MapService.SERVICE_NAME);
    return operation;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) MapOperation(com.hazelcast.map.impl.operation.MapOperation) Operation(com.hazelcast.spi.Operation) RemoveFromLoadAllOperation(com.hazelcast.map.impl.operation.RemoveFromLoadAllOperation) MapOperationProvider(com.hazelcast.map.impl.operation.MapOperationProvider) OperationResponseHandler(com.hazelcast.spi.OperationResponseHandler) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 43 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class NodeQueryCacheEndToEndConstructor method madePublishable.

private void madePublishable(String mapName, String cacheName) throws Exception {
    InvokerWrapper invokerWrapper = context.getInvokerWrapper();
    Collection<Member> memberList = context.getMemberList();
    List<Future> futures = new ArrayList<Future>(memberList.size());
    for (Member member : memberList) {
        Operation operation = new MadePublishableOperation(mapName, cacheName);
        Future future = invokerWrapper.invokeOnTarget(operation, member.getAddress());
        futures.add(future);
    }
    waitWithDeadline(futures, OPERATION_WAIT_TIMEOUT_MINUTES, MINUTES);
}
Also used : MadePublishableOperation(com.hazelcast.map.impl.querycache.subscriber.operation.MadePublishableOperation) InvokerWrapper(com.hazelcast.map.impl.querycache.InvokerWrapper) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) PublisherCreateOperation(com.hazelcast.map.impl.querycache.subscriber.operation.PublisherCreateOperation) Operation(com.hazelcast.spi.Operation) MadePublishableOperation(com.hazelcast.map.impl.querycache.subscriber.operation.MadePublishableOperation) Member(com.hazelcast.core.Member)

Example 44 with Operation

use of com.hazelcast.spi.Operation 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;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) Operation(com.hazelcast.spi.Operation) NotifyRemoteExceptionOperation(com.hazelcast.mapreduce.impl.operation.NotifyRemoteExceptionOperation) RemoteMapReduceException(com.hazelcast.mapreduce.RemoteMapReduceException) TimeoutException(java.util.concurrent.TimeoutException) RemoteMapReduceException(com.hazelcast.mapreduce.RemoteMapReduceException) OperationService(com.hazelcast.spi.OperationService) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) Member(com.hazelcast.core.Member)

Example 45 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class MultiMapTransactionLogRecord method writeData.

@Override
public void writeData(ObjectDataOutput out) throws IOException {
    out.writeUTF(name);
    out.writeInt(partitionId);
    out.writeInt(opList.size());
    for (Operation op : opList) {
        out.writeObject(op);
    }
    out.writeData(key);
    out.writeLong(ttl);
    out.writeLong(threadId);
}
Also used : Operation(com.hazelcast.spi.Operation)

Aggregations

Operation (com.hazelcast.spi.Operation)216 QuickTest (com.hazelcast.test.annotation.QuickTest)60 Test (org.junit.Test)60 OperationService (com.hazelcast.spi.OperationService)39 ParallelTest (com.hazelcast.test.annotation.ParallelTest)39 Future (java.util.concurrent.Future)19 Member (com.hazelcast.core.Member)18 Address (com.hazelcast.nio.Address)18 Data (com.hazelcast.nio.serialization.Data)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 AssertTask (com.hazelcast.test.AssertTask)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)15 ArrayList (java.util.ArrayList)15 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)14 NodeEngine (com.hazelcast.spi.NodeEngine)14 BackupAwareOperation (com.hazelcast.spi.BackupAwareOperation)13 BlockingOperation (com.hazelcast.spi.BlockingOperation)13 MapOperation (com.hazelcast.map.impl.operation.MapOperation)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 Config (com.hazelcast.config.Config)10