Search in sources :

Example 1 with Backup

use of com.hazelcast.spi.impl.operationservice.impl.operations.Backup 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 2 with Backup

use of com.hazelcast.spi.impl.operationservice.impl.operations.Backup in project hazelcast by hazelcast.

the class OperationBackupHandler method newBackup.

private static Backup newBackup(BackupAwareOperation backupAwareOp, Object backupOp, long[] replicaVersions, int replicaIndex, boolean respondBack) {
    Operation op = (Operation) backupAwareOp;
    Backup backup;
    if (backupOp instanceof Operation) {
        backup = new Backup((Operation) backupOp, op.getCallerAddress(), replicaVersions, respondBack, op.getClientCallId());
    } else if (backupOp instanceof Data) {
        backup = new Backup((Data) backupOp, op.getCallerAddress(), replicaVersions, respondBack, op.getClientCallId());
    } else {
        throw new IllegalArgumentException("Only 'Data' or 'Operation' typed backup operation is supported!");
    }
    backup.setPartitionId(op.getPartitionId()).setReplicaIndex(replicaIndex).setCallerUuid(op.getCallerUuid());
    if (hasActiveInvocation(op)) {
        setCallId(backup, op.getCallId());
    }
    return backup;
}
Also used : Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) Data(com.hazelcast.internal.serialization.Data) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 3 with Backup

use of com.hazelcast.spi.impl.operationservice.impl.operations.Backup 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 4 with Backup

use of com.hazelcast.spi.impl.operationservice.impl.operations.Backup in project hazelcast by hazelcast.

the class OperationDescriptorsTest method testBackupOperation.

@Test
public void testBackupOperation() throws UnknownHostException {
    Backup backup = new Backup(new DummyBackupOperation(), new Address("127.0.0.1", 5701), new long[] {}, false);
    String result = toOperationDesc(backup);
    assertEquals(format("Backup(%s)", DummyBackupOperation.class.getName()), result);
}
Also used : Address(com.hazelcast.cluster.Address) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with Backup

use of com.hazelcast.spi.impl.operationservice.impl.operations.Backup in project hazelcast by hazelcast.

the class OverloadedConnectionsPluginTest method toKey.

@Test
@SuppressWarnings("UnnecessaryBoxing")
public void toKey() {
    assertToKey(DummyOperation.class.getName(), new DummyOperation());
    assertToKey(Integer.class.getName(), Integer.valueOf(10));
    assertToKey("Backup(" + DummyOperation.class.getName() + ")", new Backup(new DummyOperation(), getAddress(local), new long[0], true));
}
Also used : Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) DummyOperation(com.hazelcast.spi.impl.operationservice.impl.DummyOperation) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

Backup (com.hazelcast.spi.impl.operationservice.impl.operations.Backup)7 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 BackupAwareOperation (com.hazelcast.spi.impl.operationservice.BackupAwareOperation)3 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)2 Data (com.hazelcast.internal.serialization.Data)2 TargetAware (com.hazelcast.spi.impl.operationservice.TargetAware)2 Test (org.junit.Test)2 Address (com.hazelcast.cluster.Address)1 OperationFactory (com.hazelcast.spi.impl.operationservice.OperationFactory)1 DummyOperation (com.hazelcast.spi.impl.operationservice.impl.DummyOperation)1 PartitionIteratingOperation (com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1