• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

coordinate async responses...

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have a system where a client can send in a request, possibly for multiple logical jobs to be executed. we do each job in the input request, and assemble the responses, then send them to the client.

let's say the request is to post 3 orders to an order processing system. and each order will need to return some xml to the client giving them acknowledgement of their order. it would seem that the processor (splits up jobs and calls a worker) could work more efficiently if it could send an async message to a worker (mdb?) to handle each job, and then coordinate the results back together. what is a common practice/pattern to handle this type of coordination? if we send an async message, how do we get notified that a job is done and results are ready?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you send an async request the response comes back as an event later. And you're right: the first tricky bit in the event handler is to match the response up to the request and figure out what to do with it. Message oriented middleware like MQ-Series and other JMS implementations use a correlation id. When you put a request on queue the software gives you a correlation id. When the response comes in it will have the same id. If your async middleware doesn't do that, you can add your own id to the request and response to match them up. I wrote a bit about solutions I've tried HERE. Let me know if that's useful.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you've discovered the need for the Scatter Gather Pattern. If you buy the book, it contains much more detail on implementation tricks.

Kyle
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should also take a look at http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!