Increasing the thread pool for OkHttp in order to sustain more connections.
This commit is contained in:
+29
-2
@@ -20,6 +20,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.service.okhttp
|
package com.vitorpamplona.amethyst.service.okhttp
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import com.vitorpamplona.amethyst.isDebug
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import okhttp3.Dispatcher
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.net.Proxy
|
import java.net.Proxy
|
||||||
@@ -36,9 +43,29 @@ class OkHttpClientFactory(
|
|||||||
const val DEFAULT_TIMEOUT_ON_MOBILE_SECS: Int = 30
|
const val DEFAULT_TIMEOUT_ON_MOBILE_SECS: Int = 30
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val logging = LoggingInterceptor()
|
||||||
|
val keyDecryptor = EncryptedBlobInterceptor(keyCache)
|
||||||
|
|
||||||
|
val myDispatcher =
|
||||||
|
Dispatcher().apply {
|
||||||
|
maxRequests = 512
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (isDebug) {
|
||||||
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
while (true) {
|
||||||
|
Log.d("OkHttpClientFactory", "Active threads ${myDispatcher.runningCallsCount()}")
|
||||||
|
delay(5000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val rootClient =
|
private val rootClient =
|
||||||
OkHttpClient
|
OkHttpClient
|
||||||
.Builder()
|
.Builder()
|
||||||
|
.dispatcher(myDispatcher)
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.followSslRedirects(true)
|
.followSslRedirects(true)
|
||||||
.build()
|
.build()
|
||||||
@@ -57,8 +84,8 @@ class OkHttpClientFactory(
|
|||||||
.connectTimeout(duration)
|
.connectTimeout(duration)
|
||||||
.writeTimeout(duration)
|
.writeTimeout(duration)
|
||||||
.addInterceptor(DefaultContentTypeInterceptor(userAgent))
|
.addInterceptor(DefaultContentTypeInterceptor(userAgent))
|
||||||
.addNetworkInterceptor(LoggingInterceptor())
|
.addNetworkInterceptor(logging)
|
||||||
.addNetworkInterceptor(EncryptedBlobInterceptor(keyCache))
|
.addNetworkInterceptor(keyDecryptor)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user