Search in sources :

Example 36 with Operation

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

the class MapProxySupport method clearInternal.

public void clearInternal() {
    try {
        Operation clearOperation = operationProvider.createClearOperation(name);
        clearOperation.setServiceName(SERVICE_NAME);
        BinaryOperationFactory factory = new BinaryOperationFactory(clearOperation, getNodeEngine());
        Map<Integer, Object> resultMap = operationService.invokeOnAllPartitions(SERVICE_NAME, factory);
        int clearedCount = 0;
        for (Object object : resultMap.values()) {
            clearedCount += (Integer) object;
        }
        if (clearedCount > 0) {
            publishMapEvent(clearedCount, CLEAR_ALL);
        }
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : BinaryOperationFactory(com.hazelcast.spi.impl.BinaryOperationFactory) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) Operation(com.hazelcast.spi.Operation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) AddInterceptorOperation(com.hazelcast.map.impl.operation.AddInterceptorOperation) RemoveInterceptorOperation(com.hazelcast.map.impl.operation.RemoveInterceptorOperation) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 37 with Operation

use of com.hazelcast.spi.Operation 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);
    }
}
Also used : IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) Operation(com.hazelcast.spi.Operation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) AddInterceptorOperation(com.hazelcast.map.impl.operation.AddInterceptorOperation) RemoveInterceptorOperation(com.hazelcast.map.impl.operation.RemoveInterceptorOperation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) OperationFactory(com.hazelcast.spi.OperationFactory) IsEmptyOperationFactory(com.hazelcast.map.impl.operation.IsEmptyOperationFactory) BinaryOperationFactory(com.hazelcast.spi.impl.BinaryOperationFactory) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)

Example 38 with Operation

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

the class NodeInvokerWrapper method invokeOnTarget.

@Override
public Future invokeOnTarget(Object operation, Address address) {
    checkNotNull(operation, "operation cannot be null");
    checkNotNull(address, "address cannot be null");
    Operation op = (Operation) operation;
    return operationService.invokeOnTarget(MapService.SERVICE_NAME, op, address);
}
Also used : Operation(com.hazelcast.spi.Operation)

Example 39 with Operation

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

the class QueryDispatcher method dispatchFullQueryOnLocalMemberOnQueryThread.

private List<Future<Result>> dispatchFullQueryOnLocalMemberOnQueryThread(Query query) {
    Operation operation = new QueryOperation(query);
    Future<Result> result = operationService.invokeOnTarget(MapService.SERVICE_NAME, operation, nodeEngine.getThisAddress());
    return singletonList(result);
}
Also used : Operation(com.hazelcast.spi.Operation)

Example 40 with Operation

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

the class QueryDispatcher method dispatchFullQueryOnAllMembersOnQueryThread.

private List<Future<Result>> dispatchFullQueryOnAllMembersOnQueryThread(Query query) {
    Collection<Member> members = clusterService.getMembers(DATA_MEMBER_SELECTOR);
    List<Future<Result>> futures = new ArrayList<Future<Result>>(members.size());
    for (Member member : members) {
        Operation operation = new QueryOperation(query);
        Future<Result> future = operationService.invokeOnTarget(MapService.SERVICE_NAME, operation, member.getAddress());
        futures.add(future);
    }
    return futures;
}
Also used : ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Operation(com.hazelcast.spi.Operation) Member(com.hazelcast.core.Member)

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