Search in sources :

Example 36 with Message

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

the class ProcManTransactionShould method checkEventReceived.

@Override
protected void checkEventReceived(ProcessManager<ProjectId, Project, PatchedProjectBuilder> entity, Event event) {
    final TestProcessManager aggregate = (TestProcessManager) entity;
    final Message actualMessage = unpack(event.getMessage());
    assertTrue(aggregate.getReceivedEvents().contains(actualMessage));
}
Also used : Message(com.google.protobuf.Message)

Example 37 with Message

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

the class MessageFieldValidator method isTimestamp.

private boolean isTimestamp() {
    final ImmutableList<Message> values = getValues();
    final Message value = values.isEmpty() ? null : values.get(0);
    final boolean isTimestamp = value instanceof Timestamp;
    return isTimestamp;
}
Also used : Message(com.google.protobuf.Message) Timestamp(com.google.protobuf.Timestamp)

Example 38 with Message

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

the class ProcessManagerRepository method dispatchCommand.

/**
     * Dispatches the command to a corresponding process manager.
     *
     * <p>If there is no stored process manager with such an ID,
     * a new process manager is created and stored after it handles the passed command.
     *
     * @param envelope a request to dispatch
     * @see CommandHandlingEntity#dispatchCommand(CommandEnvelope)
     */
@Override
public void dispatchCommand(CommandEnvelope envelope) {
    final Message commandMessage = envelope.getMessage();
    final CommandContext context = envelope.getCommandContext();
    final CommandClass commandClass = envelope.getMessageClass();
    checkCommandClass(commandClass);
    final I id = getIdFromCommandMessage.apply(commandMessage, context);
    final P manager = findOrCreate(id);
    final ProcManTransaction<?, ?, ?> tx = beginTransactionFor(manager);
    final List<Event> events = manager.dispatchCommand(envelope);
    store(manager);
    tx.commit();
    postEvents(events);
}
Also used : Message(com.google.protobuf.Message) CommandContext(io.spine.base.CommandContext) Event(io.spine.base.Event) CommandClass(io.spine.type.CommandClass)

Example 39 with Message

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

the class MethodMap method scan.

/**
     * Returns a map of the {@link HandlerMethod} objects to the corresponding message class.
     *
     * @param declaringClass the class that declares methods to scan
     * @param filter         the predicate that defines rules for subscriber scanning
     * @return the map of message subscribers
     * @throws DuplicateHandlerMethodException if there are more than one handler for
     *                                         the same message class are encountered
     */
private static Map<Class<? extends Message>, Method> scan(Class<?> declaringClass, Predicate<Method> filter) {
    final Map<Class<? extends Message>, Method> tempMap = Maps.newHashMap();
    for (Method method : declaringClass.getDeclaredMethods()) {
        if (filter.apply(method)) {
            final Class<? extends Message> messageClass = HandlerMethod.getFirstParamType(method);
            if (tempMap.containsKey(messageClass)) {
                final Method alreadyPresent = tempMap.get(messageClass);
                throw new DuplicateHandlerMethodException(declaringClass, messageClass, alreadyPresent.getName(), method.getName());
            }
            tempMap.put(messageClass, method);
        }
    }
    final ImmutableMap<Class<? extends Message>, Method> result = ImmutableMap.copyOf(tempMap);
    return result;
}
Also used : Message(com.google.protobuf.Message) Method(java.lang.reflect.Method)

Example 40 with Message

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

the class CommandHandlerMethod method invokeHandler.

/**
     * Invokes the handler method in the passed object.
     *
     * @return the list of events produced by the handler method
     */
public static List<? extends Message> invokeHandler(Object object, Message command, CommandContext context) {
    checkNotNull(object);
    checkNotNull(command);
    checkNotNull(context);
    final Message commandMessage = ensureCommandMessage(command);
    try {
        final CommandHandlerMethod method = forMessage(object.getClass(), commandMessage);
        final List<? extends Message> eventMessages = method.invoke(object, commandMessage, context);
        return eventMessages;
    } catch (InvocationTargetException e) {
        throw illegalStateWithCauseOf(e);
    }
}
Also used : Message(com.google.protobuf.Message) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Message (com.google.protobuf.Message)266 Test (org.junit.Test)84 Any (com.google.protobuf.Any)30 ByteString (com.google.protobuf.ByteString)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Command (io.spine.core.Command)14 DynamicMessage (com.google.protobuf.DynamicMessage)13 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)10 EntityRecord (io.spine.server.entity.EntityRecord)10 Test (org.junit.jupiter.api.Test)9 HeronTuples (com.twitter.heron.proto.system.HeronTuples)8 Event (io.spine.core.Event)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Method (java.lang.reflect.Method)8 Event (io.spine.base.Event)7 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)7 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)7 Descriptor (com.google.protobuf.Descriptors.Descriptor)6 Builder (com.google.protobuf.Message.Builder)5