Announcement Announcement Module
Collapse
No announcement yet.
Aggregator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Aggregator

    From http://static.springsource.org/sprin...le/#aggregator

    Code:
    public class PojoAggregator {
    
      public Long add(List<Long> results) {
        long total = 0l;
        for (long partialResult: results) {
          total += partialResult;
        }
        return total;
      }
    
    }
    
    public class PojoReleaseStrategy {
    ...
      public boolean canRelease(List<Long> numbers) {
        int sum = 0;
        for (long number: numbers) {
          sum += number;
        }
        return sum >= maxValue;
      }
    }
    
    public class PojoCorrelationStrategy {
    ...
      public Long groupNumbersByLastDigit(Long number) {
        return number % 10;
      }
    }
    I have a couple of questions:

    1. PojoCorrelationStrategy groups numbers based on the remainder.
    a. Where does it store these numbers?

    b. If there are five incoming numbers: 5, 5, 10, 10, 5
    we would have two groups of numbers:
    First group: 5 (5 %10 = 5)
    Second group: 0 (10 % 10 = 0)

    Who uses theses results: 5 and 0?

    2. PojoReleaseStrategy releases only when the sum of the numbers on the list are greater than max value.

    a. Where is max value stored? Private field?
    b. Where is the list coming? Is it coming from the channel or coming from the PojoCorrelationStrategy?
    c. What's the relation between PojoCorrelationStrategy and PojoReleaseStrategy. I know the definition but what doesn't make sense is how are their returned values interconnected.

    3. PojoAggregator
    a. It gets it values based on the input channel. But the values it will only accept are the ones that are correlated by the PojoCorrelationStrategy. Is that right?

    b. This means all numbers that have remainder of 1 (for example) will be aggregated by the PojoAggregator. What happens to numbers that have remainder of 2, 3, and so forth?

    Thank you.

  • #2
    1. PojoCorrelationStrategy groups numbers based on the remainder.
    a. Where does it store these numbers?
    It stores them in the MessageStore which by default is a SimpleMessageStore (in memory). However since MessageStore is a strategy interface you can plug your own implementation. Spring Integration provides JdbcMessageStore.

    b. If there are five incoming numbers: 5, 5, 10, 10, 5
    we would have two groups of numbers:
    First group: 5 (5 %10 = 5)
    Second group: 0 (10 % 10 = 0)
    That is a correlating key which is how CorrelatingMessageHandler manages MessageGroupStore which itself is persisted in MessageStore
    Code:
    MessageGroup group = messageStore.getMessageGroup(correlationKey);
    2. PojoReleaseStrategy releases only when the sum of the numbers on the list are greater than max value.

    a. Where is max value stored? Private field?
    Private field is one of the option. Remember the emphasis here is on the POJO meaning you implement it any way you want to.

    Where is the list coming?
    List is the list of already aggregated messages. Remember Aggregator will continue to aggregate them until they are ready to be released. ALso remember that the emphasis here is on PJO part. You could just as well implement ReleaseStrategy interface which defines canRelease(MessageGroup) method, but that would put you in dependency on our API where here you define your own method, your own class and the only thing you have to be compatible with is that MessageGroup which is essentially a List of Messages for a particular correlationKey. However if dealing with the MesageGroup you would also have to deal with Messages and get a payload from them. With POJO approach you get a List of payloads for all the messages in a particular message group.

    Comment


    • #3
      oleg, thanks for the reply. I really appreciate it.

      I noticed when I send four Objects (in sequence) i.e pen, paper, paper, pen and correlate them based on time, the Aggregator will group the two pens and returnthat first. Then it will aggregrate the two papers and returned it.

      My ReleaseStrategy is to release for every two items.

      This is the correct behavior, right?

      Thanks

      Comment


      • #4
        Yes, based on the sequence of objects sent and the sequence number you've specified (2), I would expect 2 results from the aggregator each containing two messages where paper would come before pen since its going to be aggregated faster.

        Comment

        Working...
        X