Search in sources :

Example 61 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class EventBusAdapter method toExternalEnvelope.

@Override
ExternalMessageEnvelope toExternalEnvelope(ExternalMessage message) {
    final Message unpacked = AnyPacker.unpack(message.getOriginalMessage());
    final Event event = (Event) unpacked;
    final ExternalMessageEnvelope result = ExternalMessageEnvelope.of(message, Events.getMessage(event));
    return result;
}
Also used : Message(com.google.protobuf.Message) Event(io.spine.core.Event)

Example 62 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class ExternalEventSubscriber method dispatch.

@Override
public Set<String> dispatch(ExternalMessageEnvelope envelope) {
    final ExternalMessage externalMessage = envelope.getOuterObject();
    final Message unpacked = AnyPacker.unpack(externalMessage.getOriginalMessage());
    if (!(unpacked instanceof Event)) {
        throw newIllegalStateException("Unexpected object %s while dispatching " + "the external event to the event subscriber.", Stringifiers.toString(unpacked));
    }
    final Event event = (Event) unpacked;
    checkArgument(isExternal(event.getContext()), "External event expected, but got %s", Stringifiers.toString(event));
    return delegate.dispatch(EventEnvelope.of(event));
}
Also used : Message(com.google.protobuf.Message) Event(io.spine.core.Event)

Example 63 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class Action method createEnrichments.

private void createEnrichments() {
    final Message sourceMessage = envelope.getMessage();
    for (EnrichmentFunction function : availableFunctions) {
        final Message enriched = apply(function, sourceMessage, envelope.getMessageContext());
        checkResult(enriched, function);
        final String typeName = TypeName.of(enriched).value();
        enrichments.put(typeName, AnyPacker.pack(enriched));
    }
}
Also used : Message(com.google.protobuf.Message)

Example 64 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class CommandRouter method routeAll.

/**
 * Posts the added messages as commands to {@code CommandBus}.
 *
 * <p>The commands are posted in the order their messages were added.
 *
 * <p>The method returns after the last command was successfully posted.
 *
 * @return the event with the source and produced commands
 */
public CommandRouted routeAll() {
    final CommandRouted.Builder result = CommandRouted.newBuilder();
    result.setSource(getSource());
    while (hasNext()) {
        final Message message = next();
        final Command command = route(message);
        result.addProduced(command);
    }
    return result.build();
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command)

Example 65 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class IteratingCommandRouter method routeFirst.

/**
 * Routes the first of the messages and returns the message
 * to be associated with the source command.
 *
 * <p>The rest of the messages are stored and those to follow.
 *
 * @return {@code CommandRouted} message with
 * <ul>
 *     <li>the source command,
 *     <li>the first produced command,
 *     <li>the command messages for the commands that will be posted by the router later
 * </ul>
 * @see CommandRouted#getMessageToFollowList()
 */
protected CommandRouted routeFirst() {
    final CommandRouted.Builder result = CommandRouted.newBuilder();
    result.setSource(getSource());
    final Message message = next();
    final Command command = route(message);
    result.addProduced(command);
    final Iterable<Any> iterable = new Iterable<Any>() {

        @Override
        public Iterator<Any> iterator() {
            return AnyPacker.pack(commandMessages());
        }
    };
    result.addAllMessageToFollow(iterable);
    return result.build();
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command) Any(com.google.protobuf.Any)

Aggregations

Message (com.google.protobuf.Message)185 Test (org.junit.Test)62 Any (com.google.protobuf.Any)30 Command (io.spine.core.Command)14 EntityRecord (io.spine.server.entity.EntityRecord)10 ByteString (com.google.protobuf.ByteString)9 Event (io.spine.core.Event)8 Event (io.spine.base.Event)7 CommandEnvelope (io.spine.core.CommandEnvelope)7 TypeUrl (io.spine.type.TypeUrl)7 IOException (java.io.IOException)7 Timestamp (com.google.protobuf.Timestamp)5 Error (io.spine.base.Error)5 Rejection (io.spine.core.Rejection)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Method (java.lang.reflect.Method)5 FieldMask (com.google.protobuf.FieldMask)4 GeneratedMessage (com.google.protobuf.GeneratedMessage)4 ThrowableMessage (io.spine.base.ThrowableMessage)4 EntityFilters (io.spine.client.EntityFilters)4