org.infinispan.commands.tx.PrepareCommand Maven / Gradle / Ivy
package org.infinispan.commands.tx;
import static org.infinispan.commons.util.InfinispanCollections.forEach;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import org.infinispan.commands.Visitor;
import org.infinispan.commands.functional.ReadWriteKeyCommand;
import org.infinispan.commands.functional.ReadWriteKeyValueCommand;
import org.infinispan.commands.functional.ReadWriteManyCommand;
import org.infinispan.commands.functional.ReadWriteManyEntriesCommand;
import org.infinispan.commands.functional.WriteOnlyKeyCommand;
import org.infinispan.commands.functional.WriteOnlyKeyValueCommand;
import org.infinispan.commands.functional.WriteOnlyManyCommand;
import org.infinispan.commands.functional.WriteOnlyManyEntriesCommand;
import org.infinispan.commands.write.ComputeCommand;
import org.infinispan.commands.write.ComputeIfAbsentCommand;
import org.infinispan.commands.write.DataWriteCommand;
import org.infinispan.commands.write.PutKeyValueCommand;
import org.infinispan.commands.write.PutMapCommand;
import org.infinispan.commands.write.RemoveCommand;
import org.infinispan.commands.write.RemoveExpiredCommand;
import org.infinispan.commands.write.ReplaceCommand;
import org.infinispan.commands.write.WriteCommand;
import org.infinispan.commons.marshall.MarshallUtil;
import org.infinispan.context.InvocationContext;
import org.infinispan.context.impl.FlagBitSets;
import org.infinispan.context.impl.RemoteTxInvocationContext;
import org.infinispan.context.impl.TxInvocationContext;
import org.infinispan.notifications.cachelistener.CacheNotifier;
import org.infinispan.transaction.impl.RemoteTransaction;
import org.infinispan.transaction.xa.GlobalTransaction;
import org.infinispan.transaction.xa.recovery.RecoveryManager;
import org.infinispan.util.ByteString;
import org.infinispan.util.concurrent.CompletableFutures;
import org.infinispan.util.concurrent.locks.TransactionalRemoteLockCommand;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
/**
* Command corresponding to the 1st phase of 2PC.
*
* @author Manik Surtani ([email protected])
* @author [email protected]
* @since 4.0
*/
public class PrepareCommand extends AbstractTransactionBoundaryCommand implements TransactionalRemoteLockCommand {
private static final Log log = LogFactory.getLog(PrepareCommand.class);
private static boolean trace = log.isTraceEnabled();
public static final byte COMMAND_ID = 12;
protected WriteCommand[] modifications;
protected boolean onePhaseCommit;
protected CacheNotifier notifier;
protected RecoveryManager recoveryManager;
private transient boolean replayEntryWrapping = false;
protected boolean retriedCommand;
private static final WriteCommand[] EMPTY_WRITE_COMMAND_ARRAY = new WriteCommand[0];
public void initialize(CacheNotifier notifier, RecoveryManager recoveryManager) {
this.notifier = notifier;
this.recoveryManager = recoveryManager;
}
private PrepareCommand() {
super(null); // For command id uniqueness test
}
public PrepareCommand(ByteString cacheName, GlobalTransaction gtx, boolean onePhaseCommit, WriteCommand... modifications) {
super(cacheName);
this.globalTx = gtx;
this.modifications = modifications;
this.onePhaseCommit = onePhaseCommit;
}
public PrepareCommand(ByteString cacheName, GlobalTransaction gtx, List commands, boolean onePhaseCommit) {
super(cacheName);
this.globalTx = gtx;
this.modifications = commands == null || commands.isEmpty() ? null : commands.toArray(new WriteCommand[commands.size()]);
this.onePhaseCommit = onePhaseCommit;
}
public PrepareCommand(ByteString cacheName) {
super(cacheName);
}
@Override
public CompletableFuture
© 2015 - 2025 Weber Informatics LLC | Privacy Policy