Search in sources :

Example 76 with Operation

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

the class OperationBackupHandler method checkServiceNamespaces.

private void checkServiceNamespaces(BackupAwareOperation backupAwareOp, Operation backupOp) {
    Operation op = (Operation) backupAwareOp;
    Object service;
    try {
        service = op.getService();
    } catch (Exception ignored) {
        // operation doesn't know its service name
        return;
    }
    if (service instanceof FragmentedMigrationAwareService) {
        assert backupAwareOp instanceof ServiceNamespaceAware : service + " is instance of FragmentedMigrationAwareService, " + backupAwareOp + " should implement ServiceNamespaceAware!";
        assert backupOp instanceof ServiceNamespaceAware : service + " is instance of FragmentedMigrationAwareService, " + backupOp + " should implement ServiceNamespaceAware!";
    } else {
        assert !(backupAwareOp instanceof ServiceNamespaceAware) : service + " is NOT instance of FragmentedMigrationAwareService, " + backupAwareOp + " should NOT implement ServiceNamespaceAware!";
        assert !(backupOp instanceof ServiceNamespaceAware) : service + " is NOT instance of FragmentedMigrationAwareService, " + backupOp + " should NOT implement ServiceNamespaceAware!";
    }
}
Also used : ServiceNamespaceAware(com.hazelcast.internal.services.ServiceNamespaceAware) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) FragmentedMigrationAwareService(com.hazelcast.internal.partition.FragmentedMigrationAwareService)

Example 77 with Operation

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

the class OperationBackupHandler method sendSingleBackup.

private int sendSingleBackup(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int replica) {
    Operation backupOp = getBackupOperation(backupAwareOp);
    PartitionReplica target = partition.getReplica(replica);
    if (target != null) {
        if (skipSendingBackupToTarget(partition, target)) {
            return 0;
        }
        // without any unnecessary memory allocation and copy when it is used as object inside `Backup`.
        if (backupOp instanceof TargetAware) {
            ((TargetAware) backupOp).setTarget(target.address());
        }
        boolean isSyncBackup = syncBackups == 1;
        Backup backup = newBackup(backupAwareOp, backupOp, replicaVersions, 1, isSyncBackup);
        outboundOperationHandler.send(backup, target.address());
        if (isSyncBackup) {
            return 1;
        }
    }
    return 0;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) TargetAware(com.hazelcast.spi.impl.operationservice.TargetAware) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 78 with Operation

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

the class OperationRunnerImpl method run.

@Override
public boolean run(Packet packet) throws Exception {
    long startNanos = System.nanoTime();
    boolean publishCurrentTask = publishCurrentTask();
    if (publishCurrentTask) {
        currentTask = packet;
    }
    ServerConnection connection = packet.getConn();
    Address caller = connection.getRemoteAddress();
    UUID callerUuid = connection.getRemoteUuid();
    Operation op = null;
    try {
        Object object = nodeEngine.toObject(packet);
        op = (Operation) object;
        op.setNodeEngine(nodeEngine);
        setCallerAddress(op, caller);
        setConnection(op, connection);
        setCallerUuidIfNotSet(op, callerUuid);
        setOperationResponseHandler(op);
        if (!ensureValidMember(op)) {
            return false;
        }
        if (publishCurrentTask) {
            currentTask = null;
        }
        return run(op, startNanos);
    } catch (Throwable throwable) {
        // If exception happens we need to extract the callId from the bytes directly!
        long callId = extractOperationCallId(packet);
        outboundResponseHandler.send(connection.getConnectionManager(), caller, new ErrorResponse(throwable, callId, packet.isUrgent()));
        logOperationDeserializationException(throwable, callId);
        throw ExceptionUtil.rethrow(throwable);
    } finally {
        if (op != null) {
            op.clearThreadContext();
        }
        if (publishCurrentTask) {
            currentTask = null;
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.impl.operationservice.OperationAccessor.setCallerAddress) ServerConnection(com.hazelcast.internal.server.ServerConnection) Operations.isJoinOperation(com.hazelcast.spi.impl.operationservice.Operations.isJoinOperation) ReadonlyOperation(com.hazelcast.spi.impl.operationservice.ReadonlyOperation) BlockingOperation(com.hazelcast.spi.impl.operationservice.BlockingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) Operations.isMigrationOperation(com.hazelcast.spi.impl.operationservice.Operations.isMigrationOperation) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operations.isWanReplicationOperation(com.hazelcast.spi.impl.operationservice.Operations.isWanReplicationOperation) UUID(java.util.UUID) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 79 with Operation

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

the class CacheProxySupport method replaceAsyncInternal.

protected <T> InvocationFuture<T> replaceAsyncInternal(K key, V oldValue, V newValue, ExpiryPolicy expiryPolicy, boolean hasOldValue, boolean isGet, boolean withCompletionEvent) {
    ensureOpen();
    if (hasOldValue) {
        validateNotNull(key, oldValue, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, oldValue, newValue);
    } else {
        validateNotNull(key, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, newValue);
    }
    Data keyData = serializationService.toData(key);
    Data oldValueData = serializationService.toData(oldValue);
    Data newValueData = serializationService.toData(newValue);
    Operation operation;
    if (isGet) {
        operation = operationProvider.createGetAndReplaceOperation(keyData, newValueData, expiryPolicy, IGNORE_COMPLETION);
    } else {
        operation = operationProvider.createReplaceOperation(keyData, oldValueData, newValueData, expiryPolicy, IGNORE_COMPLETION);
    }
    return invoke(operation, keyData, withCompletionEvent);
}
Also used : Data(com.hazelcast.internal.serialization.Data) MutableOperation(com.hazelcast.cache.impl.operation.MutableOperation) CacheListenerRegistrationOperation(com.hazelcast.cache.impl.operation.CacheListenerRegistrationOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 80 with Operation

use of com.hazelcast.spi.impl.operationservice.Operation 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)

Aggregations

Operation (com.hazelcast.spi.impl.operationservice.Operation)271 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)79 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)56 Address (com.hazelcast.cluster.Address)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)25 Data (com.hazelcast.internal.serialization.Data)24 Future (java.util.concurrent.Future)24 Member (com.hazelcast.cluster.Member)22 ArrayList (java.util.ArrayList)21 NodeEngine (com.hazelcast.spi.impl.NodeEngine)18 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)17 AssertTask (com.hazelcast.test.AssertTask)15 ILogger (com.hazelcast.logging.ILogger)14 UrgentSystemOperation (com.hazelcast.spi.impl.operationservice.UrgentSystemOperation)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 Config (com.hazelcast.config.Config)12 CompletableFuture (java.util.concurrent.CompletableFuture)12