use of io.spine.core.EventEnvelope in project core-java by SpineEventEngine.
the class AggregateEventEndpoint method getTargets.
/**
* Obtains IDs of aggregates that react on the event processed by this endpoint.
*/
@Override
protected Set<I> getTargets() {
final EventEnvelope envelope = envelope();
final Set<I> ids = repository().getEventRouting().apply(envelope.getMessage(), envelope.getEventContext());
return ids;
}
use of io.spine.core.EventEnvelope in project core-java by SpineEventEngine.
the class EventPlayingEntity method play.
/**
* Plays the given events upon this entity.
*
* <p>Please note that the entity version is set according to the version of the event context.
* Therefore, if the passed event(s) are in fact so called "integration" events and originated
* from another application, they should be properly imported first.
* Otherwise, the version conflict is possible.
*
* <p>Execution of this method requires the {@linkplain #isTransactionInProgress()
* presence of active transaction}.
*
* @param events the events to play
*/
protected void play(Iterable<Event> events) {
final Transaction<I, ? extends EventPlayingEntity<I, S, B>, S, B> tx = tx();
for (Event event : events) {
final EventEnvelope eventEnvelope = EventEnvelope.of(event);
tx.apply(eventEnvelope);
}
}
use of io.spine.core.EventEnvelope in project core-java by SpineEventEngine.
the class DelegatingEventDispatcher method getExternalDispatcher.
/**
* Wraps this dispatcher to an external event dispatcher.
*
* @return the external rejection dispatcher proxying calls to the underlying instance
*/
public ExternalMessageDispatcher<I> getExternalDispatcher() {
return new ExternalMessageDispatcher<I>() {
@Override
public Set<ExternalMessageClass> getMessageClasses() {
final Set<EventClass> eventClasses = delegate.getExternalEventClasses();
return ExternalMessageClass.fromEventClasses(eventClasses);
}
@Override
public Set<I> dispatch(ExternalMessageEnvelope envelope) {
final EventEnvelope eventEnvelope = asEventEnvelope(envelope);
final Set<I> ids = delegate.dispatchEvent(eventEnvelope);
return ids;
}
@Override
public void onError(ExternalMessageEnvelope envelope, RuntimeException exception) {
final EventEnvelope eventEnvelope = asEventEnvelope(envelope);
delegate.onError(eventEnvelope, exception);
}
};
}
use of io.spine.core.EventEnvelope in project core-java by SpineEventEngine.
the class EventBusShould method deliver_postponed_event_to_dispatcher_using_configured_executor.
@Test
public void deliver_postponed_event_to_dispatcher_using_configured_executor() {
final BareDispatcher dispatcher = new BareDispatcher();
eventBusWithPosponedExecution.register(dispatcher);
final Event event = GivenEvent.projectCreated();
eventBusWithPosponedExecution.post(event);
final Set<EventEnvelope> postponedEvents = postponedDispatcherDelivery.getPostponedEvents();
final EventEnvelope postponedEvent = postponedEvents.iterator().next();
verify(delegateDispatcherExecutor, never()).execute(any(Runnable.class));
postponedDispatcherDelivery.deliverNow(postponedEvent, Consumers.idOf(dispatcher));
assertTrue(dispatcher.isDispatchCalled());
verify(delegateDispatcherExecutor).execute(any(Runnable.class));
}
use of io.spine.core.EventEnvelope in project core-java by SpineEventEngine.
the class EventBusShould method pick_proper_consumer_by_consumer_id_when_delivering_to_delegates_of_same_event.
@Test
public void pick_proper_consumer_by_consumer_id_when_delivering_to_delegates_of_same_event() {
final FirstProjectCreatedDelegate first = new FirstProjectCreatedDelegate();
final AnotherProjectCreatedDelegate second = new AnotherProjectCreatedDelegate();
final DelegatingEventDispatcher<String> firstDispatcher = DelegatingEventDispatcher.of(first);
final DelegatingEventDispatcher<String> secondDispatcher = DelegatingEventDispatcher.of(second);
eventBusWithPosponedExecution.register(firstDispatcher);
eventBusWithPosponedExecution.register(secondDispatcher);
final Event event = GivenEvent.projectCreated();
eventBusWithPosponedExecution.post(event);
final Set<EventEnvelope> postponedEvents = postponedDispatcherDelivery.getPostponedEvents();
final EventEnvelope postponedEvent = postponedEvents.iterator().next();
verify(delegateDispatcherExecutor, never()).execute(any(Runnable.class));
postponedDispatcherDelivery.deliverNow(postponedEvent, Consumers.idOf(firstDispatcher));
assertTrue(first.isDispatchCalled());
verify(delegateDispatcherExecutor).execute(any(Runnable.class));
assertFalse(second.isDispatchCalled());
}
Aggregations