Package org.infinispan.commands.tx
Class AbstractTransactionBoundaryCommand
- java.lang.Object
-
- org.infinispan.commands.tx.AbstractTransactionBoundaryCommand
-
- All Implemented Interfaces:
CacheRpcCommand
,ReplicableCommand
,TopologyAffectedCommand
,TransactionBoundaryCommand
,VisitableCommand
- Direct Known Subclasses:
CommitCommand
,LockControlCommand
,PrepareCommand
,RollbackCommand
public abstract class AbstractTransactionBoundaryCommand extends Object implements TransactionBoundaryCommand
An abstract transaction boundary command that holds a reference to aGlobalTransaction
- 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 protected ByteString
cacheName
protected GlobalTransaction
globalTx
protected InvocationContextFactory
icf
protected AsyncInterceptorChain
invoker
protected org.infinispan.transaction.impl.TransactionTable
txTable
-
Constructor Summary
Constructors Constructor Description AbstractTransactionBoundaryCommand(ByteString cacheName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canBlock()
If true, the command is processed asynchronously in a thread provided by an Infinispan thread pool.boolean
equals(Object o)
ByteString
getCacheName()
GlobalTransaction
getGlobalTransaction()
Address
getOrigin()
Get the origin of the commandint
getTopologyId()
int
hashCode()
void
init(AsyncInterceptorChain chain, InvocationContextFactory icf, org.infinispan.transaction.impl.TransactionTable txTable)
protected Object
invalidRemoteTxReturnValue()
This is what is returned to remote callers when an invalid RemoteTransaction is encountered.CompletableFuture<Object>
invokeAsync()
Invoke the command asynchronously.boolean
isReturnValueExpected()
If true, a return value will be provided when performed remotely.VisitableCommand.LoadType
loadType()
void
markTransactionAsRemote(boolean isRemote)
Object
perform(InvocationContext ctx)
Performs the primary function of the command.void
readFrom(ObjectInput input)
Reads this instance from the stream written byReplicableCommand.writeTo(ObjectOutput)
.void
setOrigin(Address origin)
Sets the sender'sAddress
.void
setTopologyId(int topologyId)
String
toString()
protected void
visitRemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction tx)
void
writeTo(ObjectOutput output)
Writes this instance to theObjectOutput
.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.infinispan.commands.ReplicableCommand
getCommandId, invoke, isSuccessful
-
Methods inherited from interface org.infinispan.commands.VisitableCommand
acceptVisitor, ignoreCommandOnStatus, shouldInvoke
-
-
-
-
Field Detail
-
globalTx
protected GlobalTransaction globalTx
-
cacheName
protected final ByteString cacheName
-
invoker
protected AsyncInterceptorChain invoker
-
icf
protected InvocationContextFactory icf
-
txTable
protected org.infinispan.transaction.impl.TransactionTable txTable
-
-
Constructor Detail
-
AbstractTransactionBoundaryCommand
public AbstractTransactionBoundaryCommand(ByteString cacheName)
-
-
Method Detail
-
init
public void init(AsyncInterceptorChain chain, InvocationContextFactory icf, org.infinispan.transaction.impl.TransactionTable txTable)
-
getTopologyId
public int getTopologyId()
- Specified by:
getTopologyId
in interfaceTopologyAffectedCommand
-
setTopologyId
public void setTopologyId(int topologyId)
- Specified by:
setTopologyId
in interfaceTopologyAffectedCommand
-
getCacheName
public ByteString getCacheName()
- Specified by:
getCacheName
in interfaceCacheRpcCommand
- Returns:
- the name of the cache that produced this command. This will also be the name of the cache this command is intended for.
-
getGlobalTransaction
public GlobalTransaction getGlobalTransaction()
- Specified by:
getGlobalTransaction
in interfaceTransactionBoundaryCommand
-
markTransactionAsRemote
public void markTransactionAsRemote(boolean isRemote)
- Specified by:
markTransactionAsRemote
in interfaceTransactionBoundaryCommand
-
invalidRemoteTxReturnValue
protected Object invalidRemoteTxReturnValue()
This is what is returned to remote callers when an invalid RemoteTransaction is encountered. Can happen if a remote node propagates a transactional call to the current node, and the current node has no idea of the transaction in question. Can happen during rehashing, when ownerships are reassigned during a transactions. Returning a null usually means the transactional command succeeded.- Returns:
- return value to respond to a remote caller with if the transaction context is invalid.
-
perform
public Object perform(InvocationContext ctx) throws Throwable
Description copied from interface:VisitableCommand
Performs the primary function of the command. Please see specific implementation classes for details on what is performed as well as return types. Important: this method will be invoked at the end of interceptors chain. It should never be called directly from a custom interceptor.- Specified by:
perform
in interfaceReplicableCommand
- Specified by:
perform
in interfaceVisitableCommand
- Parameters:
ctx
- invocation context- Returns:
- arbitrary return value generated by performing this command
- Throws:
Throwable
- in the event of problems.
-
invokeAsync
public CompletableFuture<Object> invokeAsync() throws Throwable
Description copied from interface:ReplicableCommand
Invoke the command asynchronously.This method replaces
ReplicableCommand.perform(InvocationContext)
for remote execution. The default implementation andReplicableCommand.perform(InvocationContext)
will be removed in future versions.- Specified by:
invokeAsync
in interfaceReplicableCommand
- Throws:
Throwable
-
visitRemoteTransaction
protected void visitRemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction tx)
-
writeTo
public void writeTo(ObjectOutput output) throws IOException
Description copied from interface:ReplicableCommand
Writes this instance to theObjectOutput
.- Specified by:
writeTo
in interfaceReplicableCommand
- 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
- 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.
-
loadType
public VisitableCommand.LoadType loadType()
- Specified by:
loadType
in interfaceVisitableCommand
- Returns:
- Nodes on which the command needs to read the previous values of the keys it acts on.
-
getOrigin
public Address getOrigin()
Description copied from interface:CacheRpcCommand
Get the origin of the command- Specified by:
getOrigin
in interfaceCacheRpcCommand
-
setOrigin
public void setOrigin(Address origin)
Description copied from interface:ReplicableCommand
Sets the sender'sAddress
.By default, it doesn't set anything. Implement this method if the sender's
Address
is needed.- Specified by:
setOrigin
in interfaceCacheRpcCommand
- Specified by:
setOrigin
in interfaceReplicableCommand
- Parameters:
origin
- the sender'sAddress
-
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
- Returns:
- true or false
-
canBlock
public final boolean canBlock()
Description copied from interface:ReplicableCommand
If true, the command is processed asynchronously in a thread provided by an Infinispan thread pool. Otherwise, the command is processed directly in the JGroups thread. This feature allows to avoid keep a JGroups thread busy that can originate discard of messages and retransmissions. So, the commands that can block (waiting for some state, acquiring locks, etc.) should return true.- Specified by:
canBlock
in interfaceReplicableCommand
- Returns:
true
if the command can block/wait,false
otherwise
-
-