From 3fefb2e4d6dd3b1fa50478161ab6fb5dcf3871bc Mon Sep 17 00:00:00 2001 From: Nathan Hamblen Date: Thu, 1 Nov 2012 00:00:46 -0400 Subject: [PATCH] 1. Eliminates underlying client's default request timeout which interferes with streaming API consumption. 2. Provides a method Http#configure for altering the client configuration. Fixes #30 --- core/src/main/scala/execution.scala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/execution.scala b/core/src/main/scala/execution.scala index 12127a7c..bbc11daa 100644 --- a/core/src/main/scala/execution.scala +++ b/core/src/main/scala/execution.scala @@ -15,6 +15,8 @@ case class Http( promiseExecutor: juc.Executor = Defaults.promiseExecutor, timer: Timer = Defaults.timer ) extends HttpExecutor { + import AsyncHttpClientConfig.Builder + /** Convenience method for an Executor with the given timeout */ def waiting(t: Duration) = copy(timeout=t) @@ -22,6 +24,15 @@ case class Http( the given size */ def threads(promiseThreadPoolSize: Int) = copy(promiseExecutor = DaemonThreads(promiseThreadPoolSize)) + + /** Replaces `client` with a new instance configured using the withBuilder + function. The current client config is the builder's prototype. */ + def configure(withBuilder: Builder => Builder) = + copy(client = + new AsyncHttpClient(withBuilder( + new AsyncHttpClientConfig.Builder(client.getConfig) + ).build) + ) } /** Singleton default Http executor, can be used directly or altered @@ -41,7 +52,8 @@ private [dispatch] object Defaults { new NettyAsyncHttpProviderConfig().addProperty( NettyAsyncHttpProviderConfig.BOSS_EXECUTOR_SERVICE, bossExecutor ) - ).build() + ).setRequestTimeoutInMs(-1) // don't timeout streaming connections + .build lazy val bossExecutor = juc.Executors.newCachedThreadPool(DaemonThreads.factory) lazy val promiseExecutor = DaemonThreads(256)