org.axonframework.eventsourcing
Class AbstractEventSourcedEntity

java.lang.Object
  extended by org.axonframework.eventsourcing.AbstractEventSourcedEntity
All Implemented Interfaces:
EventSourcedEntity
Direct Known Subclasses:
AbstractAnnotatedEntity

public abstract class AbstractEventSourcedEntity
extends Object
implements EventSourcedEntity

Base class for Event Sourced entities that are not at the root of the aggregate. Instead of keeping track of uncommitted events themselves, these entities refer to their aggregate root to do that for them. A DomainEvent published in any of the entities in an Aggregate is published to all entities in the entire aggregate.

Since:
0.7
Author:
Allard Buijze

Constructor Summary
AbstractEventSourcedEntity()
           
 
Method Summary
protected  void apply(Object event)
          Apply the provided event.
protected  void apply(Object event, MetaData metaData)
          Apply the provided event and attaching the given metaData.
protected  AbstractEventSourcedAggregateRoot getAggregateRoot()
          Returns the reference to the root of the aggregate this entity is a member of.
protected abstract  Collection<? extends EventSourcedEntity> getChildEntities()
          Returns a collection of event sourced entities directly referenced by this entity.
protected abstract  void handle(DomainEventMessage event)
          Apply state changes based on the given event.
 void handleRecursively(DomainEventMessage event)
          Report the given event for handling in the current instance (this), as well as all the entities referenced by this instance.
 void registerAggregateRoot(AbstractEventSourcedAggregateRoot aggregateRootToRegister)
          Register the aggregate root with this entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractEventSourcedEntity

public AbstractEventSourcedEntity()
Method Detail

registerAggregateRoot

public void registerAggregateRoot(AbstractEventSourcedAggregateRoot aggregateRootToRegister)
Description copied from interface: EventSourcedEntity
Register the aggregate root with this entity. The entity must use this aggregate root to apply Domain Events. The aggregate root is responsible for tracking all applied events.

A parent entity is responsible for invoking this method on its child entities prior to propagating events to it. Typically, this means all entities have their aggregate root set before any actions are taken on it.

Specified by:
registerAggregateRoot in interface EventSourcedEntity
Parameters:
aggregateRootToRegister - the root of the aggregate this entity is part of.

handleRecursively

public void handleRecursively(DomainEventMessage event)
Description copied from interface: EventSourcedEntity
Report the given event for handling in the current instance (this), as well as all the entities referenced by this instance.

Specified by:
handleRecursively in interface EventSourcedEntity
Parameters:
event - The event to handle

getChildEntities

protected abstract Collection<? extends EventSourcedEntity> getChildEntities()
Returns a collection of event sourced entities directly referenced by this entity. May return null or an empty list to indicate no child entities are available. The collection may also contain null values.

Returns:
a list of event sourced entities contained in this aggregate

handle

protected abstract void handle(DomainEventMessage event)
Apply state changes based on the given event.

Note: Implementations of this method should *not* perform validation.

Parameters:
event - The event to handle

apply

protected void apply(Object event)
Apply the provided event. Applying events means they are added to the uncommitted event queue and forwarded to the handle(org.axonframework.domain.DomainEventMessage) event handler method} for processing.

The event is applied on all entities part of this aggregate.

Parameters:
event - The payload of the event to apply

apply

protected void apply(Object event,
                     MetaData metaData)
Apply the provided event and attaching the given metaData. Applying events means they are added to the uncommitted event queue and forwarded to the handle(org.axonframework.domain.DomainEventMessage) event handler method} for processing.

The event is applied on all entities part of this aggregate.

Parameters:
event - The payload of the event to apply
metaData - any meta-data that must be registered with the Event

getAggregateRoot

protected AbstractEventSourcedAggregateRoot getAggregateRoot()
Returns the reference to the root of the aggregate this entity is a member of.

Returns:
the reference to the root of the aggregate this entity is a member of


Copyright © 2010-2016. All Rights Reserved.