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

Composite elements do not honour @Order annotations [BATCH-1385] #2196

Closed
spring-issuemaster opened this issue Aug 26, 2009 · 1 comment
Closed

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Aug 26, 2009

Arnaud Jeansen opened BATCH-1385 and commented

It is currently not possible to force the execution order of elements (read listeners, write listeners, ...) using the @Order annotation.

After some time wondering why this was the case, I found that it was perfectly working using the Ordered interface.

The problem lies in org.springframework.batch.core.listener.OrderedComposite.
This class separates the elements in two groups "ordered" and "unordered", but it only checks to see if the element implements Ordered to decide whether it belongs in the ordered list.

<snippet from OrderedComposite>

/**
 * Register additional item.
 * 
 * @param item
 */
public void add(S item) {
     if (item instanceof Ordered) {
          if (!ordered.contains(item)) {
               ordered.add(item);
          }
     }
     else {
          if (!unordered.contains(item)) {
               unordered.add(item);
          }
     }
     list.clear();
     list.addAll(ordered);
     list.addAll(unordered);
}

{

This add method should probably do something like

/**
 * Register additional item.
 * 
 * @param item
 */
public void add(S item) {
     if (item instanceof Ordered || 
          (item != null && item.getClass().getAnnotation(Order.class) != null)) {
          if (!ordered.contains(item)) {
               ordered.add(item);
          }
     }
     else {
          if (!unordered.contains(item)) {
               unordered.add(item);
          }
     }
     list.clear();
     list.addAll(ordered);
     list.addAll(unordered);
}

With this change , the elements with the annotation will be put in the ordered set, and their order value will be properly taken into account (the ordered set relies on a correct AnnotationAwareOrderComparator)


Affects: 2.0.3

Referenced from: commits eda5e09, 822f8bb

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Sep 20, 2009

Dave Syer commented

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.