mirror of
https://github.com/square/okhttp.git
synced 2025-08-07 12:42:57 +03:00
Temporarily remove ConnectionListener from the public API (#8831)
I'd like to update the API to improve observability into things like ConnecitonPool, RoutePlanner, ConnectPlan, and ReusePlan. And also into HTTP/2 internals like flow-control. As-is this is more coupled to Call lifecycles and is somewhat duplicative with ConnectionPool. We'll do that work and make it a new public API, but we won't have it in the public API at all for the 5.0 release. Co-authored-by: Jesse Wilson <jwilson@squareup.com>
This commit is contained in:
@@ -13,6 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
@file:Suppress(
|
||||||
|
"CANNOT_OVERRIDE_INVISIBLE_MEMBER",
|
||||||
|
"INVISIBLE_MEMBER",
|
||||||
|
"INVISIBLE_REFERENCE",
|
||||||
|
)
|
||||||
|
|
||||||
package okhttp3
|
package okhttp3
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ class OkHttpClientTestRule :
|
|||||||
private lateinit var testName: String
|
private lateinit var testName: String
|
||||||
private var defaultUncaughtExceptionHandler: Thread.UncaughtExceptionHandler? = null
|
private var defaultUncaughtExceptionHandler: Thread.UncaughtExceptionHandler? = null
|
||||||
private var taskQueuesWereIdle: Boolean = false
|
private var taskQueuesWereIdle: Boolean = false
|
||||||
val connectionListener = RecordingConnectionListener()
|
private val connectionListener = RecordingConnectionListener()
|
||||||
|
|
||||||
var logger: Logger? = null
|
var logger: Logger? = null
|
||||||
|
|
||||||
|
@@ -13,6 +13,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
@file:Suppress(
|
||||||
|
"CANNOT_OVERRIDE_INVISIBLE_MEMBER",
|
||||||
|
"INVISIBLE_MEMBER",
|
||||||
|
"INVISIBLE_REFERENCE",
|
||||||
|
)
|
||||||
|
|
||||||
package okhttp3
|
package okhttp3
|
||||||
|
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
@@ -24,11 +30,12 @@ import java.util.Deque
|
|||||||
import java.util.concurrent.ConcurrentLinkedDeque
|
import java.util.concurrent.ConcurrentLinkedDeque
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import okhttp3.ConnectionEvent.NoNewExchanges
|
import okhttp3.ConnectionEvent.NoNewExchanges
|
||||||
|
import okhttp3.internal.connection.ConnectionListener
|
||||||
import okhttp3.internal.connection.RealConnection
|
import okhttp3.internal.connection.RealConnection
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
|
|
||||||
open class RecordingConnectionListener(
|
internal open class RecordingConnectionListener(
|
||||||
/**
|
/**
|
||||||
* An override to ignore the normal order that is enforced.
|
* An override to ignore the normal order that is enforced.
|
||||||
* EventListeners added by Interceptors will not see all events.
|
* EventListeners added by Interceptors will not see all events.
|
||||||
|
@@ -36,6 +36,7 @@ import okhttp3.internal.concurrent.TaskFaker
|
|||||||
import okhttp3.internal.concurrent.TaskRunner
|
import okhttp3.internal.concurrent.TaskRunner
|
||||||
import okhttp3.internal.concurrent.withLock
|
import okhttp3.internal.concurrent.withLock
|
||||||
import okhttp3.internal.connection.CallConnectionUser
|
import okhttp3.internal.connection.CallConnectionUser
|
||||||
|
import okhttp3.internal.connection.ConnectionListener
|
||||||
import okhttp3.internal.connection.FastFallbackExchangeFinder
|
import okhttp3.internal.connection.FastFallbackExchangeFinder
|
||||||
import okhttp3.internal.connection.RealCall
|
import okhttp3.internal.connection.RealCall
|
||||||
import okhttp3.internal.connection.RealConnection
|
import okhttp3.internal.connection.RealConnection
|
||||||
|
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Block, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package okhttp3.internal.http2
|
|
||||||
|
|
||||||
import okhttp3.ConnectionListener
|
|
||||||
import okhttp3.internal.http2.flowcontrol.WindowCounter
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ConnectionListener that outputs CSV for flow control of client receiving streams.
|
|
||||||
*/
|
|
||||||
class Http2FlowControlConnectionListener :
|
|
||||||
ConnectionListener(),
|
|
||||||
FlowControlListener {
|
|
||||||
val start = System.currentTimeMillis()
|
|
||||||
|
|
||||||
override fun receivingStreamWindowChanged(
|
|
||||||
streamId: Int,
|
|
||||||
windowCounter: WindowCounter,
|
|
||||||
bufferSize: Long,
|
|
||||||
) {
|
|
||||||
println("${System.currentTimeMillis() - start},$streamId,${windowCounter.unacknowledged},$bufferSize")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun receivingConnectionWindowChanged(windowCounter: WindowCounter) {
|
|
||||||
println("${System.currentTimeMillis() - start},0,${windowCounter.unacknowledged},")
|
|
||||||
}
|
|
||||||
}
|
|
@@ -333,27 +333,9 @@ public abstract interface class okhttp3/Connection {
|
|||||||
public abstract fun socket ()Ljava/net/Socket;
|
public abstract fun socket ()Ljava/net/Socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class okhttp3/ConnectionListener {
|
|
||||||
public static final field Companion Lokhttp3/ConnectionListener$Companion;
|
|
||||||
public fun <init> ()V
|
|
||||||
public fun connectEnd (Lokhttp3/Connection;Lokhttp3/Route;Lokhttp3/Call;)V
|
|
||||||
public fun connectFailed (Lokhttp3/Route;Lokhttp3/Call;Ljava/io/IOException;)V
|
|
||||||
public fun connectStart (Lokhttp3/Route;Lokhttp3/Call;)V
|
|
||||||
public fun connectionAcquired (Lokhttp3/Connection;Lokhttp3/Call;)V
|
|
||||||
public fun connectionClosed (Lokhttp3/Connection;)V
|
|
||||||
public fun connectionReleased (Lokhttp3/Connection;Lokhttp3/Call;)V
|
|
||||||
public fun noNewExchanges (Lokhttp3/Connection;)V
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class okhttp3/ConnectionListener$Companion {
|
|
||||||
public final fun getNONE ()Lokhttp3/ConnectionListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class okhttp3/ConnectionPool {
|
public final class okhttp3/ConnectionPool {
|
||||||
public fun <init> ()V
|
public fun <init> ()V
|
||||||
public fun <init> (IJLjava/util/concurrent/TimeUnit;)V
|
public fun <init> (IJLjava/util/concurrent/TimeUnit;)V
|
||||||
public fun <init> (IJLjava/util/concurrent/TimeUnit;Lokhttp3/ConnectionListener;)V
|
|
||||||
public synthetic fun <init> (IJLjava/util/concurrent/TimeUnit;Lokhttp3/ConnectionListener;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
|
||||||
public final fun connectionCount ()I
|
public final fun connectionCount ()I
|
||||||
public final fun evictAll ()V
|
public final fun evictAll ()V
|
||||||
public final fun idleConnectionCount ()I
|
public final fun idleConnectionCount ()I
|
||||||
|
@@ -333,27 +333,9 @@ public abstract interface class okhttp3/Connection {
|
|||||||
public abstract fun socket ()Ljava/net/Socket;
|
public abstract fun socket ()Ljava/net/Socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class okhttp3/ConnectionListener {
|
|
||||||
public static final field Companion Lokhttp3/ConnectionListener$Companion;
|
|
||||||
public fun <init> ()V
|
|
||||||
public fun connectEnd (Lokhttp3/Connection;Lokhttp3/Route;Lokhttp3/Call;)V
|
|
||||||
public fun connectFailed (Lokhttp3/Route;Lokhttp3/Call;Ljava/io/IOException;)V
|
|
||||||
public fun connectStart (Lokhttp3/Route;Lokhttp3/Call;)V
|
|
||||||
public fun connectionAcquired (Lokhttp3/Connection;Lokhttp3/Call;)V
|
|
||||||
public fun connectionClosed (Lokhttp3/Connection;)V
|
|
||||||
public fun connectionReleased (Lokhttp3/Connection;Lokhttp3/Call;)V
|
|
||||||
public fun noNewExchanges (Lokhttp3/Connection;)V
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class okhttp3/ConnectionListener$Companion {
|
|
||||||
public final fun getNONE ()Lokhttp3/ConnectionListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class okhttp3/ConnectionPool {
|
public final class okhttp3/ConnectionPool {
|
||||||
public fun <init> ()V
|
public fun <init> ()V
|
||||||
public fun <init> (IJLjava/util/concurrent/TimeUnit;)V
|
public fun <init> (IJLjava/util/concurrent/TimeUnit;)V
|
||||||
public fun <init> (IJLjava/util/concurrent/TimeUnit;Lokhttp3/ConnectionListener;)V
|
|
||||||
public synthetic fun <init> (IJLjava/util/concurrent/TimeUnit;Lokhttp3/ConnectionListener;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
|
||||||
public final fun connectionCount ()I
|
public final fun connectionCount ()I
|
||||||
public final fun evictAll ()V
|
public final fun evictAll ()V
|
||||||
public final fun idleConnectionCount ()I
|
public final fun idleConnectionCount ()I
|
||||||
|
@@ -18,6 +18,7 @@ package okhttp3
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import okhttp3.internal.concurrent.TaskRunner
|
import okhttp3.internal.concurrent.TaskRunner
|
||||||
|
import okhttp3.internal.connection.ConnectionListener
|
||||||
import okhttp3.internal.connection.FastFallbackExchangeFinder
|
import okhttp3.internal.connection.FastFallbackExchangeFinder
|
||||||
import okhttp3.internal.connection.ForceConnectRoutePlanner
|
import okhttp3.internal.connection.ForceConnectRoutePlanner
|
||||||
import okhttp3.internal.connection.RealConnectionPool
|
import okhttp3.internal.connection.RealConnectionPool
|
||||||
@@ -82,9 +83,8 @@ class ConnectionPool internal constructor(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Public API
|
// Internal until we promote ConnectionListener to be a public API.
|
||||||
@ExperimentalOkHttpApi
|
internal constructor(
|
||||||
constructor(
|
|
||||||
maxIdleConnections: Int = 5,
|
maxIdleConnections: Int = 5,
|
||||||
keepAliveDuration: Long = 5,
|
keepAliveDuration: Long = 5,
|
||||||
timeUnit: TimeUnit = TimeUnit.MINUTES,
|
timeUnit: TimeUnit = TimeUnit.MINUTES,
|
||||||
|
@@ -20,7 +20,6 @@ import java.net.InetAddress
|
|||||||
import java.net.Proxy
|
import java.net.Proxy
|
||||||
import java.net.Socket
|
import java.net.Socket
|
||||||
import okhttp3.Connection
|
import okhttp3.Connection
|
||||||
import okhttp3.ConnectionListener
|
|
||||||
import okhttp3.EventListener
|
import okhttp3.EventListener
|
||||||
import okhttp3.Handshake
|
import okhttp3.Handshake
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
|
@@ -13,8 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3
|
package okhttp3.internal.connection
|
||||||
|
|
||||||
|
import okhttp3.Call
|
||||||
|
import okhttp3.Connection
|
||||||
|
import okhttp3.Route
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,8 +27,7 @@ import okio.IOException
|
|||||||
* attempt to mutate the event parameters, or be reentrant back into the client.
|
* attempt to mutate the event parameters, or be reentrant back into the client.
|
||||||
* Any IO - writing to files or network should be done asynchronously.
|
* Any IO - writing to files or network should be done asynchronously.
|
||||||
*/
|
*/
|
||||||
@ExperimentalOkHttpApi
|
internal abstract class ConnectionListener {
|
||||||
abstract class ConnectionListener {
|
|
||||||
/**
|
/**
|
||||||
* Invoked as soon as a call causes a connection to be started.
|
* Invoked as soon as a call causes a connection to be started.
|
||||||
*/
|
*/
|
||||||
@@ -78,7 +80,6 @@ abstract class ConnectionListener {
|
|||||||
*/
|
*/
|
||||||
open fun noNewExchanges(connection: Connection) {}
|
open fun noNewExchanges(connection: Connection) {}
|
||||||
|
|
||||||
@ExperimentalOkHttpApi
|
|
||||||
companion object {
|
companion object {
|
||||||
val NONE: ConnectionListener = object : ConnectionListener() {}
|
val NONE: ConnectionListener = object : ConnectionListener() {}
|
||||||
}
|
}
|
@@ -27,7 +27,6 @@ import javax.net.ssl.SSLPeerUnverifiedException
|
|||||||
import javax.net.ssl.SSLSocket
|
import javax.net.ssl.SSLSocket
|
||||||
import okhttp3.Address
|
import okhttp3.Address
|
||||||
import okhttp3.Connection
|
import okhttp3.Connection
|
||||||
import okhttp3.ConnectionListener
|
|
||||||
import okhttp3.Handshake
|
import okhttp3.Handshake
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@@ -67,7 +66,7 @@ import okio.buffer
|
|||||||
* Connections are shared in a connection pool. Accesses to the connection's state must be guarded
|
* Connections are shared in a connection pool. Accesses to the connection's state must be guarded
|
||||||
* by holding a lock on the connection.
|
* by holding a lock on the connection.
|
||||||
*/
|
*/
|
||||||
class RealConnection(
|
class RealConnection internal constructor(
|
||||||
val taskRunner: TaskRunner,
|
val taskRunner: TaskRunner,
|
||||||
val connectionPool: RealConnectionPool,
|
val connectionPool: RealConnectionPool,
|
||||||
override val route: Route,
|
override val route: Route,
|
||||||
|
@@ -22,7 +22,6 @@ import java.util.concurrent.ThreadLocalRandom
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
|
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
|
||||||
import okhttp3.Address
|
import okhttp3.Address
|
||||||
import okhttp3.ConnectionListener
|
|
||||||
import okhttp3.ConnectionPool
|
import okhttp3.ConnectionPool
|
||||||
import okhttp3.Route
|
import okhttp3.Route
|
||||||
import okhttp3.internal.closeQuietly
|
import okhttp3.internal.closeQuietly
|
||||||
@@ -36,7 +35,7 @@ import okhttp3.internal.okHttpName
|
|||||||
import okhttp3.internal.platform.Platform
|
import okhttp3.internal.platform.Platform
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
|
|
||||||
class RealConnectionPool(
|
class RealConnectionPool internal constructor(
|
||||||
private val taskRunner: TaskRunner,
|
private val taskRunner: TaskRunner,
|
||||||
/**
|
/**
|
||||||
* The maximum number of idle connections across all addresses.
|
* The maximum number of idle connections across all addresses.
|
||||||
|
@@ -24,7 +24,6 @@ import java.nio.charset.Charset
|
|||||||
import javax.net.ssl.SSLSocket
|
import javax.net.ssl.SSLSocket
|
||||||
import okhttp3.Cache
|
import okhttp3.Cache
|
||||||
import okhttp3.CipherSuite
|
import okhttp3.CipherSuite
|
||||||
import okhttp3.ConnectionListener
|
|
||||||
import okhttp3.ConnectionPool
|
import okhttp3.ConnectionPool
|
||||||
import okhttp3.ConnectionSpec
|
import okhttp3.ConnectionSpec
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
@@ -36,6 +35,7 @@ import okhttp3.OkHttpClient
|
|||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.internal.concurrent.TaskRunner
|
import okhttp3.internal.concurrent.TaskRunner
|
||||||
|
import okhttp3.internal.connection.ConnectionListener
|
||||||
import okhttp3.internal.connection.RealConnection
|
import okhttp3.internal.connection.RealConnection
|
||||||
|
|
||||||
internal fun parseCookie(
|
internal fun parseCookie(
|
||||||
|
@@ -13,6 +13,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
@file:Suppress(
|
||||||
|
"CANNOT_OVERRIDE_INVISIBLE_MEMBER",
|
||||||
|
"INVISIBLE_MEMBER",
|
||||||
|
"INVISIBLE_REFERENCE",
|
||||||
|
)
|
||||||
|
|
||||||
package okhttp3
|
package okhttp3
|
||||||
|
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
|
@@ -31,7 +31,6 @@ import java.net.URI
|
|||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
import okhttp3.Address
|
import okhttp3.Address
|
||||||
import okhttp3.ConnectionListener
|
|
||||||
import okhttp3.FakeDns
|
import okhttp3.FakeDns
|
||||||
import okhttp3.OkHttpClientTestRule
|
import okhttp3.OkHttpClientTestRule
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
Reference in New Issue
Block a user