Mindbowser / javapns

Automatically exported from code.google.com/p/javapns
0 stars 0 forks source link

Missing call to setMaxRetained in NotificationThreads.getPushedNotifications #101

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. send a simple payload to a large number of devices (more than 1000 for 
example 1500) using the Push.payload() method.

What is the expected output? What do you see instead?
I expect to have 1500 PushedNotifications in the returned PushedNotifications 
collection. I got instead the last 1000 Notifications.

What version of the product are you using? On what operating system?

Latest beta (2.2 beta3).

Please provide any additional information below.

To fix the problem simply add a call to setMaxRetain in the constructor of 
PushedNotifications(int capacity) like this:

 /**
     * Construct an empty list of PushedNotification objects with a suggested
     * initial capacity.
     * 
     * @param capacity
     */
    public PushedNotifications(int capacity) {
        super(capacity);
        setMaxRetained(capacity);
    }

Original issue reported on code.google.com by ericpr...@gmail.com on 19 Jan 2012 at 8:28

GoogleCodeExporter commented 8 years ago
The capacity argument you see there corresponds to the Vector's initial 
capacity (see java.util.Vector's javadoc).  It is not related to the 
maxRetained feature.

Original comment by sype...@gmail.com on 19 Jan 2012 at 2:57

GoogleCodeExporter commented 8 years ago
Ok, but my concern is in the following code:

@Override
    public PushedNotifications getPushedNotifications() {
        int capacity = 0;
        for (NotificationThread thread : threads)
            capacity += thread.getPushedNotifications().size();
        PushedNotifications all = new PushedNotifications(capacity);
        for (NotificationThread thread : threads)
            all.addAll(thread.getPushedNotifications());
        return all;
    }

you compute the capacity of the array but you don't call the setMaxRetained 
capacity. When you call addAll(), it will retain only the last 1000 entries 
(see prepareAdd()).  

To fix the pb I put the call to setMaxRetained() in the PushedNotifications 
constructor, but you can either put it just after the PushedNotifications 
object is created.

PushedNotifications all = new PushedNotifications(capacity);
all.setMaxRetained(capacity);

Original comment by ericpr...@gmail.com on 19 Jan 2012 at 3:31

GoogleCodeExporter commented 8 years ago
Fixed in r351 (in source code only, will be part of the next build).

Original comment by sype...@gmail.com on 19 Jan 2012 at 3:42