/** * Marks this aggregate as deleted, instructing a repository to remove that aggregate at an appropriate time. * <p/> * Note that different repository implementations may react differently to aggregates marked for deletion. * Typically, Event Sourced Repositories will ignore the marking and expect deletion to be provided as part of Event * information. */ public static void markDeleted() { getInstance().doMarkDeleted(); }
/** * Indicates whether this Aggregate instance is 'live'. Events applied to a 'live' Aggregate represent events that * are currently happening, as opposed to events representing historic decisions used to reconstruct the * Aggregate's state. * * @return {@code true} if the aggregate is 'live', {@code false} if the aggregate is initializing state based on * historic events */ public static boolean isLive() { return AggregateLifecycle.getInstance().getIsLive(); }
/** * Gets the version of the aggregate. * * @return the current version of the aggregate */ public static Long getVersion() { return getInstance().version(); }
/** * Apply a {@link org.axonframework.eventhandling.DomainEventMessage} with given payload and metadata (metadata * from interceptors will be combined with the provided metadata). Applying events means they are immediately * applied (published) to the aggregate and scheduled for publication to other event handlers. * <p/> * The event is applied on all entities part of this aggregate. If the event is applied from an event handler of the * aggregate and additional events need to be applied that depends on state changes brought about by the first event * use the returned {@link ApplyMore} instance. * * @param payload the payload of the event to apply * @param metaData any meta-data that must be registered with the Event * @return a gizmo to apply additional events after the given event has been processed by the entire aggregate * @see ApplyMore */ public static ApplyMore apply(Object payload, MetaData metaData) { return AggregateLifecycle.getInstance().doApply(payload, metaData); }
/** * Creates a new aggregate instance. In order for new aggregate to be created, a {@link Repository} should be * available to the current aggregate. {@link Repository} of an aggregate to be created is exposed to the current * aggregate via {@link RepositoryProvider}. * * @param <T> type of new aggregate to be created * @param aggregateType type of new aggregate to be created * @param factoryMethod factory method which creates new aggregate * @return a new aggregate instance * @throws Exception thrown if something goes wrong during instantiation of new aggregate */ public static <T> Aggregate<T> createNew(Class<T> aggregateType, Callable<T> factoryMethod) throws Exception { if (!isLive()) { throw new UnsupportedOperationException( "Aggregate is still initializing its state, creation of new aggregates is not possible"); } return getInstance().doCreateNew(aggregateType, factoryMethod); }
/** * Apply a {@link org.axonframework.eventhandling.DomainEventMessage} with given payload without metadata (though * interceptors can also be used to provide metadata). Applying events means they are immediately applied * (published) to the aggregate and scheduled for publication to other event handlers. * <p/> * The event is applied on all entities part of this aggregate. If the event is applied from an event handler of the * aggregate and additional events need to be applied that depends on state changes brought about by the first event * use the returned {@link ApplyMore} instance. * * @param payload the payload of the event to apply * @return a gizmo to apply additional events after the given event has been processed by the entire aggregate * @see ApplyMore */ public static ApplyMore apply(Object payload) { return AggregateLifecycle.getInstance().doApply(payload, MetaData.emptyInstance()); }
/** * Indicates whether this Aggregate instance is 'live'. Events applied to a 'live' Aggregate represent events that * are currently happening, as opposed to events representing historic decisions used to reconstruct the * Aggregate's state. * * @return {@code true} if the aggregate is 'live', {@code false} if the aggregate is initializing state based on * historic events */ public static boolean isLive() { return AggregateLifecycle.getInstance().getIsLive(); }
/** * Gets the version of the aggregate. * * @return the current version of the aggregate */ public static Long getVersion() { return getInstance().version(); }
/** * Marks this aggregate as deleted, instructing a repository to remove that aggregate at an appropriate time. * <p/> * Note that different repository implementations may react differently to aggregates marked for deletion. * Typically, Event Sourced Repositories will ignore the marking and expect deletion to be provided as part of Event * information. */ public static void markDeleted() { getInstance().doMarkDeleted(); }
/** * Apply a {@link org.axonframework.eventhandling.DomainEventMessage} with given payload and metadata (metadata * from interceptors will be combined with the provided metadata). Applying events means they are immediately * applied (published) to the aggregate and scheduled for publication to other event handlers. * <p/> * The event is applied on all entities part of this aggregate. If the event is applied from an event handler of the * aggregate and additional events need to be applied that depends on state changes brought about by the first event * use the returned {@link ApplyMore} instance. * * @param payload the payload of the event to apply * @param metaData any meta-data that must be registered with the Event * @return a gizmo to apply additional events after the given event has been processed by the entire aggregate * @see ApplyMore */ public static ApplyMore apply(Object payload, MetaData metaData) { return AggregateLifecycle.getInstance().doApply(payload, metaData); }
/** * Creates a new aggregate instance. In order for new aggregate to be created, a {@link Repository} should be * available to the current aggregate. {@link Repository} of an aggregate to be created is exposed to the current * aggregate via {@link RepositoryProvider}. * * @param <T> type of new aggregate to be created * @param aggregateType type of new aggregate to be created * @param factoryMethod factory method which creates new aggregate * @return a new aggregate instance * @throws Exception thrown if something goes wrong during instantiation of new aggregate */ public static <T> Aggregate<T> createNew(Class<T> aggregateType, Callable<T> factoryMethod) throws Exception { if (!isLive()) { throw new UnsupportedOperationException( "Aggregate is still initializing its state, creation of new aggregates is not possible"); } return getInstance().doCreateNew(aggregateType, factoryMethod); }
/** * Apply a {@link org.axonframework.eventhandling.DomainEventMessage} with given payload without metadata (though * interceptors can also be used to provide metadata). Applying events means they are immediately applied * (published) to the aggregate and scheduled for publication to other event handlers. * <p/> * The event is applied on all entities part of this aggregate. If the event is applied from an event handler of the * aggregate and additional events need to be applied that depends on state changes brought about by the first event * use the returned {@link ApplyMore} instance. * * @param payload the payload of the event to apply * @return a gizmo to apply additional events after the given event has been processed by the entire aggregate * @see ApplyMore */ public static ApplyMore apply(Object payload) { return AggregateLifecycle.getInstance().doApply(payload, MetaData.emptyInstance()); }