Skip to content

Conversation

artembilan
Copy link
Member

Fixes #3320

Turns out that lifecycle control for the whole bunch of components
in one IntegrationFlow is useful in fields.

  • Change the logic in the StandardIntegrationFlow to let to call
    start() and stop() independently how the flow was registered in
    the application context.
    This way it can be autowired as a Lifecycle to let end-user to
    avoid the search for proper component in the flow to stop or start
    manually - all the components registered with the flow are going
    to be stopped or started respectively

Fixes spring-projects#3320

Turns out that lifecycle control for the whole bunch of components
in one `IntegrationFlow` is useful in fields.

* Change the logic in the `StandardIntegrationFlow` to let to call
`start()` and `stop()` independently how the flow was registered in
the application context.
This way it can be autowired as a `Lifecycle` to let end-user to
avoid the search for proper component in the flow to stop or start
manually - all the components registered with the flow are going
to be stopped or started respectively
@artembilan artembilan requested a review from garyrussell July 2, 2020 17:28
if (this.lifecycles.size() > 0) {
AggregatingCallback aggregatingCallback = new AggregatingCallback(this.lifecycles.size(), callback);
ListIterator<SmartLifecycle> iterator = this.lifecycles.listIterator(this.lifecycles.size());
while (iterator.hasPrevious()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this, but stopping right to left was wrong; corrected in the new code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, Gary, it was right. Because we started before from right to left and filled out the local lifecycles property.
Then we used this lifecycles in the stop() and therefore the first one in the flow was in the end of that list, so we again should iterate it backwards to stop in proper order.
Right now indeed we don't have an intermediate list therefore the logic is changed around a normal integrationComponents state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... right.

@garyrussell
Copy link
Contributor

[ant:checkstyle] [ERROR] /home/travis/build/spring-projects/spring-integration/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java:128:41: Reference to instance variable 'integrationComponents' needs "this.". [RequireThis]
[ant:checkstyle] [ERROR] /home/travis/build/spring-projects/spring-integration/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java:143:41: Reference to instance variable 'integrationComponents' needs "this.". [RequireThis]

@garyrussell garyrussell merged commit 146b0af into spring-projects:master Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider Honoring Lifecycle.stop() in StandardIntegrationFlow
2 participants