Search in sources :

Example 36 with OperationService

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

the class CacheProxyLoadAllTask method run.

@Override
public void run() {
    try {
        completionListener = injectDependencies(completionListener);
        OperationService operationService = nodeEngine.getOperationService();
        OperationFactory operationFactory;
        IPartitionService partitionService = nodeEngine.getPartitionService();
        Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
        int partitionCount = partitionService.getPartitionCount();
        Map<Integer, Object> results = createHashMap(partitionCount);
        for (Map.Entry<Address, List<Integer>> memberPartitions : memberPartitionsMap.entrySet()) {
            Set<Integer> partitions = new PartitionIdSet(partitionCount, memberPartitions.getValue());
            Set<Data> ownerKeys = filterOwnerKeys(partitionService, partitions);
            operationFactory = operationProvider.createLoadAllOperationFactory(ownerKeys, replaceExistingValues);
            Map<Integer, Object> memberResults;
            memberResults = operationService.invokeOnPartitions(serviceName, operationFactory, partitions);
            results.putAll(memberResults);
        }
        validateResults(results);
        if (completionListener != null) {
            completionListener.onCompletion();
        }
    } catch (Exception e) {
        if (completionListener != null) {
            completionListener.onException(e);
        }
    } catch (Throwable t) {
        if (t instanceof OutOfMemoryError) {
            throw rethrow(t);
        } else {
            if (completionListener != null) {
                completionListener.onException(new CacheException(t));
            }
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) CacheException(javax.cache.CacheException) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Data(com.hazelcast.internal.serialization.Data) CacheException(javax.cache.CacheException) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) List(java.util.List) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 37 with OperationService

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

the class ClientEngineImpl method getClientsInCluster.

Map<UUID, String> getClientsInCluster() {
    OperationService operationService = node.nodeEngine.getOperationService();
    Map<UUID, String> clientsMap = new HashMap<>();
    for (Member member : node.getClusterService().getMembers()) {
        Address target = member.getAddress();
        Operation clientInfoOperation = new GetConnectedClientsOperation();
        Future<Map<UUID, String>> future = operationService.invokeOnTarget(SERVICE_NAME, clientInfoOperation, target);
        try {
            Map<UUID, String> endpoints = future.get();
            if (endpoints == null) {
                continue;
            }
            // Merge connected clients according to their UUID
            clientsMap.putAll(endpoints);
        } catch (Exception e) {
            logger.warning("Cannot get client information from: " + target.toString(), e);
        }
    }
    return clientsMap;
}
Also used : Address(com.hazelcast.cluster.Address) InetSocketAddress(java.net.InetSocketAddress) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) LoginException(javax.security.auth.login.LoginException)

Example 38 with OperationService

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

the class QueueProxySupport method invoke.

private InvocationFuture<Object> invoke(Operation operation) {
    final NodeEngine nodeEngine = getNodeEngine();
    OperationService operationService = nodeEngine.getOperationService();
    return operationService.invokeOnPartition(QueueService.SERVICE_NAME, operation, getPartitionId());
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 39 with OperationService

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

the class QueueProxySupport method invokeAndGetData.

private Object invokeAndGetData(QueueOperation operation) {
    final NodeEngine nodeEngine = getNodeEngine();
    try {
        OperationService operationService = nodeEngine.getOperationService();
        Future f = operationService.invokeOnPartition(QueueService.SERVICE_NAME, operation, partitionId);
        return f.get();
    } catch (Throwable throwable) {
        throw rethrow(throwable);
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 40 with OperationService

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

the class QueueService method rollbackTransaction.

@Override
public void rollbackTransaction(UUID transactionId) {
    final Set<String> queueNames = containerMap.keySet();
    OperationService operationService = nodeEngine.getOperationService();
    for (String name : queueNames) {
        int partitionId = partitionService.getPartitionId(StringPartitioningStrategy.getPartitionKey(name));
        Operation operation = new QueueTransactionRollbackOperation(name, transactionId).setPartitionId(partitionId).setService(this).setNodeEngine(nodeEngine);
        operationService.invokeOnPartition(operation);
    }
}
Also used : QueueTransactionRollbackOperation(com.hazelcast.collection.impl.txnqueue.operations.QueueTransactionRollbackOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) QueueTransactionRollbackOperation(com.hazelcast.collection.impl.txnqueue.operations.QueueTransactionRollbackOperation) QueueMergeOperation(com.hazelcast.collection.impl.queue.operations.QueueMergeOperation) QueueReplicationOperation(com.hazelcast.collection.impl.queue.operations.QueueReplicationOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint)

Aggregations

OperationService (com.hazelcast.spi.impl.operationservice.OperationService)140 Operation (com.hazelcast.spi.impl.operationservice.Operation)55 Test (org.junit.Test)54 HazelcastInstance (com.hazelcast.core.HazelcastInstance)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)40 Address (com.hazelcast.cluster.Address)31 NodeEngine (com.hazelcast.spi.impl.NodeEngine)31 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)24 Future (java.util.concurrent.Future)24 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 Config (com.hazelcast.config.Config)22 Member (com.hazelcast.cluster.Member)21 Data (com.hazelcast.internal.serialization.Data)12 SlowTest (com.hazelcast.test.annotation.SlowTest)12 ClusterService (com.hazelcast.internal.cluster.ClusterService)9 ILogger (com.hazelcast.logging.ILogger)7 ArrayList (java.util.ArrayList)7 IPartitionService (com.hazelcast.internal.partition.IPartitionService)6