Search in sources :

Example 21 with OperationService

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

the class MasterConfirmationOperation method run.

@Override
public void run() {
    final Address endpoint = getCallerAddress();
    if (endpoint == null) {
        return;
    }
    final ClusterServiceImpl clusterService = getService();
    final ILogger logger = getLogger();
    final MemberImpl member = clusterService.getMember(endpoint);
    if (member == null) {
        logger.warning("MasterConfirmation has been received from " + endpoint + ", but it is not a member of this cluster!");
        OperationService operationService = getNodeEngine().getOperationService();
        operationService.send(new MemberRemoveOperation(clusterService.getThisAddress()), endpoint);
    } else {
        if (clusterService.isMaster()) {
            clusterService.getClusterHeartbeatManager().acceptMasterConfirmation(member, timestamp);
        } else {
            logger.warning(endpoint + " has sent MasterConfirmation, but this node is not master!");
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) ILogger(com.hazelcast.logging.ILogger) OperationService(com.hazelcast.spi.OperationService)

Example 22 with OperationService

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

the class ReplicaSyncRequest method sendRetryResponse.

/** Send a response to the replica to retry the replica sync */
private void sendRetryResponse() {
    NodeEngine nodeEngine = getNodeEngine();
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    ReplicaSyncRetryResponse response = new ReplicaSyncRetryResponse();
    response.setPartitionId(partitionId).setReplicaIndex(replicaIndex);
    Address target = getCallerAddress();
    OperationService operationService = nodeEngine.getOperationService();
    operationService.send(response, target);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) OperationService(com.hazelcast.spi.OperationService)

Example 23 with OperationService

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

the class MapNearCacheManager method createRepairingInvalidationTask.

private RepairingTask createRepairingInvalidationTask() {
    ExecutionService executionService = nodeEngine.getExecutionService();
    ClusterService clusterService = nodeEngine.getClusterService();
    OperationService operationService = nodeEngine.getOperationService();
    HazelcastProperties properties = nodeEngine.getProperties();
    ILogger logger = nodeEngine.getLogger(RepairingTask.class);
    MetaDataFetcher metaDataFetcher = new MemberMapMetaDataFetcher(clusterService, operationService, logger);
    String localUuid = nodeEngine.getLocalMember().getUuid();
    return new RepairingTask(metaDataFetcher, executionService.getGlobalTaskScheduler(), partitionService, properties, localUuid, logger);
}
Also used : HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) MemberMapMetaDataFetcher(com.hazelcast.map.impl.nearcache.invalidation.MemberMapMetaDataFetcher) ClusterService(com.hazelcast.internal.cluster.ClusterService) RepairingTask(com.hazelcast.internal.nearcache.impl.invalidation.RepairingTask) ILogger(com.hazelcast.logging.ILogger) OperationService(com.hazelcast.spi.OperationService) ExecutionService(com.hazelcast.spi.ExecutionService) MetaDataFetcher(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataFetcher) MemberMapMetaDataFetcher(com.hazelcast.map.impl.nearcache.invalidation.MemberMapMetaDataFetcher)

Example 24 with OperationService

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;
}
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 25 with OperationService

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);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) OperationService(com.hazelcast.spi.OperationService)

Aggregations

OperationService (com.hazelcast.spi.OperationService)135 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)48 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 HazelcastInstance (com.hazelcast.core.HazelcastInstance)45 Operation (com.hazelcast.spi.Operation)39 NodeEngine (com.hazelcast.spi.NodeEngine)30 Address (com.hazelcast.nio.Address)26 Future (java.util.concurrent.Future)26 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)24 Config (com.hazelcast.config.Config)21 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)21 Member (com.hazelcast.core.Member)19 Data (com.hazelcast.nio.serialization.Data)14 ArrayList (java.util.ArrayList)11 Node (com.hazelcast.instance.Node)7 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)7 ExecutionException (java.util.concurrent.ExecutionException)7 TimeoutException (java.util.concurrent.TimeoutException)7 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)6