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 ([email protected]), [email protected]
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.commands.VisitableCommand
VisitableCommand.LoadType
-
-
Field Summary
Fields Modifier and Type Field Description static byte
COMMAND_ID
protected List<WriteCommand>
modifications
protected boolean
onePhaseCommit
protected boolean
retriedCommand
-
Fields inherited from class org.infinispan.commands.tx.AbstractTransactionBoundaryCommand
cacheName, globalTx
-
-
Constructor Summary
Constructors Constructor Description PrepareCommand(ByteString cacheName)
PrepareCommand(ByteString cacheName, GlobalTransaction gtx, List<WriteCommand> commands, boolean onePhaseCommit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
acceptVisitor(InvocationContext ctx, Visitor visitor)
Accept a visitor, and return the result of accepting this visitor.RemoteTxInvocationContext
createContext(ComponentRegistry componentRegistry)
It creates the transaction context.Collection<?>
getAffectedKeys()
byte
getCommandId()
Used by marshallers to convert this command into an id for streaming.Object
getKeyLockOwner()
It returns the lock owner of the key.Collection<?>
getKeysToLock()
It returns aCollection
with the keys to be lock.List<WriteCommand>
getModifications()
boolean
hasModifications()
boolean
hasSkipLocking()
It checks if this command should acquire locks.boolean
hasZeroLockAcquisition()
CompletionStage<?>
invokeAsync(ComponentRegistry registry)
Invoke the command asynchronously.boolean
isOnePhaseCommit()
boolean
isReplayEntryWrapping()
If set to true, then the keys touched by this transaction are to be wrapped again and original ones discarded.boolean
isRetriedCommand()
boolean
isReturnValueExpected()
If true, a return value will be provided when performed remotely.void
readFrom(ObjectInput input)
Reads this instance from the stream written byReplicableCommand.writeTo(ObjectOutput)
.void
setReplayEntryWrapping(boolean replayEntryWrapping)
void
setRetriedCommand(boolean retriedCommand)
String
toString()
void
writeTo(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, logThrowable
-
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 List<WriteCommand> modifications
-
onePhaseCommit
protected boolean onePhaseCommit
-
retriedCommand
protected boolean retriedCommand
-
-
Constructor Detail
-
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:CacheRpcCommand
Invoke the command asynchronously.This method replaces
ReplicableCommand.invoke()
for remote execution. The default implementation andReplicableCommand.invoke()
will be removed in future versions.- Specified by:
invokeAsync
in interfaceCacheRpcCommand
- Overrides:
invokeAsync
in classAbstractTransactionBoundaryCommand
- Throws:
Throwable
-
createContext
public RemoteTxInvocationContext createContext(ComponentRegistry componentRegistry)
Description copied from interface:TransactionalRemoteLockCommand
It creates the transaction context.- Specified by:
createContext
in interfaceTransactionalRemoteLockCommand
- Returns:
- the
TxInvocationContext
.
-
getKeysToLock
public Collection<?> getKeysToLock()
Description copied from interface:RemoteLockCommand
It returns aCollection
with 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 andnull
is not a valid return value.- Specified by:
getKeysToLock
in interfaceRemoteLockCommand
- Returns:
- a
Collection
of keys to lock.
-
getKeyLockOwner
public Object getKeyLockOwner()
Description copied from interface:RemoteLockCommand
It returns the lock owner of the key.Usually, in transaction caches it is the
GlobalTransaction
and in non-transactional caches theCommandInvocationId
.- Specified by:
getKeyLockOwner
in interfaceRemoteLockCommand
- Returns:
- the lock owner of the key.
-
hasZeroLockAcquisition
public boolean hasZeroLockAcquisition()
- Specified by:
hasZeroLockAcquisition
in interfaceRemoteLockCommand
- Returns:
- it the locks should be acquire with 0 (zero) acquisition timeout.
-
hasSkipLocking
public boolean hasSkipLocking()
Description copied from interface:RemoteLockCommand
It checks if this command should acquire locks.- Specified by:
hasSkipLocking
in interfaceRemoteLockCommand
- Returns:
true
if locks should be acquired for the keys inRemoteLockCommand.getKeysToLock()
.
-
acceptVisitor
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
Description copied from interface:VisitableCommand
Accept a visitor, and return the result of accepting this visitor.- Specified by:
acceptVisitor
in interfaceVisitableCommand
- Parameters:
ctx
- invocation contextvisitor
- visitor to accept- Returns:
- arbitrary return value
- Throws:
Throwable
- in the event of problems
-
getModifications
public List<WriteCommand> getModifications()
-
isOnePhaseCommit
public boolean isOnePhaseCommit()
-
getCommandId
public byte getCommandId()
Description copied from interface:ReplicableCommand
Used by marshallers to convert this command into an id for streaming.- Specified by:
getCommandId
in 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:ReplicableCommand
Writes this instance to theObjectOutput
.- Specified by:
writeTo
in interfaceReplicableCommand
- Overrides:
writeTo
in 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:ReplicableCommand
Reads this instance from the stream written byReplicableCommand.writeTo(ObjectOutput)
.- Specified by:
readFrom
in interfaceReplicableCommand
- Overrides:
readFrom
in 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.
-
toString
public String toString()
- Overrides:
toString
in 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:ReplicableCommand
If true, a return value will be provided when performed remotely. Otherwise, a remoteResponseGenerator
may choose to simply return null to save on marshalling costs.- Specified by:
isReturnValueExpected
in interfaceReplicableCommand
- Overrides:
isReturnValueExpected
in classAbstractTransactionBoundaryCommand
- Returns:
- true or false
-
isRetriedCommand
public boolean isRetriedCommand()
-
setRetriedCommand
public void setRetriedCommand(boolean retriedCommand)
-
-