java实现请求排队处理,异步HTTP请求,排队的请求

I have developed for appstore before and I used ASIHTTPRequest. Is there something similar for Android?

Am looking at making a few HTTP requests, which are queued and manageable. This is what I need to do:

Set-up a queue of lets say 6 http requests.

Once the queue is setup, execute it with each request giving me a success/failure result.

If one request fails, I have the option to cancel/clear the whole queue.

If all the requests in the queue are successful, I can have another callback for the whole queue's success event.

And,each request can have a retry count; meaning; I can say each request can retry n number of time before they can return a failure.

ASIHTTPRequest for IOS was pretty good at handling this. Is there anyway I can do this with Android? Most of my content returned is XML and no binary data.

Any feedback is much appreciated.

解决方案

What you describe is not overly complicated to build.

Extend java.util.Queue

Create custom "listener" interface which handles all the events you need to track.

Custom request objects that allow a "listener" to be set.

Your custom queue will have a thread to process items in it's own queue.

Depending on your exact requirements, you may also need an additional interface/listener to pass back the final response to the object that made the initial request.

When adding an object to the queue, your queue would set itself as the "listener" on the custom request object.

When the events happen in the request object, the event methods will be called on the listener object...in the case the queue...which can react appropriately.

I suspect something like ASIHTTPRequest does not really exist in Java/Android, because it's not as difficult a problem to solve as on iOS. I could implement the above objects into a functional component in 20 minutes or less. Of course, if you've not done something like this before, it may take you much longer.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值