Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

POF Serialisation and Aggregators

BretCalveyMay 2 2012 — edited May 3 2012
Hi,

We have a problem where we need to find out the "top N" of something - for example, "go and find the top 5 widgits IDs in terms of sales"

Where a Widgit is...

Widgit ID, Description, Number of unit sold

To do this, I wrote an aggregator. I got this working fine when I had the value of N hardcoded.

So I wanted to make it so that the client can pass in the value of N, i.e. ...

TopNWidgitsAggregator aggr = new TopNWidgitsAggregator(100); // Will find top 100

We are using POF so obviously I need to serialize and deserialize my "N" attribute.

As I am extending AbstractAggregator, the only way I could do this was by overriding readExternal and writeExternal...

@Override
public void readExternal(PofReader in) throws IOException {
super.readExternal(in);
n = in.readInt(3);
}

@Override
public void writeExternal(PofWriter out) throws IOException {
super.writeExternal(out);
out.writeInt(3, n);
}

This all works fine. The only thing I do not like about this is that I had to hard code the value "3". I only found out that I needed to use "3" by navigating to AbstractAggregator.readExternal in Eclipse and then working out how many "read" methods it performs against the serializer.

(Actually, now I think of it, my value should probably be 2 because the AbstractAggregator starts at POF index 0)

This is a bit ugly and wondered if there was another way of doing it.

If not, I would have thought that the AbstractAggregator would have provided a constant (called NEXT_POF_FIELD or something) so that you wouldn't have to hard code the number "3" (or 2!) everywhere.

Am I doing something wrong?

Thanks in advance,

-Bret
This post has been answered by robvarga on May 2 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 31 2012
Added on May 2 2012
2 comments
228 views