Search in sources :

Example 31 with OperationService

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

the class RequestMapDataOperation method run.

@Override
public void run() throws Exception {
    ILogger logger = getLogger();
    Address callerAddress = getCallerAddress();
    int partitionId = getPartitionId();
    NodeEngine nodeEngine = getNodeEngine();
    if (logger.isFineEnabled()) {
        logger.fine("Caller " + callerAddress + " requested copy of replicated map '" + name + "' (partitionId " + partitionId + ") from " + nodeEngine.getThisAddress());
    }
    ReplicatedMapService service = getService();
    PartitionContainer container = service.getPartitionContainer(partitionId);
    ReplicatedRecordStore store = container.getOrCreateRecordStore(name);
    store.setLoaded(true);
    if (nodeEngine.getThisAddress().equals(callerAddress)) {
        return;
    }
    long version = store.getVersion();
    Set<RecordMigrationInfo> recordSet = getRecordSet(store);
    Operation op = new SyncReplicatedMapDataOperation(name, recordSet, version).setPartitionId(partitionId).setValidateTarget(false);
    OperationService operationService = nodeEngine.getOperationService();
    operationService.createInvocationBuilder(SERVICE_NAME, op, callerAddress).setTryCount(INVOCATION_TRY_COUNT).invoke();
}
Also used : Address(com.hazelcast.cluster.Address) PartitionContainer(com.hazelcast.replicatedmap.impl.PartitionContainer) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) Operation(com.hazelcast.spi.impl.operationservice.Operation) RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ILogger(com.hazelcast.logging.ILogger) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 32 with OperationService

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

the class ClearOperation method replicateClearOperation.

private void replicateClearOperation(long version) {
    OperationService operationService = getNodeEngine().getOperationService();
    Collection<Address> members = getMemberAddresses();
    for (Address address : members) {
        Operation op = new ClearOperation(mapName, false, version).setPartitionId(getPartitionId()).setValidateTarget(false);
        operationService.createInvocationBuilder(getServiceName(), op, address).setTryCount(INVOCATION_TRY_COUNT).invoke();
    }
}
Also used : Address(com.hazelcast.cluster.Address) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) MutatingOperation(com.hazelcast.spi.impl.operationservice.MutatingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 33 with OperationService

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

the class XAResourceImpl method finalizeTransactionRemotely.

private void finalizeTransactionRemotely(Xid xid, boolean isCommit) throws XAException {
    NodeEngine nodeEngine = getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    OperationService operationService = nodeEngine.getOperationService();
    SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
    Data xidData = nodeEngine.toData(serializableXID);
    int partitionId = partitionService.getPartitionId(xidData);
    FinalizeRemoteTransactionOperation operation = new FinalizeRemoteTransactionOperation(xidData, isCommit);
    InternalCompletableFuture<Integer> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
    Integer errorCode;
    try {
        errorCode = future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
    if (errorCode != null) {
        throw new XAException(errorCode);
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) XAException(javax.transaction.xa.XAException) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Data(com.hazelcast.internal.serialization.Data) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) FinalizeRemoteTransactionOperation(com.hazelcast.transaction.impl.xa.operations.FinalizeRemoteTransactionOperation) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) MemberLeftException(com.hazelcast.core.MemberLeftException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ExecutionException(java.util.concurrent.ExecutionException) XAException(javax.transaction.xa.XAException)

Example 34 with OperationService

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

the class CacheProxy method getAll.

@Override
public Map<K, V> getAll(Set<? extends K> keys, ExpiryPolicy expiryPolicy) {
    ensureOpen();
    validateNotNull(keys);
    if (keys.isEmpty()) {
        return emptyMap();
    }
    final int keyCount = keys.size();
    final Set<Data> ks = createHashSet(keyCount);
    for (K key : keys) {
        validateNotNull(key);
        Data dataKey = serializationService.toData(key);
        ks.add(dataKey);
    }
    Map<K, V> result = createHashMap(keyCount);
    PartitionIdSet partitions = getPartitionsForKeys(ks);
    try {
        OperationFactory factory = operationProvider.createGetAllOperationFactory(ks, expiryPolicy);
        OperationService operationService = getNodeEngine().getOperationService();
        Map<Integer, Object> responses = operationService.invokeOnPartitions(getServiceName(), factory, partitions);
        for (Object response : responses.values()) {
            MapEntries mapEntries = serializationService.toObject(response);
            mapEntries.putAllToMap(serializationService, result);
        }
    } catch (Throwable e) {
        throw rethrowAllowedTypeFirst(e, CacheException.class);
    }
    return result;
}
Also used : CacheException(javax.cache.CacheException) Data(com.hazelcast.internal.serialization.Data) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapEntries(com.hazelcast.map.impl.MapEntries) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 35 with OperationService

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

the class CacheProxySupport method removeAllInternal.

protected void removeAllInternal(Set<? extends K> keys) {
    Set<Data> keysData = null;
    if (keys != null) {
        keysData = createHashSet(keys.size());
        for (K key : keys) {
            validateNotNull(key);
            keysData.add(serializationService.toData(key));
        }
    }
    int partitionCount = getNodeEngine().getPartitionService().getPartitionCount();
    Integer completionId = listenerCompleter.registerCompletionLatch(partitionCount);
    OperationService operationService = getNodeEngine().getOperationService();
    OperationFactory operationFactory = operationProvider.createRemoveAllOperationFactory(keysData, completionId);
    try {
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(getServiceName(), operationFactory);
        int completionCount = 0;
        for (Object result : results.values()) {
            if (result != null && result instanceof CacheClearResponse) {
                Object response = ((CacheClearResponse) result).getResponse();
                if (response instanceof Boolean) {
                    completionCount++;
                }
                if (response instanceof Throwable) {
                    throw (Throwable) response;
                }
            }
        }
        listenerCompleter.waitCompletionLatch(completionId, partitionCount - completionCount);
    } catch (Throwable t) {
        listenerCompleter.deregisterCompletionLatch(completionId);
        throw rethrowAllowedTypeFirst(t, CacheException.class);
    }
}
Also used : CacheException(javax.cache.CacheException) Data(com.hazelcast.internal.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

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