|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.axonframework.eventhandling.TransactionStatus
public class TransactionStatus
Provides details about the current status of an event handling transaction. This method is typically accessed through
the beforeTransaction and afterTransaction methods on TransactionManager, but
may also be obtained through the static current() method.
| Constructor Summary | |
|---|---|
protected |
TransactionStatus()
Initialize a TransactionStatus instance with default settings. |
| Method Summary | |
|---|---|
protected static void |
clear()
Clears the TransactionStatus related to the current thread. |
static TransactionStatus |
current()
Returns the TransactionStatus object related to a transaction running on the current thread. |
int |
getEventsProcessedInTransaction()
Returns the number of events processed (so far) in the current transaction. |
int |
getEventsProcessedSinceLastYield()
Returns the number of events processed (so far) since the scheduler last yielded to other threads. |
Throwable |
getException()
Returns the exception that caused the transaction to be marked as failed. |
int |
getMaxTransactionSize()
Returns the maximum number of events that may be processed inside the current transaction. |
long |
getRetryInterval()
Returns the current retry interval. |
RetryPolicy |
getRetryPolicy()
Returns the retry policy for the current transaction |
YieldPolicy |
getYieldPolicy()
Returns the YieldPolicy applicable to the current transaction. |
boolean |
isSuccessful()
Indicates whether the current transactional batch is executed successfully. |
protected boolean |
isTransactionSizeReached()
Indicates whether or not the maximum amount of events have been processed in this transaction. |
protected void |
markFailed(Throwable cause)
Mark the current transaction as failed. |
protected void |
recordEventProcessed()
Record the fact that an event has been processed. |
void |
requestImmediateCommit()
Requests the EventProcessingScheduler to commit the transaction immediately. |
void |
requestImmediateYield()
Forces the EventProcessingScheduler to immediately yield to other schedulers after processing this event. |
protected void |
resetTransactionStatus()
Resets the event count for current transaction to 0 and sets the YieldPolicy to the default value (YIELD_AFTER_TRANSACTION). |
protected static void |
set(TransactionStatus newStatus)
Sets the TransactionStatus object related to the transaction running in the current thread. |
void |
setMaxTransactionSize(int maxTransactionSize)
Sets the maximum number of events to process inside the current transaction. |
void |
setRetryInterval(long retryInterval)
Sets the retry interval for the current transaction. his is the number of milliseconds processing should wait before retrying this transaction. |
void |
setRetryPolicy(RetryPolicy retryPolicy)
Sets the retry policy for the current transaction. |
void |
setYieldPolicy(YieldPolicy yieldPolicy)
Sets the YieldPolicy for the current transaction. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected TransactionStatus()
| Method Detail |
|---|
public static TransactionStatus current()
null if no transaction is running on the current thread.
null if none is present.protected static void clear()
protected static void set(TransactionStatus newStatus)
newStatus - The TransactionStatus for the current transactionpublic int getEventsProcessedInTransaction()
public int getEventsProcessedSinceLastYield()
public void setYieldPolicy(YieldPolicy yieldPolicy)
YIELD_AFTER_TRANSACTION.
yieldPolicy - The YieldPolicy to use for the current transactionpublic YieldPolicy getYieldPolicy()
public void requestImmediateYield()
public void requestImmediateCommit()
public int getMaxTransactionSize()
public void setMaxTransactionSize(int maxTransactionSize)
maxTransactionSize - The number of events to process in the current transactionpublic void setRetryPolicy(RetryPolicy retryPolicy)
SKIP_FAILED_EVENT by default.
Typically, exceptions are caused by programming errors or the underlying processing environment that the event
handler uses, such as a database. In the former, there is no point in retrying the event processing. It would
cause an unlimited loop in event processing, making an application vulnerable to a poisonous message attack. In
the latter case, the event listener should identify which exception is transitive (i.e. might make a chance when
retried), and which is not. If an exception is transitive, either RETRY_TRANSACTION or RETRY_LAST_EVENT should be chosen.
Furthermore, the policy choice should be based on the effect of a transaction rollback. Some data sources, such
as databases, roll back the entire transaction. In that case, choose RETRY_TRANSACTION policy. If a rollback on the underlying data source only rolls back the last modification,
choose RETRY_LAST_EVENT.
If failed events should be ignored altogether, choose the SKIP_FAILED_EVENT
policy.
These policies may be set in both the beforeTransaction() and afterTransaction methods.
The latter would allow you to change policy based on the exact type of exception encountered.
retryPolicy - the retry policy to apply when a transaction fails.public RetryPolicy getRetryPolicy()
setRetryPolicy(RetryPolicy)protected void recordEventProcessed()
protected void resetTransactionStatus()
protected boolean isTransactionSizeReached()
public long getRetryInterval()
public void setRetryInterval(long retryInterval)
retryInterval - the number of milliseconds to wait before retrying the transactionpublic boolean isSuccessful()
public Throwable getException()
isSuccessful() to find out if transaction was successful or not.
protected void markFailed(Throwable cause)
cause - the exception that caused the transaction to fail
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||