public class DisruptorUnitOfWork extends Object implements UnitOfWork, EventRegistrationCallback
| Constructor and Description |
|---|
DisruptorUnitOfWork(boolean transactional)
Creates a new Unit of Work for use in the DisruptorCommandBus.
|
| Modifier and Type | Method and Description |
|---|---|
void |
commit()
Commits the UnitOfWork.
|
EventSourcedAggregateRoot |
getAggregate()
Returns the identifier of the aggregate modified in this UnitOfWork.
|
String |
getAggregateType()
Returns the type identifier of the aggregate handled in this unit of work.
|
List<EventMessage> |
getEventsToPublish()
Returns the events that need to be published as part of this Unit of Work.
|
DomainEventStream |
getEventsToStore()
Returns the events that need to be stored as part of this Unit of Work.
|
boolean |
isStarted()
Indicates whether this UnitOfWork is started.
|
boolean |
isTransactional()
Indicates whether this UnitOfWork is bound to a transaction.
|
void |
onAfterCommit()
Invokes this UnitOfWork's on-after-commit cycle.
|
void |
onCleanup()
Invokes this UnitOfWork's on-cleanup cycle.
|
void |
onPrepareCommit()
Invokes this UnitOfWork's on-prepare-commit cycle.
|
void |
onPrepareTransactionCommit(Object transaction)
Invokes this UnitOfWork's on-prepare-transaction-commit cycle.
|
<T> DomainEventMessage<T> |
onRegisteredEvent(DomainEventMessage<T> event)
Invoked when an Aggregate registers an Event for publication.
|
void |
onRollback(Throwable cause)
Invokes this UnitOfWork's on-rollback cycle.
|
void |
publishEvent(EventMessage event,
EventBus eventBus)
Request to publish the given
event on the given eventBus. |
<T extends AggregateRoot> |
registerAggregate(T aggregateRoot,
EventBus eventBus,
SaveAggregateCallback<T> saveAggregateCallback)
Register an aggregate with this UnitOfWork.
|
void |
registerListener(UnitOfWorkListener listener)
Register a listener that listens to state changes in this UnitOfWork.
|
void |
rollback()
Clear the UnitOfWork of any buffered changes.
|
void |
rollback(Throwable cause)
Clear the UnitOfWork of any buffered changes.
|
void |
setAggregateType(String aggregateType)
Sets the type identifier of the aggregate handled in this unit of work
|
void |
start()
Starts the current unit of work, preparing it for aggregate registration.
|
public DisruptorUnitOfWork(boolean transactional)
transactional - Whether this Unit of Work is bound to a transactionpublic void commit()
UnitOfWorkcommit in interface UnitOfWorkpublic void onPrepareCommit()
public void onPrepareTransactionCommit(Object transaction)
transaction - The object representing the transaction to about to be committedpublic void onAfterCommit()
public void onCleanup()
public void onRollback(Throwable cause)
cause - The cause of the rollbackpublic void rollback()
UnitOfWorkUnitOfWorkListeners are notified.
If the rollback is a result of an exception, consider using UnitOfWork.rollback(Throwable) instead.rollback in interface UnitOfWorkpublic void rollback(Throwable cause)
UnitOfWorkUnitOfWorkListeners are notified.rollback in interface UnitOfWorkcause - The cause of the rollback. May be null.public void start()
UnitOfWorkstart in interface UnitOfWorkpublic boolean isStarted()
UnitOfWorkUnitOfWork.start() method has been called,
and
if the UnitOfWork has not been committed or rolled back.isStarted in interface UnitOfWorktrue if this UnitOfWork is started, false otherwise.public boolean isTransactional()
UnitOfWorkisTransactional in interface UnitOfWorktrue if this unit of work is bound to a transaction, otherwise falsepublic void registerListener(UnitOfWorkListener listener)
UnitOfWorkregisterListener in interface UnitOfWorklistener - The listener to notify when the UnitOfWork's state changes.public <T extends AggregateRoot> T registerAggregate(T aggregateRoot, EventBus eventBus, SaveAggregateCallback<T> saveAggregateCallback)
UnitOfWorksaveAggregateCallback is ignored.registerAggregate in interface UnitOfWorkT - the type of aggregate to registeraggregateRoot - The aggregate root to register in the UnitOfWorkeventBus - The event bus on which Events generated by this aggregate must be publishedsaveAggregateCallback - The callback that is invoked when the UnitOfWork wants to store the registered
aggregatepublic void publishEvent(EventMessage event, EventBus eventBus)
UnitOfWorkevent on the given eventBus. The UnitOfWork may either
publish immediately, or buffer the events until the UnitOfWork is committed.publishEvent in interface UnitOfWorkevent - The event to be published on the event buseventBus - The event bus on which to publish the eventpublic DomainEventStream getEventsToStore()
public List<EventMessage> getEventsToPublish()
public EventSourcedAggregateRoot getAggregate()
public <T> DomainEventMessage<T> onRegisteredEvent(DomainEventMessage<T> event)
EventRegistrationCallbackevent.onRegisteredEvent in interface EventRegistrationCallbackT - The type of payloadevent - The event registered for publicationnull.public String getAggregateType()
public void setAggregateType(String aggregateType)
aggregateType - the type identifier of the aggregate handled in this unit of workCopyright © 2010-2013. All Rights Reserved.