Search in sources :

Example 1 with EventEnvelope

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;
}
Also used : EventEnvelope(io.spine.core.EventEnvelope)

Example 2 with EventEnvelope

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);
    }
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Event(io.spine.core.Event)

Example 3 with 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);
        }
    };
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) ExternalMessageClass(io.spine.server.integration.ExternalMessageClass) EventClass(io.spine.core.EventClass) ExternalMessageEnvelope(io.spine.server.integration.ExternalMessageEnvelope) ExternalMessageDispatcher(io.spine.server.integration.ExternalMessageDispatcher)

Example 4 with EventEnvelope

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));
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Example 5 with EventEnvelope

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());
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Aggregations

EventEnvelope (io.spine.core.EventEnvelope)24 Test (org.junit.Test)19 Event (io.spine.core.Event)9 StringValue (com.google.protobuf.StringValue)3 TestEventFactory (io.spine.server.command.TestEventFactory)3 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)2 FailingSubscriber (io.spine.server.event.given.EventSubscriberTestEnv.FailingSubscriber)2 FloatValue (com.google.protobuf.FloatValue)1 Message (com.google.protobuf.Message)1 Command (io.spine.core.Command)1 EventClass (io.spine.core.EventClass)1 MessageEnvelope (io.spine.core.MessageEnvelope)1 GivenEvent (io.spine.core.given.GivenEvent)1 PostponingEventDelivery (io.spine.server.aggregate.given.AggregateMessageDeliveryTestEnv.PostponingEventDelivery)1 FailingAggregateRepository (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository)1 EventCatcher (io.spine.server.event.given.CommandHandlerTestEnv.EventCatcher)1 GivenEvent (io.spine.server.event.given.EventEnricherTestEnv.GivenEvent)1 ExternalMessageClass (io.spine.server.integration.ExternalMessageClass)1 ExternalMessageDispatcher (io.spine.server.integration.ExternalMessageDispatcher)1 ExternalMessageEnvelope (io.spine.server.integration.ExternalMessageEnvelope)1