cancelAllRequests() synchronously

103 views
Skip to first unread message

Matías Dumrauf

unread,
Apr 24, 2013, 1:05:01 PM4/24/13
to robo...@googlegroups.com
I'm currently trying to implement some feature that implies making one request after the other, but cancelling the previous one.

When the spice manager executes a request, it is added to the requestQueue which is a shared variable used in the service that runs the logic, but it is scheduled for execution. The same happens when a cancel() message is sent (it is scheduled and executed async), but it uses an executor service. Both functions use a shared lock to handle concurrency.

The thing is that I need to send to execute a new Request after cancelling the current one (or all the existent ones), but as the cancel operation is async I've got a race condition against the execution of the last request added. Sometimes it gets cancelled too.


I've seen a private method in SpiceManager (cancelAllRequestsInternal()) that does the cancelling stuff. It is indeed the logic of the runnable that is sent to be executed in the ExecutorService. So, would it be correct to expose this method in the api? Is there any other way to cancel a/all request/s synchronously?


Matías

Stéphane Nicolas

unread,
May 1, 2013, 6:45:05 AM5/1/13
to robo...@googlegroups.com
Hi Mathias,

thanks for your interest in RS. Your question is actually pretty interesting. Btw, sorry for the delay, I got quite a lot of work those days...

Request cancelation is a difficult matter in RS. It relies on multi-threading, thread handling, interruption of java.io operations, etc. It is indeed, impossible to know exactly when a request will be cancelled. It will be, for sure, but some aspects of cancelation rely on very deep considerations about thread handling in java.

In this meaning, I don't see a much better approach than the path we took. This means it will not be possible to get something both fast, precise and synchronous method to cancel a request. 

What exactly do you want to achieve ? Do you want to preserve network resources ? Disk space used by cache ? How do you deal with a network request stopped while sending data to a server ? Or while having half written data in cache ? 

Stéphane



2013/4/24 Matías Dumrauf <matias....@gmail.com>


Matías

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes RoboSpice.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 



--
Stéphane NICOLAS,
OCTO Technology 
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - blog.octo.com
www.usievents.com
...........................................................

Mateusz Boś

unread,
Jan 22, 2015, 9:17:46 AM1/22/15
to robo...@googlegroups.com, snic...@octo.com
Hi Stéphane,

First of all thank you for the amazing library!


@Matías
Small chance that your problem is still unresolved(or important now) but you could try to utilize this method: http://stephanenicolas.github.io/robospice/site/latest/apidocs/com/octo/android/robospice/SpiceManager.html#cancel%28com.octo.android.robospice.request.SpiceRequest%29
However it would require to reference the SpiceRequest at all times - and here is the catch because after rotation you simply won't have a reference to it.

@Stéphane
I went through the docs and could not find any way to get a request object from spice manager
. Is there any?

Mateusz
Reply all
Reply to author
Forward
0 new messages