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