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

Support multiple TaskDecorators in TaskExecutionAutoConfiguration #23686

Closed
ttddyy opened this issue Sep 24, 2019 · 5 comments
Closed

Support multiple TaskDecorators in TaskExecutionAutoConfiguration #23686

ttddyy opened this issue Sep 24, 2019 · 5 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@ttddyy
Copy link
Contributor

ttddyy commented Sep 24, 2019

TaskExecutionAutoConfiguration currently only take single TaskDecorator bean.
This is because there is no implementation that represents multiple TaskDeorators. (e.g.: CompositeTaskDecorator).

I handle this by creating CompositeTaskDecorator:

public class CompositeTaskDecorator implements TaskDecorator {
    private List<TaskDecorator> taskDecorators = new ArrayList<>();

    public CompositeTaskDecorator(Collection<? extends TaskDecorator> taskDecorators) {
        this.taskDecorators.addAll(taskDecorators);
    }

    public CompositeTaskDecorator(TaskDecorator... taskDecorators) {
        this.taskDecorators.addAll(Arrays.asList(taskDecorators));
    }

    public boolean add(TaskDecorator taskDecorator) {
        return this.taskDecorators.add(taskDecorator);
    }

    @Override
    public Runnable decorate(Runnable runnable) {
        for (TaskDecorator taskDecorator : this.taskDecorators) {
            runnable = taskDecorator.decorate(runnable);
        }
        return runnable;
    }
}

I believe it is pretty common to have usecases to apply multiple TaskDecorators; so, it is nice if CompositeTaskDecorator is available in either spring or spring-boot.

Then, if such class is available, TaskExecutionAutoConfiguration(TaskExecutorBuilder) can detect multiple task decorators.

TaskDecorator taskDecorator(ObjectProvider<TaskDecorator> taskDeorators) {
  return new CompositeTaskDecorator(taskDeorators.orderedStream().collect(Collectors.toList()));
}
@snicoll snicoll transferred this issue from spring-projects/spring-boot Sep 24, 2019
@snicoll
Copy link
Member

snicoll commented Sep 24, 2019

I've moved that suggestion to Spring Framework. If it turns out this gets added in the core container, we can make the necessary changes in Spring Boot.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 24, 2019
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Sep 24, 2019
ttddyy added a commit to ttddyy/spring-framework that referenced this issue Sep 24, 2019
@cptully
Copy link

cptully commented Jun 16, 2022

This is an old issue, any movement? I'm glad I googled, because I was about to run into the exact issue solved by this PR!

@sbrannen sbrannen changed the title Multiple TaskDecorator support in TaskExecutionAutoConfiguration Support multiple TaskDecorators in TaskExecutionAutoConfiguration Jun 17, 2022
@sbrannen sbrannen added this to the Triage Queue milestone Jun 17, 2022
@sbrannen
Copy link
Member

This is an old issue, any movement?

We'll discuss it within the team.

@cptully
Copy link

cptully commented Jun 17, 2022

Great!

@rstoyanchev rstoyanchev removed this from the Triage Queue milestone Jan 20, 2023
@bclozel bclozel self-assigned this Jun 5, 2023
@bclozel bclozel removed their assignment Jun 28, 2023
@snicoll
Copy link
Member

snicoll commented Aug 23, 2023

Closing in favor of PR #23692

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2023
@snicoll snicoll added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants