Skip to content

Commit

Permalink
GH-3497: ReplyProducerCleaner: check only MPs
Browse files Browse the repository at this point in the history
Fixes #3497

The `BaseIntegrationFlowDefinition.REFERENCED_REPLY_PRODUCERS` is filled up
only with the `MessageProducer` instances.
Therefore no reason to calculate a hash code for every single bean passed
to the `ReplyProducerCleaner.requiresDestruction()`

* Check for the `MessageProducer` instance before passing the bean to the
`BaseIntegrationFlowDefinition.REFERENCED_REPLY_PRODUCERS.contains()`
* Check for the `MessageProducer` in the `ReplyProducerCleaner.postProcessBeforeDestruction()`,
too.
It can be called independently of the `requiresDestruction()` and will calculate a hash code
from the bean again for nothing

**Cherry-pick to 5.4.x & 5.3.x**
  • Loading branch information
artembilan authored and garyrussell committed Feb 22, 2021
1 parent 41cf8b3 commit 871c1bc
Showing 1 changed file with 6 additions and 3 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 the original author or authors.
* Copyright 2019-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -3100,12 +3100,15 @@ private ReplyProducerCleaner() {

@Override
public boolean requiresDestruction(Object bean) {
return BaseIntegrationFlowDefinition.REFERENCED_REPLY_PRODUCERS.contains(bean);
return bean instanceof MessageProducer &&
BaseIntegrationFlowDefinition.REFERENCED_REPLY_PRODUCERS.contains(bean);
}

@Override
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
BaseIntegrationFlowDefinition.REFERENCED_REPLY_PRODUCERS.remove(bean);
if (bean instanceof MessageProducer) {
BaseIntegrationFlowDefinition.REFERENCED_REPLY_PRODUCERS.remove(bean);
}
}

}
Expand Down

0 comments on commit 871c1bc

Please sign in to comment.