Interface TransactionOutbox
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
static class
Builder forTransactionOutbox
. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
default boolean
flush()
Flush in a single thread.boolean
Identifies any stale tasks queued usingschedule(Class)
(those which were queued more than suppliedTransactionOutbox.TransactionOutboxBuilder.attemptFrequency(Duration)
ago and have been tried less thanTransactionOutbox.TransactionOutboxBuilder.blockAfterAttempts(int)
)} times) and attempts to resubmit them.void
Performs initial setup, making the instance usable.void
processNow
(TransactionOutboxEntry entry) Processes an entry immediately in the current thread.<T> T
The main entry point for submitting new transaction outbox tasks.boolean
Unblocks a blocked entry and resets the attempt count so that it will be retried again.boolean
Clears a failed entry of its failed state and resets the attempt count so that it will be retried again.with()
Starts building a schedule request with parameterization.
-
Method Details
-
builder
- Returns:
- A builder for creating a new instance of
TransactionOutbox
.
-
initialize
void initialize()Performs initial setup, making the instance usable. IfTransactionOutbox.TransactionOutboxBuilder.initializeImmediately(boolean)
is true, which is the default, this method is called automatically when the instance is constructed. -
schedule
The main entry point for submitting new transaction outbox tasks.Returns a proxy of
T
which, when called, will instantly return and schedule a call of the real method to occur after the current transaction is committed (as such a transaction needs to be active and accessible from the transaction manager supplied toTransactionOutbox.TransactionOutboxBuilder.transactionManager(TransactionManager)
),Usage:
transactionOutbox.schedule(MyService.class) .runMyMethod("with", "some", "arguments");
This will write a record to the database using the supplied
Persistor
andInstantiator
, using the current database transaction, which will get rolled back if the rest of the transaction is, and thus never processed. However, if the transaction is committed, the real method will be called immediately afterwards using the submitter supplied toTransactionOutbox.TransactionOutboxBuilder.submitter(Submitter)
. Should that fail, the call will be reattempted wheneverflush()
is called, provided at least suppliedTransactionOutbox.TransactionOutboxBuilder.attemptFrequency(Duration)
has passed since the time the task was last attempted.- Type Parameters:
T
- The type to proxy.- Parameters:
clazz
- The class to proxy.- Returns:
- The proxy of
T
.
-
with
Starts building a schedule request with parameterization. SeeTransactionOutbox.ParameterizedScheduleBuilder.schedule(Class)
for more information.- Returns:
- Builder.
-
flush
default boolean flush()Flush in a single thread. Callsflush(Executor)
with anExecutor
which runs all work in the current thread.- Returns:
- true if any work was flushed.
- See Also:
-
flush
Identifies any stale tasks queued usingschedule(Class)
(those which were queued more than suppliedTransactionOutbox.TransactionOutboxBuilder.attemptFrequency(Duration)
ago and have been tried less thanTransactionOutbox.TransactionOutboxBuilder.blockAfterAttempts(int)
)} times) and attempts to resubmit them.As long as the
TransactionOutbox.TransactionOutboxBuilder.submitter(Submitter)
is non-blocking (e.g. uses a bounded queue with aRejectedExecutionHandler
which throws such asThreadPoolExecutor.AbortPolicy
), this method will return quickly. However, if theTransactionOutbox.TransactionOutboxBuilder.submitter(Submitter)
uses a bounded queue with a blocking policy, this method could block for a long time, depending on how long the scheduled work takes and how largeTransactionOutbox.TransactionOutboxBuilder.flushBatchSize(int)
is.Calls
TransactionManager.inTransactionReturns(TransactionalSupplier)
to start a new transaction for the fetch.Additionally, expires any records completed prior to the
TransactionOutbox.TransactionOutboxBuilder.retentionThreshold(Duration)
.- Parameters:
executor
- to be used for parallelising work (note that the method overall is blocking and this is solely ued for fork-join semantics).- Returns:
- true if any work was flushed.
-
unblock
Unblocks a blocked entry and resets the attempt count so that it will be retried again. Requires an active transaction and a transaction manager that supports thread local context.- Parameters:
entryId
- The entry id.- Returns:
- True if the request to unblock the entry was successful. May return false if another thread unblocked the entry first.
-
unblock
Clears a failed entry of its failed state and resets the attempt count so that it will be retried again. Requires an active transaction and a transaction manager that supports supplied context.- Parameters:
entryId
- The entry id.transactionContext
- The transaction context (TransactionManager
implementation specific).- Returns:
- True if the request to unblock the entry was successful. May return false if another thread unblocked the entry first.
-
processNow
Processes an entry immediately in the current thread. Intended for use in custom implementations ofSubmitter
and should not generally otherwise be called.- Parameters:
entry
- The entry.
-