web service Rest Client creation

Hi,
when and why two use below two ways of web service Rest type Client creation



1.Futue way of doing like Future<boolean> f= asyncInvoker.post


2.call back handler way of doing

please advise
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
These two methods are even really tied to Rest clients, they are two alternatives for processing the results of any asynchronous process, ie. a process where the result will arrive at *some* time in the future, it may be straight away, it may be in 10 seconds or it may be in 10 hours.

There is no right or wrong method to choose, it depends totally on the particular situation where they are used. However some general guidelines might be.... Use Future's where the code after the call to start the async process needs to use the result at some point. Take this pseudo code for example....

Future f = startAsyncProcessToGetAResult();

// do some other general work here that does NOT depend on the result of the above, this means that we can still be working while the async process is also working.

// Ok, we've done all that we can do that doesn't depend on the result, so now wait for the result.
result = f.get();             // This may return straight away, if the async process was quick, or it may cause us to wait until the async process has finished generating our result

// Now we have the result, we can do something with it here...



The above would be hard with callback handlers because we would need to arrange for the code after the async request, to communicate with the callback handler to get the result when it was ready. It can be done, but just more complex.


On the otherside then, callback handlers are good for where we need to start and async process but either there is NO result, or the result is used by not by the original method that kicked off the call. Consider another example where we want to efficiently download a set of images from a website and store them on disk. We could use the following pseudo code...

for (String url : imageUrlList) {
   startImageDownloader(new DownloaderCallback() {
      public void doWithImage(Image i) {
         writeImageToFile(i, parentDirectory);
      }
   }
}

Again this could be done with a Future<Image> but then we would need to track all the Future's that are returned for each image, and then wait on them all, and when each one resolves, write the image to disk. Again, yes it is possible, but it is just not as elegant at the above.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
Any detailed link or ebook or resource on this with simple examples. please advise
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Any detailed link or ebook or resource on this

Not that I know of.

with simple examples

I gave you a couple of simple examples. If you didn't understand anything about them, ask questions.
0
gudii9Author Commented:
ie. a process where the result will arrive at *some* time in the future, it may be straight away, it may be in 10 seconds or it may be in 10 hours.
how to specify the time like 10 seconds or 10 minutes etc. Is it is passed as argument of post method?
The above would be hard with callback handlers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.