Interface MessageStreamResolver

All Superinterfaces:
Function<Object,MessageStream<?>>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface MessageStreamResolver extends Function<Object,MessageStream<?>>
Resolves the value returned by a message handler into the MessageStream that carries it to the dispatcher.

The messageType the handler is subscribed for is given alongside the result, as it determines how many Messages the handler may produce. Handlers of CommandMessages produce exactly one result, so a returned collection is carried as the payload of a single Message. Handlers of other message types may produce several results, so a returned collection is spread over one Message per element.

This interface refines the Function that HandlerDefinition.createHandler(Class, java.lang.reflect.Method, ParameterResolverFactory, Function) has accepted since 5.0.0, so that it can be passed wherever that Function is expected. A HandlerDefinition that forwards the Function it receives keeps the message type intact; one that replaces it with a Function of its own falls back to apply(Object), which cannot know the message type and therefore resolves as if the handler may produce several results.

Since:
5.3.1
Author:
Mitchell Herrijgers
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default MessageStream<?>
    apply(@Nullable Object result)
    Resolves the given result without knowing which type of Message the handler is subscribed for, and thus how many Messages it may produce.
    resolve(@Nullable Object result, Class<? extends Message> messageType)
    Resolves the given result of a handler subscribed for the given messageType into a MessageStream.

    Methods inherited from interface java.util.function.Function

    andThen, compose