title: Maintaing multiple HttpRequests through a daemon thread in Mule
body: <p>I have a scenario that requires a synchronous web service to create a response after making a call to an asynchronous service (with a correlation ID to identify this event at a later time). The asynchronous service would place the results in a cache. And my web service needs to setup an active poller/listener to wait for an event with the same correlation id to be inserted in the cache. Once the record is available, the web service can create a response object and send it over to client.</p>
  
  <p>Now, the async process could take a long time which would result in idling the main thread of my web service.
  The web service is being developed as a mule workflow, and the exact scenario is shown below:</p>
  
  <p>
  <pre>                   |&rarr; async service &rarr; update cache &rarr; end <b>//Async thread</b>
  Client--> myWebSvc |
                     |&rarr; setup cache listener &rarr; onEvent() &rarr; respond to Client <b>//Main thread</b></pre>
  </p>
  
  <p>Is there a way in mule that could help me maintain a map of such HttpRequests and maintain them in a daemon thread? This would help take up new requests while waiting on response for old ones. </p>
  
  <p>I have started looking at Java NIO but am unable to think of ways to integrate it with the Mule workflow. Is there a solution within mule that can help me free up the main thread and store the HttpRequest object in a map to be called upon later?</p>
  
  <p>Just a few more details:
  The web service is implemented in java. The mule workflow looks like this:</p>
  
  <pre>
  
                                               |&rarr; async subflow to invoke async process
  HTTP Request &rarr; CXF component &rarr; Java component|
                                               |&rarr; (sub flow) Java component to listen to events
  </pre>