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;
}
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));
}
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));
}
}
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();
}
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();
}
Aggregations