org.infinispan.transaction.impl.LocalTransaction Maven / Gradle / Ivy
package org.infinispan.transaction.impl;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.transaction.Transaction;
import org.infinispan.commands.write.ClearCommand;
import org.infinispan.commands.write.WriteCommand;
import org.infinispan.commons.CacheException;
import org.infinispan.commons.util.CollectionFactory;
import org.infinispan.container.entries.CacheEntry;
import org.infinispan.container.entries.RepeatableReadEntry;
import org.infinispan.context.Flag;
import org.infinispan.context.impl.FlagBitSets;
import org.infinispan.remoting.transport.Address;
import org.infinispan.topology.CacheTopology;
import org.infinispan.transaction.xa.GlobalTransaction;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
/**
* Object that holds transaction's state on the node where it originated; as opposed to {@link RemoteTransaction}.
*
* @author [email protected]
* @author Pedro Ruivo
* @since 5.0
*/
public abstract class LocalTransaction extends AbstractCacheTransaction {
private static final Log log = LogFactory.getLog(LocalTransaction.class);
private static final boolean trace = log.isTraceEnabled();
private Set remoteLockedNodes;
private final Transaction transaction;
private final boolean implicitTransaction;
private volatile boolean isFromRemoteSite;
private boolean prepareSent;
private boolean commitOrRollbackSent;
public LocalTransaction(Transaction transaction, GlobalTransaction tx, boolean implicitTransaction, int topologyId,
long txCreationTime) {
super(tx, topologyId, txCreationTime);
this.transaction = transaction;
this.implicitTransaction = implicitTransaction;
}
public final void addModification(WriteCommand mod) {
if (trace) log.tracef("Adding modification %s. Mod list is %s", mod, modifications);
if (modifications == null) {
// we need to synchronize this collection to be able to get a valid snapshot from another thread during state transfer
modifications = Collections.synchronizedList(new LinkedList());
}
if (mod.hasAnyFlag(FlagBitSets.CACHE_MODE_LOCAL)) {
hasLocalOnlyModifications = true;
}
modifications.add(mod);
}
public void locksAcquired(Collection nodes) {
if (trace) log.tracef("Adding remote locks on %s. Remote locks are %s", nodes, remoteLockedNodes);
if (remoteLockedNodes == null)
remoteLockedNodes = new HashSet<>(nodes);
else
remoteLockedNodes.addAll(nodes);
}
public Collection getRemoteLocksAcquired(){
if (remoteLockedNodes == null) return Collections.emptySet();
return remoteLockedNodes;
}
public void clearRemoteLocksAcquired() {
if (remoteLockedNodes != null) remoteLockedNodes.clear();
}
public Transaction getTransaction() {
return transaction;
}
@Override
public Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy