Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* It is placed between the {@link org.infinispan.statetransfer.StateTransferInterceptor} and the {@link
* org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor}.
*
* The acknowledges are sent after the lock is released and it interacts with the {@link
* org.infinispan.statetransfer.StateTransferInterceptor} to trigger the retries when topology changes while the
* commands are processing.
*
* @author Pedro Ruivo
* @since 9.0
*/
public class TriangleAckInterceptor extends DDAsyncInterceptor {
private static final Log log = LogFactory.getLog(TriangleAckInterceptor.class);
private static final boolean trace = log.isTraceEnabled();
private RpcManager rpcManager;
private CommandsFactory commandsFactory;
private CommandAckCollector commandAckCollector;
private final InvocationComposeHandler onLocalWriteCommand = this::onLocalWriteCommand;
private DistributionManager distributionManager;
private StateTransferManager stateTransferManager;
private Address localAddress;
private final InvocationComposeHandler onRemotePrimaryOwner = this::onRemotePrimaryOwner;
private final InvocationComposeHandler onRemoteBackupOwner = this::onRemoteBackupOwner;
@Inject
public void inject(RpcManager rpcManager, CommandsFactory commandsFactory, CommandAckCollector commandAckCollector,
DistributionManager distributionManager, StateTransferManager stateTransferManager) {
this.rpcManager = rpcManager;
this.commandsFactory = commandsFactory;
this.commandAckCollector = commandAckCollector;
this.distributionManager = distributionManager;
this.stateTransferManager = stateTransferManager;
}
@Start
public void start() {
localAddress = rpcManager.getAddress();
}
@Override
public BasicInvocationStage visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command)
throws Throwable {
return handleWriteCommand(ctx, command);
}
@Override
public BasicInvocationStage visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable {
return handleWriteCommand(ctx, command);
}
@Override
public BasicInvocationStage visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable {
return handleWriteCommand(ctx, command);
}
@Override
public BasicInvocationStage visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable {
if (ctx.isOriginLocal()) {
return handleLocalPutMapCommand(ctx, command);
} else {
return handleRemotePutMapCommand(ctx, command);
}
}
private BasicInvocationStage handleRemotePutMapCommand(InvocationContext ctx, PutMapCommand command) {
return invokeNext(ctx, command).compose((stage, rCtx, rCommand, rv, t) -> {
final PutMapCommand cmd = (PutMapCommand) rCommand;
if (t != null) {
sendExceptionAck(cmd.getCommandInvocationId(), cmd.getTopologyId(), t);
return stage;
}
int segment = distributionManager.getConsistentHash().getSegment(command.getMap().keySet().iterator().next());
if (cmd.isForwarded()) {
sendPutMapBackupAck(cmd, segment);
} else {
//noinspection unchecked
sendPrimaryPutMapAck(cmd, (Map