use of com.hazelcast.spi.impl.operationservice.TargetAware 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;
}
use of com.hazelcast.spi.impl.operationservice.TargetAware in project hazelcast by hazelcast.
the class Invocation method initInvocationTarget.
/**
* Initializes the invocation target.
*
* @throws Exception if the initialization was a failure
*/
final void initInvocationTarget() throws Exception {
Member previousTargetMember = targetMember;
T target = getInvocationTarget();
if (target == null) {
throw newTargetNullException();
}
targetMember = toTargetMember(target);
if (targetMember != null) {
targetAddress = targetMember.getAddress();
} else {
targetAddress = toTargetAddress(target);
}
memberListVersion = context.clusterService.getMemberListVersion();
if (targetMember == null) {
if (previousTargetMember != null) {
// then it means a member left.
throw new MemberLeftException(previousTargetMember);
}
if (!(isJoinOperation(op) || isWanReplicationOperation(op))) {
throw new TargetNotMemberException(target, op.getPartitionId(), op.getClass().getName(), op.getServiceName());
}
}
if (op instanceof TargetAware) {
((TargetAware) op).setTarget(targetAddress);
}
}
use of com.hazelcast.spi.impl.operationservice.TargetAware in project hazelcast by hazelcast.
the class OperationBackupHandler method sendMultipleBackups.
private int sendMultipleBackups(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int totalBackups) {
int sendSyncBackups = 0;
Operation backupOp = getBackupOperation(backupAwareOp);
if (!(backupOp instanceof TargetAware)) {
// optimize common case: serialize operation once and send to multiple targets
Data backupOpData = nodeEngine.getSerializationService().toData(backupOp);
for (int replicaIndex = 1; replicaIndex <= totalBackups; replicaIndex++) {
PartitionReplica target = partition.getReplica(replicaIndex);
if (target == null) {
continue;
}
if (skipSendingBackupToTarget(partition, target)) {
continue;
}
boolean isSyncBackup = replicaIndex <= syncBackups;
Backup backup = newBackup(backupAwareOp, backupOpData, replicaVersions, replicaIndex, isSyncBackup);
outboundOperationHandler.send(backup, target.address());
if (isSyncBackup) {
sendSyncBackups++;
}
}
} else {
for (int replicaIndex = 1; replicaIndex <= totalBackups; replicaIndex++) {
int syncBackupSent = sendSingleBackup(backupAwareOp, partition, replicaVersions, syncBackups, replicaIndex);
sendSyncBackups += syncBackupSent;
}
}
return sendSyncBackups;
}
Aggregations