Skip to content

Commit

Permalink
Merge pull request #2644 from AxonFramework/prevent_log_warn_on_deadline
Browse files Browse the repository at this point in the history
Don't log warn when the aggregate is handling a deadline message.
  • Loading branch information
gklijs committed Mar 15, 2023
2 parents 6bf8c78 + c06c77d commit 243811b
Showing 1 changed file with 15 additions and 3 deletions.
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

0 comments on commit 243811b

Please sign in to comment.