Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't log warn when the aggregate is handling a deadline message. #2644

Merged
merged 1 commit into from Mar 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,6 +19,7 @@
import org.axonframework.commandhandling.CommandMessage;
import org.axonframework.common.Assert;
import org.axonframework.common.AxonConfigurationException;
import org.axonframework.deadline.DeadlineMessage;
import org.axonframework.messaging.Message;
import org.axonframework.messaging.ScopeDescriptor;
import org.axonframework.messaging.annotation.ClasspathHandlerDefinition;
Expand All @@ -33,6 +34,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -122,7 +124,6 @@ public A newInstance(@Nonnull Callable<T> factoryMethod,
*
* @param factoryMethod The method to create the aggregate's root instance
* @return an Aggregate instance describing the aggregate's state
*
* @throws Exception when the factoryMethod throws an exception
*/
protected abstract A doCreateNew(Callable<T> factoryMethod) throws Exception;
Expand Down Expand Up @@ -174,13 +175,23 @@ public Aggregate<T> loadOrCreate(@Nonnull String aggregateIdentifier, @Nonnull C
private UnitOfWork<?> currentUnitOfWork() {
UnitOfWork<?> uow = CurrentUnitOfWork.get();
Class<?> messageType = uow.getMessage() != null ? uow.getMessage().getClass() : null;
if (messageType != null && !CommandMessage.class.isAssignableFrom(messageType)) {
logger.warn("The active Unit of Work is expected to contain a CommandMessage, but instead contains a [{}]",
if (invalidMessageType(messageType)) {
logger.warn("The active Unit of Work is expected to contain a CommandMessage or a DeadlineMessage, but instead contains a [{}]",
messageType);
}
return uow;
}

private boolean invalidMessageType(Class<?> messageType) {
if (messageType == null) {
return false;
}
if (CommandMessage.class.isAssignableFrom(messageType)) {
return false;
}
return !DeadlineMessage.class.isAssignableFrom(messageType);
}

/**
* Returns the map of aggregates currently managed by this repository under the given unit of work. Note that the
* repository keeps the managed aggregates in the root unit of work, to guarantee each Unit of Work works with the
Expand Down Expand Up @@ -370,6 +381,7 @@ public void send(@Nonnull Message<?> message, @Nonnull ScopeDescriptor scopeDesc
}
}
}

@Override
public boolean canResolve(@Nonnull ScopeDescriptor scopeDescription) {
return scopeDescription instanceof AggregateScopeDescriptor && aggregateModel.types().anyMatch(
Expand Down