Package org.infinispan.commands.tx
Class PrepareCommand
- java.lang.Object
-
- org.infinispan.commands.tx.AbstractTransactionBoundaryCommand
-
- org.infinispan.commands.tx.PrepareCommand
-
- All Implemented Interfaces:
CacheRpcCommand,ReplicableCommand,TopologyAffectedCommand,TransactionBoundaryCommand,VisitableCommand,RemoteLockCommand,TransactionalRemoteLockCommand
- Direct Known Subclasses:
VersionedPrepareCommand
public class PrepareCommand extends AbstractTransactionBoundaryCommand implements TransactionalRemoteLockCommand
Command corresponding to the 1st phase of 2PC.- Since:
- 4.0
- Author:
- Manik Surtani (manik@jboss.org), Mircea.Markus@jboss.com
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.commands.VisitableCommand
VisitableCommand.LoadType
-
-
Field Summary
Fields Modifier and Type Field Description static byteCOMMAND_IDprotected WriteCommand[]modificationsprotected booleanonePhaseCommitprotected booleanretriedCommand-
Fields inherited from class org.infinispan.commands.tx.AbstractTransactionBoundaryCommand
cacheName, globalTx
-
-
Constructor Summary
Constructors Constructor Description PrepareCommand(ByteString cacheName)PrepareCommand(ByteString cacheName, GlobalTransaction gtx, boolean onePhaseCommit, WriteCommand... modifications)PrepareCommand(ByteString cacheName, GlobalTransaction gtx, List<WriteCommand> commands, boolean onePhaseCommit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectacceptVisitor(InvocationContext ctx, Visitor visitor)Accept a visitor, and return the result of accepting this visitor.PrepareCommandcopy()RemoteTxInvocationContextcreateContext(ComponentRegistry componentRegistry)It creates the transaction context.Collection<?>getAffectedKeys()bytegetCommandId()Used by marshallers to convert this command into an id for streaming.ObjectgetKeyLockOwner()It returns the lock owner of the key.Collection<?>getKeysToLock()It returns aCollectionwith the keys to be lock.WriteCommand[]getModifications()booleanhasModifications()booleanhasSkipLocking()It checks if this command should acquire locks.booleanhasZeroLockAcquisition()CompletionStage<?>invokeAsync(ComponentRegistry registry)Invoke the command asynchronously.booleanisOnePhaseCommit()booleanisReplayEntryWrapping()If set to true, then the keys touched by this transaction are to be wrapped again and original ones discarded.booleanisRetriedCommand()booleanisReturnValueExpected()If true, a return value will be provided when performed remotely.voidreadFrom(ObjectInput input)Reads this instance from the stream written byReplicableCommand.writeTo(ObjectOutput).voidsetReplayEntryWrapping(boolean replayEntryWrapping)voidsetRetriedCommand(boolean retriedCommand)StringtoString()voidwriteTo(ObjectOutput output)Writes this instance to theObjectOutput.-
Methods inherited from class org.infinispan.commands.tx.AbstractTransactionBoundaryCommand
equals, getCacheName, getGlobalTransaction, getOrigin, getTopologyId, hashCode, invalidRemoteTxReturnValue, loadType, markTransactionAsRemote, setOrigin, setTopologyId, visitRemoteTransaction
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.infinispan.commands.ReplicableCommand
canBlock, invoke, invokeAsync, isSuccessful
-
Methods inherited from interface org.infinispan.commands.VisitableCommand
init
-
-
-
-
Field Detail
-
COMMAND_ID
public static final byte COMMAND_ID
- See Also:
- Constant Field Values
-
modifications
protected WriteCommand[] modifications
-
onePhaseCommit
protected boolean onePhaseCommit
-
retriedCommand
protected boolean retriedCommand
-
-
Constructor Detail
-
PrepareCommand
public PrepareCommand(ByteString cacheName, GlobalTransaction gtx, boolean onePhaseCommit, WriteCommand... modifications)
-
PrepareCommand
public PrepareCommand(ByteString cacheName, GlobalTransaction gtx, List<WriteCommand> commands, boolean onePhaseCommit)
-
PrepareCommand
public PrepareCommand(ByteString cacheName)
-
-
Method Detail
-
invokeAsync
public CompletionStage<?> invokeAsync(ComponentRegistry registry) throws Throwable
Description copied from interface:CacheRpcCommandInvoke the command asynchronously.This method replaces
ReplicableCommand.invoke()for remote execution. The default implementation andReplicableCommand.invoke()will be removed in future versions.- Specified by:
invokeAsyncin interfaceCacheRpcCommand- Overrides:
invokeAsyncin classAbstractTransactionBoundaryCommand- Throws:
Throwable
-
createContext
public RemoteTxInvocationContext createContext(ComponentRegistry componentRegistry)
Description copied from interface:TransactionalRemoteLockCommandIt creates the transaction context.- Specified by:
createContextin interfaceTransactionalRemoteLockCommand- Returns:
- the
TxInvocationContext.
-
getKeysToLock
public Collection<?> getKeysToLock()
Description copied from interface:RemoteLockCommandIt returns aCollectionwith the keys to be lock.It may return an empty collection if no keys needs to be locked independently of the return value of
RemoteLockCommand.hasSkipLocking(). It may contains duplicated keys andnullis not a valid return value.- Specified by:
getKeysToLockin interfaceRemoteLockCommand- Returns:
- a
Collectionof keys to lock.
-
getKeyLockOwner
public Object getKeyLockOwner()
Description copied from interface:RemoteLockCommandIt returns the lock owner of the key.Usually, in transaction caches it is the
GlobalTransactionand in non-transactional caches theCommandInvocationId.- Specified by:
getKeyLockOwnerin interfaceRemoteLockCommand- Returns:
- the lock owner of the key.
-
hasZeroLockAcquisition
public boolean hasZeroLockAcquisition()
- Specified by:
hasZeroLockAcquisitionin interfaceRemoteLockCommand- Returns:
- it the locks should be acquire with 0 (zero) acquisition timeout.
-
hasSkipLocking
public boolean hasSkipLocking()
Description copied from interface:RemoteLockCommandIt checks if this command should acquire locks.- Specified by:
hasSkipLockingin interfaceRemoteLockCommand- Returns:
trueif locks should be acquired for the keys inRemoteLockCommand.getKeysToLock().
-
acceptVisitor
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
Description copied from interface:VisitableCommandAccept a visitor, and return the result of accepting this visitor.- Specified by:
acceptVisitorin interfaceVisitableCommand- Parameters:
ctx- invocation contextvisitor- visitor to accept- Returns:
- arbitrary return value
- Throws:
Throwable- in the event of problems
-
getModifications
public WriteCommand[] getModifications()
-
isOnePhaseCommit
public boolean isOnePhaseCommit()
-
getCommandId
public byte getCommandId()
Description copied from interface:ReplicableCommandUsed by marshallers to convert this command into an id for streaming.- Specified by:
getCommandIdin interfaceReplicableCommand- Returns:
- the method id of this command. This is compatible with pre-2.2.0 MethodCall ids.
-
writeTo
public void writeTo(ObjectOutput output) throws IOException
Description copied from interface:ReplicableCommandWrites this instance to theObjectOutput.- Specified by:
writeToin interfaceReplicableCommand- Overrides:
writeToin classAbstractTransactionBoundaryCommand- Parameters:
output- the stream.- Throws:
IOException- if an error occurred during the I/O.
-
readFrom
public void readFrom(ObjectInput input) throws IOException, ClassNotFoundException
Description copied from interface:ReplicableCommandReads this instance from the stream written byReplicableCommand.writeTo(ObjectOutput).- Specified by:
readFromin interfaceReplicableCommand- Overrides:
readFromin classAbstractTransactionBoundaryCommand- Parameters:
input- the stream to read.- Throws:
IOException- if an error occurred during the I/O.ClassNotFoundException- if it tries to load an undefined class.
-
copy
public PrepareCommand copy()
-
toString
public String toString()
- Overrides:
toStringin classAbstractTransactionBoundaryCommand
-
hasModifications
public boolean hasModifications()
-
getAffectedKeys
public Collection<?> getAffectedKeys()
-
isReplayEntryWrapping
public boolean isReplayEntryWrapping()
If set to true, then the keys touched by this transaction are to be wrapped again and original ones discarded.
-
setReplayEntryWrapping
public void setReplayEntryWrapping(boolean replayEntryWrapping)
- See Also:
isReplayEntryWrapping()
-
isReturnValueExpected
public boolean isReturnValueExpected()
Description copied from interface:ReplicableCommandIf true, a return value will be provided when performed remotely. Otherwise, a remoteResponseGeneratormay choose to simply return null to save on marshalling costs.- Specified by:
isReturnValueExpectedin interfaceReplicableCommand- Overrides:
isReturnValueExpectedin classAbstractTransactionBoundaryCommand- Returns:
- true or false
-
isRetriedCommand
public boolean isRetriedCommand()
-
setRetriedCommand
public void setRetriedCommand(boolean retriedCommand)
-
-