Search in sources :

Example 26 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class EventBus method handleDeadMessage.

@Override
public void handleDeadMessage(EventEnvelope message, StreamObserver<Response> responseObserver) {
    final Event event = message.getOuterObject();
    log().warn("No subscriber or dispatcher defined for the event class: {}", event.getClass().getName());
}
Also used : Event(io.spine.base.Event)

Example 27 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class EventsShould method createEventAndAssertReturnedMessageFor.

private static void createEventAndAssertReturnedMessageFor(Message msg) {
    final Event event = EventTests.createContextlessEvent(msg);
    assertEquals(msg, getMessage(event));
}
Also used : Event(io.spine.base.Event)

Example 28 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class EventFactory method createEvent.

/**
     * Creates an event for the passed event message.
     *
     * <p>The message passed is validated according to the constraints set in its Protobuf
     * definition. In case the message isn't valid, an {@linkplain ConstraintViolationThrowable
     * exception} is thrown.
     *
     * <p>In the message is an instance of {@code Any}, it is unpacked for validation.
     *
     * <p>It is recommended to use a corresponding {@linkplain io.spine.validate.ValidatingBuilder
     * ValidatingBuilder} implementation to create a message.
     *
     * @param messageOrAny the message of the event or the message packed into {@code Any}
     * @param version      the version of the entity which produces the event
     * @throws ConstraintViolationThrowable if the passed message does not satisfy the constraints
     *                                      set for it in its Protobuf definition
     */
public Event createEvent(Message messageOrAny, @Nullable Version version) throws ConstraintViolationThrowable {
    checkNotNull(messageOrAny);
    // we must validate it now before emitting the next ID.
    validate(messageOrAny);
    final EventId eventId = idSequence.next();
    final EventContext context = createContext(producerId, commandContext, version);
    final Event result = createEvent(eventId, messageOrAny, context);
    return result;
}
Also used : IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) EventContext(io.spine.base.EventContext) EventId(io.spine.base.EventId) IntegrationEvent(io.spine.server.integration.IntegrationEvent) Event(io.spine.base.Event)

Example 29 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class EventFactory method toEvent.

/**
     * Creates an event based on the passed integration event.
     */
public static Event toEvent(IntegrationEvent integrationEvent) {
    final IntegrationEventContext sourceContext = integrationEvent.getContext();
    final EventContext context = toEventContext(sourceContext);
    final Event result = createEvent(sourceContext.getEventId(), integrationEvent.getMessage(), context);
    return result;
}
Also used : IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) EventContext(io.spine.base.EventContext) IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) IntegrationEvent(io.spine.server.integration.IntegrationEvent) Event(io.spine.base.Event)

Example 30 with Event

use of io.spine.base.Event in project core-java by SpineEventEngine.

the class EventFactory method createEvent.

/**
     * Creates a new {@code Event} instance.
     *
     * @param id           the ID of the event
     * @param messageOrAny the event message or {@code Any} containing the message
     * @param context      the event context
     * @return created event instance
     */
private static Event createEvent(EventId id, Message messageOrAny, EventContext context) {
    checkNotNull(messageOrAny);
    checkNotNull(context);
    final Any packed = toAny(messageOrAny);
    final Event result = Event.newBuilder().setId(id).setMessage(packed).setContext(context).build();
    return result;
}
Also used : IntegrationEvent(io.spine.server.integration.IntegrationEvent) Event(io.spine.base.Event) Any(com.google.protobuf.Any) Messages.toAny(io.spine.protobuf.Messages.toAny)

Aggregations

Event (io.spine.base.Event)32 Test (org.junit.Test)14 Message (com.google.protobuf.Message)7 EventContext (io.spine.base.EventContext)4 IntegrationEvent (io.spine.server.integration.IntegrationEvent)4 StringValue (com.google.protobuf.StringValue)3 EventFactory (io.spine.server.command.EventFactory)3 TestEventFactory (io.spine.test.TestEventFactory)3 ProjectId (io.spine.test.projection.ProjectId)3 ProjectCreated (io.spine.test.projection.event.ProjectCreated)3 Duration (com.google.protobuf.Duration)2 Command (io.spine.base.Command)2 EventId (io.spine.base.EventId)2 EventStore (io.spine.server.event.EventStore)2 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 Any (com.google.protobuf.Any)1 Timestamp (com.google.protobuf.Timestamp)1 CommandContext (io.spine.base.CommandContext)1 Events.getMessage (io.spine.base.Events.getMessage)1