This page is no longer maintained — Please continue to the home page at www.scala-lang.org

actor based http client

No replies
Paul Dix
Joined: 2009-05-29,
User offline. Last seen 42 years 45 weeks ago.

Hi all,
I'm writing a small scala service that needs to make many concurrent
http requests. I know that using the apache HttpClient with the
MultThreadedHttpConnectionManager is an option. However, I'd like to
use something Actor based for managing the connections.

Along those lines I have some probably stupid questions. I just
started looking at Scala two days ago so please pardon my ignorance.

My understanding is that each Actor gets its own thread. If you
respond to things inside "react" it won't spawn additional threads.
Given that the http connections will block, I need to send each active
one out to a separate thread.

So my initial thought was to have a single Actor that will manage a
pool of HTTP client actors. When the manager receives a message to
perform a request it pulls off that pool and sends a message to one of
the clients. Once the client is done it sends a message back to the
manager which then puts the HTTP client back on the pool and sends the
completed response back to the original calling actor.

Is this a reasonable way to do connection concurrency in Scala? Is
there a better way to do things? Is there a way for me to do reactor
style IO instead? As in, do native IO where the OS handles it and only
send back to Scala when there is something to process.

Thanks, would appreciate any thoughts.

Paul

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland