Results 1 to 15 of 15
  1.    #1  
    The download manager is pretty straight forward for downloading files, but I am not sure how manage its asynchronous behavior with a high download count.

    Let's say you want to download 200 pictures. The easiest thing to do would be to send all 200 picture URLs to the download manager and then wait for them to complete. However, the download manager seems to only accept 130 files at a time and returns error -3 after that.

    Ok, so I'll send 130 of the 200 to the download manager, wait until the 130 finish and then push the other 70 to the download manager (or push one on every time one finishes).

    This is where the download manager gets tricky to me.

    Option 1
    I can call queryStatus for each individual file to can check to see if they are done, but there is no callback for the download manager as a whole, to say "I'm done. Give me more."

    Option 2
    I can call the listPending function in a loop until it returns a count of 0, but that seems brute force.

    Option 3
    The other option seems to be to keep a list of all the tokens I receive from the download manager (IDs for all the downloads in progress) and remove them from the list/array that I keep of them, one by one, as the onSuccess function of the download manager tells me they are complete, until they are all removed. That seems like the best approach, but also a bit of work to implement.

    What I would really like is a callback for when download count hits 0.

    Which option do you all like? Is there another approach that I am missing?

    Thanks for your thoughts!
    Check out my apps at clearwaterapps.com
  2.    #2  
    I think I am going to use setTimeout() to call listPending periodically until the count = 0
    Check out my apps at clearwaterapps.com
  3. tc600's Avatar
    Posts
    305 Posts
    Global Posts
    306 Global Posts
    #3  
    I've found it a little frustrating dealing with the downloads. The callbacks sometimes seem to disappear/never get called.

    I set up two queues, one to hold everything I intend to download and one to hold the active downloads. At the start I move elements from the full queue to download queue, then activate the downloads from the download queue. As they finish downloading, I remove them from the active queue and move more elements from the full queue over to the download queue. This is a kin to customers standing in line waiting to be served by an open cash register at a store. Occasionally though, the downloads never indicate that they've completed (although I have subscribed), so I have to initiate a Download Status Query to find out.

    listPending sounds like it could work too. I'd like to hear if it works out well ...
  4.    #4  
    Quote Originally Posted by tc600 View Post
    I've found it a little frustrating dealing with the downloads. The callbacks sometimes seem to disappear/never get called.

    I set up two queues, one to hold everything I intend to download and one to hold the active downloads. At the start I move elements from the full queue to download queue, then activate the downloads from the download queue. As they finish downloading, I remove them from the active queue and move more elements from the full queue over to the download queue. This is a kin to customers standing in line waiting to be served by an open cash register at a store. Occasionally though, the downloads never indicate that they've completed (although I have subscribed), so I have to initiate a Download Status Query to find out.

    listPending sounds like it could work too. I'd like to hear if it works out well ...
    Cool. Thanks for your input.

    I'll let you know how it goes.

    listPending should simplify the process, but I won't have information on the status of individual files like your approach does.

    I just realized that the setTimeout function only works if the screen is on, so I don't know how I am going to periodically call listPending yet...
    Check out my apps at clearwaterapps.com
  5.    #5  
    Well, I am not thrilled with it, but I think I am going to run with it for now...

    I built an array of all the URLs to download.
    Then I send 50 of them to the download manager and splice them off of the array.
    Next, I use the window setTimeout() function to periodically call listPending and see if there are 0 active downloads. If so, I throw another 50 at it and splice them off the array. If not, I throw the rest of the array on the download manager and call listPending once a second, again with setTimeout, until there are 0 active downloads.

    So, I effectively chunk up my download list and send it over.

    This does not give me any error reporting on the individual files, but I am just grabbing a bunch of pictures and don't necessarily need them all... crapy, but oh well for now.

    Also, if the screen turns off, the current chunk will finish, but the next one will not be enqueued until setTimeout can execute when the screen turns on.

    The download manager could definitely use a higher level API in my opinion.
    Check out my apps at clearwaterapps.com
  6. #6  
    it sounds like youre all doing it very weirdly, why dont you just listen for compleated: true if you set subscribe: true and then download/upload the next file?

    like so

    Code:
    this.controller.serviceRequest('palm://com.palm.downloadmanager/', {
    		 	method: 'download', // - will download specified file
    				parameters: {
    					target: "https://www.box.net/api/1.0/download/" + this.auth_token + '/'+ id,
    					targetDir : "/media/internal/" + this.name, 
    					"targetFilename" : name,
    					keepFilenameOnRedirect: true,
    					subscribe: true
    				},
    				onSuccess : this.downloadResult.bind(this),
    	            onFailure : this.downloadResult.bind(this)
    	});
    and then
    Code:
    FolderAssistant.prototype.downloadResult = function(event) {
    if (event.returnValue === true){
    this.ticket = event.ticket
    }
    else if (event.completed === true){
    this.PPmodel.value = 1;
    this.controller.modelChanged(this.PPmodel);
    this.fileNumber = this.fileNumber + 1;
    this.downloadTree();	
    }
    else if (event.ticket === this.ticket){						
    var total = event.amountTotal;
    var percent = total / 100;
    var recevied = event.amountReceived;
    var done = recevied / percent;
    var show = Math.round(done)
    if (isNaN(show)){}
    else {
    	this.PPmodel.value = show / 100;
    	this.controller.modelChanged(this.PPmodel);
    
    }
    Last edited by abegee; 07/22/2010 at 09:08 AM.
  7.    #7  
    That looks like a great way of downloading one file at a time, but I have a couple hundred small files, so I figured it would give me better performance to throw more files over the wall to the download manager at once.

    Seems like the download manager should be able to download many small files is parallel and better use the bandwidth than I could by getting one at a time.

    I guess it could use the full bandwidth on each file.

    Have you compared performance?

    I like that you have knowledge of each download though.

    If I compare the performance, I'll post back.
    Check out my apps at clearwaterapps.com
  8. #8  
    what I was saying is that the download manager does have a callback function, as for downloading multiple files at once I don't see the difference in bandwidth.
  9. #9  
    why dont you log in and watch netstat -nt output?

    remember this is a mobile device and each network connection consumes memory. i guess you could try tuning for that but you probably want to test
  10. tc600's Avatar
    Posts
    305 Posts
    Global Posts
    306 Global Posts
    #10  
    Quote Originally Posted by abegee View Post
    what I was saying is that the download manager does have a callback function, as for downloading multiple files at once I don't see the difference in bandwidth.
    I like this in theory, but in practice in any given downloading session, I've found that the onSuccess handler doesn't always fire like it's supposed to. It sometimes seemingly disappears whether I subscribe or not. Even after subscription, I can get a couple of updates and then nothing ... until I force the issue with a downloadStatusQuery.
  11. #11  
    I've never had the download manager stop working on me, I've downloaded entire folders of stuff and it's always worked.
  12. tc600's Avatar
    Posts
    305 Posts
    Global Posts
    306 Global Posts
    #12  
    I don't think it has stopped, it just occasionally hasn't fired off the onSuccess handlers so that my code knows its progress/completion. I'm trying to keep the user updated and the missing/delayed info makes it look like nothing is happening.
  13. tc600's Avatar
    Posts
    305 Posts
    Global Posts
    306 Global Posts
    #13  
    So I wish I had paid closer attention to the development of the Facebook app ... as it turns out, Service requests can get garbage collected and how to fix it is at:

    incaseofstairs - Code and other randomness

    in the post about "Garbage Collection Gotchas in webOS".
  14.    #14  
    Quote Originally Posted by tc600 View Post
    So I wish I had paid closer attention to the development of the Facebook app ... as it turns out, Service requests can get garbage collected and how to fix it is at:

    incaseofstairs - Code and other randomness

    in the post about "Garbage Collection Gotchas in webOS".
    Ok, that makes a lot of sense. Thanks for the heads up.

    I guess I am going to go back and change my implementation to a one by one call that uses the wrapper in his post.
    Check out my apps at clearwaterapps.com
  15. tc600's Avatar
    Posts
    305 Posts
    Global Posts
    306 Global Posts
    #15  
    The wrapper made a huge difference for me ... I think I now have too much extra error handling/recovery code that I can rip out.

Posting Permissions