Search in sources :

Example 41 with Operation

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

the class TransactionImpl method replicateTxnLog.

private void replicateTxnLog() {
    if (skipBackupLogReplication()) {
        return;
    }
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    List<Future> futures = new ArrayList<Future>(backupAddresses.length);
    for (Address backupAddress : backupAddresses) {
        if (clusterService.getMember(backupAddress) != null) {
            Operation op = createReplicateTxBackupLogOperation();
            Future f = operationService.invokeOnTarget(SERVICE_NAME, op, backupAddress);
            futures.add(f);
        }
    }
    waitWithDeadline(futures, timeoutMillis, MILLISECONDS, replicationTxExceptionHandler);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.cluster.Address) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) PurgeTxBackupLogOperation(com.hazelcast.transaction.impl.operations.PurgeTxBackupLogOperation) ReplicateTxBackupLogOperation(com.hazelcast.transaction.impl.operations.ReplicateTxBackupLogOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) RollbackTxBackupLogOperation(com.hazelcast.transaction.impl.operations.RollbackTxBackupLogOperation) CreateTxBackupLogOperation(com.hazelcast.transaction.impl.operations.CreateTxBackupLogOperation)

Example 42 with Operation

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

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    factory.newHazelcastClient();
    factory.newHazelcastClient();
    Node node = getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, String>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, String> clients = future.get();
    assertEquals(2, clients.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with Operation

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

the class OperationDescriptors method toOperationDesc.

public static String toOperationDesc(Operation op) {
    Class<? extends Operation> operationClass = op.getClass();
    if (PartitionIteratingOperation.class.isAssignableFrom(operationClass)) {
        PartitionIteratingOperation partitionIteratingOperation = (PartitionIteratingOperation) op;
        OperationFactory operationFactory = partitionIteratingOperation.getOperationFactory();
        String desc = DESCRIPTORS.get(operationFactory.getClass().getName());
        if (desc == null) {
            desc = PartitionIteratingOperation.class.getSimpleName() + "(" + operationFactory.getClass().getName() + ")";
            DESCRIPTORS.put(operationFactory.getClass().getName(), desc);
        }
        return desc;
    } else if (Backup.class.isAssignableFrom(operationClass)) {
        Backup backup = (Backup) op;
        Operation backupOperation = backup.getBackupOp();
        String desc = DESCRIPTORS.get(backupOperation.getClass().getName());
        if (desc == null) {
            desc = Backup.class.getSimpleName() + "(" + backup.getBackupOp().getClass().getName() + ")";
            DESCRIPTORS.put(backupOperation.getClass().getName(), desc);
        }
        return desc;
    } else {
        return operationClass.getName();
    }
}
Also used : PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 44 with Operation

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

the class PartitionServiceProxy method isClusterSafe.

@Override
public boolean isClusterSafe() {
    Collection<Member> members = nodeEngine.getClusterService().getMembers();
    if (members == null || members.isEmpty()) {
        return true;
    }
    final Collection<Future<Boolean>> futures = new ArrayList<>(members.size());
    for (Member member : members) {
        final Address target = member.getAddress();
        final Operation operation = new SafeStateCheckOperation();
        final Future<Boolean> future = nodeEngine.getOperationService().invokeOnTarget(InternalPartitionService.SERVICE_NAME, operation, target);
        futures.add(future);
    }
    // todo this max wait is appropriate?
    final int maxWaitTime = getMaxWaitTime();
    Collection<Boolean> results = FutureUtil.returnWithDeadline(futures, maxWaitTime, TimeUnit.SECONDS, exceptionHandler);
    if (results.size() != futures.size()) {
        return false;
    }
    for (Boolean result : results) {
        if (!result) {
            return false;
        }
    }
    return true;
}
Also used : Address(com.hazelcast.cluster.Address) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) ArrayList(java.util.ArrayList) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) Future(java.util.concurrent.Future) Operation(com.hazelcast.spi.impl.operationservice.Operation) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) Member(com.hazelcast.cluster.Member)

Example 45 with Operation

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

the class ReplicaFragmentMigrationState method writeData.

@Override
public void writeData(ObjectDataOutput out) throws IOException {
    out.writeInt(namespaces.size());
    for (Map.Entry<ServiceNamespace, long[]> e : namespaces.entrySet()) {
        out.writeObject(e.getKey());
        out.writeLongArray(e.getValue());
    }
    out.writeInt(migrationOperations.size());
    for (Operation operation : migrationOperations) {
        out.writeObject(operation);
    }
    chunkSerDeHelper.writeChunkedOperations(out);
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Operation(com.hazelcast.spi.impl.operationservice.Operation) HashMap(java.util.HashMap) Map(java.util.Map)

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