Search in sources :

Example 1 with RejectionReactorMethod

use of io.spine.server.rejection.RejectionReactorMethod in project core-java by SpineEventEngine.

the class Aggregate method reactOn.

/**
 * Dispatches the rejection to which the aggregate reacts.
 *
 * <p>Reacting on a rejection may result in emitting event messages. All the
 * {@linkplain Empty empty} messages are filtered out from the result.
 *
 * @param  rejection the envelope with the rejection
 * @return a list of event messages that the aggregate produces in reaction to
 *         the rejection, or an empty list if the aggregate state does not change in
 *         response to this rejection
 */
List<? extends Message> reactOn(RejectionEnvelope rejection) {
    final CommandClass commandClass = CommandClass.of(rejection.getCommandMessage());
    final RejectionReactorMethod method = thisClass().getReactor(rejection.getMessageClass(), commandClass);
    final List<? extends Message> messages = method.invoke(this, rejection.getMessage(), rejection.getRejectionContext());
    return from(messages).filter(nonEmpty()).toList();
}
Also used : RejectionReactorMethod(io.spine.server.rejection.RejectionReactorMethod) CommandClass(io.spine.core.CommandClass)

Example 2 with RejectionReactorMethod

use of io.spine.server.rejection.RejectionReactorMethod in project core-java by SpineEventEngine.

the class ProcessManager method dispatchRejection.

/**
 * Dispatches a rejection to the reacting method of the process manager.
 *
 * @param  rejection the envelope with the rejection
 * @return a list of produced events or an empty list if the process manager does not
 *         produce new events because of the passed event
 */
List<Event> dispatchRejection(RejectionEnvelope rejection) {
    final CommandClass commandClass = CommandClass.of(rejection.getCommandMessage());
    final RejectionReactorMethod method = thisClass().getReactor(rejection.getMessageClass(), commandClass);
    final List<? extends Message> eventMessages = method.invoke(this, rejection.getMessage(), rejection.getRejectionContext());
    final List<Event> events = toEvents(eventMessages, rejection);
    return events;
}
Also used : RejectionReactorMethod(io.spine.server.rejection.RejectionReactorMethod) Event(io.spine.core.Event) CommandClass(io.spine.core.CommandClass)

Aggregations

CommandClass (io.spine.core.CommandClass)2 RejectionReactorMethod (io.spine.server.rejection.RejectionReactorMethod)2 Event (io.spine.core.Event)1