|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.commandhandling.disruptor.DisruptorUnitOfWork
public class DisruptorUnitOfWork
Specialized UnitOfWork instance for the DisruptorCommandBus. It expects the executing command to target a single aggregate instance.
Constructor Summary | |
---|---|
DisruptorUnitOfWork(boolean transactional)
Creates a new Unit of Work for use in the DisruptorCommandBus. |
Method Summary | ||
---|---|---|
void |
attachInheritedResources(UnitOfWork inheritingUnitOfWork)
Attach all inherited resources to the given unitOfWork . |
|
void |
attachResource(String name,
Object resource)
Attaches the given resource to this Unit of Work under the given name . |
|
void |
attachResource(String name,
Object resource,
boolean inherited)
Attaches the given resource to this Unit of Work under the given name . |
|
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. |
|
|
getResource(String name)
Returns the resource previously attached under given name , or null if no such resource
is available. |
|
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. |
|
|
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 . |
|
|
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 |
setEventStreamDecorator(EventStreamDecorator eventStreamDecorator)
Registers the EventStreamDecorator for events as part of this unit of work |
|
void |
start()
Starts the current unit of work, preparing it for aggregate registration. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DisruptorUnitOfWork(boolean transactional)
transactional
- Whether this Unit of Work is bound to a transactionMethod Detail |
---|
public void commit()
UnitOfWork
commit
in interface UnitOfWork
public 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()
UnitOfWork
UnitOfWorkListener
s are notified.
If the rollback is a result of an exception, consider using UnitOfWork.rollback(Throwable)
instead.
rollback
in interface UnitOfWork
public void rollback(Throwable cause)
UnitOfWork
UnitOfWorkListener
s are notified.
rollback
in interface UnitOfWork
cause
- The cause of the rollback. May be null
.public void start()
UnitOfWork
start
in interface UnitOfWork
public boolean isStarted()
UnitOfWork
UnitOfWork.start()
method has been called,
and
if the UnitOfWork has not been committed or rolled back.
isStarted
in interface UnitOfWork
true
if this UnitOfWork is started, false
otherwise.public boolean isTransactional()
UnitOfWork
isTransactional
in interface UnitOfWork
true
if this unit of work is bound to a transaction, otherwise false
public void registerListener(UnitOfWorkListener listener)
UnitOfWork
registerListener
in interface UnitOfWork
listener
- The listener to notify when the UnitOfWork's state changes.public <T extends AggregateRoot> T registerAggregate(T aggregateRoot, EventBus eventBus, SaveAggregateCallback<T> saveAggregateCallback)
UnitOfWork
saveAggregateCallback
is ignored.
registerAggregate
in interface UnitOfWork
T
- 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
aggregate
public void attachResource(String name, Object resource)
UnitOfWork
resource
to this Unit of Work under the given name
. The attached
resource is not inherited by any nested Unit of Work (see UnitOfWork.attachResource(String, Object, boolean)
.
If a resource was already attached under this name, it is overwritten.
By convention, resources should be attached using the fully Qualified name of their type (or main interface).
For example, a JDBC Connection should be attached using the name "java.sql.Connection". When there is a
requirement to distinguish between different resources of the same type, their name may differ from this
convention.
attachResource
in interface UnitOfWork
name
- The name under which to attach the resourceresource
- The resource to attachpublic void attachResource(String name, Object resource, boolean inherited)
UnitOfWork
resource
to this Unit of Work under the given name
. The attached
resource is inherited
as indicated. Inherited resources are automatically attached to a nested
Unit of Work.
If a resource was already attached under this name, it is overwritten.
By convention, resources should be attached using the fully Qualified name of their type (or main interface).
For example, a JDBC Connection should be attached using the name "java.sql.Connection". When there is a
requirement to distinguish between different resources of the same type, their name may differ from this
convention.
attachResource
in interface UnitOfWork
name
- The name under which to attach the resourceresource
- The resource to attachinherited
- Whether or not the resource may be inherited by a nested Unit of Workpublic <T> T getResource(String name)
UnitOfWork
name
, or null
if no such resource
is available.
getResource
in interface UnitOfWork
T
- The type of resourcename
- The name under which the resource was attached
name
, or null
if no such resource is
available.public void attachInheritedResources(UnitOfWork inheritingUnitOfWork)
UnitOfWork
unitOfWork
.
attachInheritedResources
in interface UnitOfWork
inheritingUnitOfWork
- the Unit of Work inheriting the resources from this instance.public void publishEvent(EventMessage event, EventBus eventBus)
UnitOfWork
event
on the given eventBus
. The UnitOfWork may either
publish immediately, or buffer the events until the UnitOfWork is committed.
publishEvent
in interface UnitOfWork
event
- 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)
EventRegistrationCallback
event
.
onRegisteredEvent
in interface EventRegistrationCallback
T
- The type of payloadevent
- The event registered for publication
null
.public String getAggregateType()
public void setAggregateType(String aggregateType)
aggregateType
- the type identifier of the aggregate handled in this unit of workpublic void setEventStreamDecorator(EventStreamDecorator eventStreamDecorator)
eventStreamDecorator
- The EventStreamDecorator to use for the event streams part of this unit of work
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |