APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http

pack-priv final Class ConnectionPool

extends Object
Class Inheritance
Imports
java.io.IOException, java.net.InetSocketAddress, java.nio.ByteBuffer, java.time.temporal.ChronoUnit, java.util.ArrayList, .Collections, .HashMap, .Iterator, .LinkedList, .List, .ListIterator, .Objects, .Optional, java.util.concurrent.Flow, java.util.concurrent.locks.ReentrantLock, java.util.stream.Collectors, jdk.internal.net.http.common.Deadline, .FlowTube, .Log, .Logger, .TimeLine, .TimeSource, .Utils

Http 1.1 connection pool.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ConnectionPool.CacheKey

Entries in connection pool are keyed by destination address and/or proxy address: case 1: plain TCP not via proxy (destination IP only) case 2: plain TCP via proxy (proxy only) case 3: SSL not via proxy (destination IP+hostname only) case 4: SSL over tunnel (destination IP+hostname and proxy)

private class
ConnectionPool.CleanupTrigger

An object that subscribes to the flow while the connection is in the pool.

pack-priv static class
private static class
ConnectionPool.ExpiryList

Manages a LinkedList of sorted ExpiryEntry.

Field Summary

Modifier and TypeField and Description
private final String
pack-priv final Logger
private final ConnectionPool.ExpiryList
pack-priv static final long
private final HashMap<ConnectionPool.CacheKey, LinkedList<HttpConnection>>
private final HashMap<ConnectionPool.CacheKey, LinkedList<HttpConnection>>
private final ReentrantLock
pack-priv volatile boolean
private final TimeLine

Constructor Summary

AccessConstructor and Description
pack-priv
ConnectionPool(long clientId)

pack-priv
ConnectionPool(long clientId, TimeLine timeSource)

private
ConnectionPool(String tag, TimeLine timeSource)

There should be one of these per HttpClient.

Method Summary

Modifier and TypeMethod and Description
pack-priv static ConnectionPool.CacheKey
cacheKey(boolean secure, InetSocketAddress destination, InetSocketAddress proxy)

pack-priv void
cleanup(HttpConnection c, long pendingData, Throwable error)

private void
pack-priv boolean
private boolean
pack-priv final String
private HttpConnection
pack-priv HttpConnection
getConnection(boolean secure, InetSocketAddress addr, InetSocketAddress proxy)

private HttpConnection
getConnection0(boolean secure, InetSocketAddress addr, InetSocketAddress proxy)

pack-priv long

Returns:

the delay in milliseconds in which the next connection will expire.
purgeExpiredConnectionsAndReturnNextDeadline
()

Purge expired connection and return the number of milliseconds in which the next connection is scheduled to expire.

pack-priv long
private void
private ConnectionPool.CleanupTrigger
private boolean
private boolean
pack-priv void
returnToPool(HttpConnection conn)

Returns the connection to the pool.

pack-priv void
returnToPool(HttpConnection conn, Deadline now, long keepAlive)

pack-priv void
pack-priv void
stop()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dbgTagback to summary
private final String dbgTag
debugback to summary
pack-priv final Logger debug
expiryListback to summary
private final ConnectionPool.ExpiryList expiryList
MAX_POOL_SIZEback to summary
pack-priv static final long MAX_POOL_SIZE
plainPoolback to summary
private final HashMap<ConnectionPool.CacheKey, LinkedList<HttpConnection>> plainPool
sslPoolback to summary
private final HashMap<ConnectionPool.CacheKey, LinkedList<HttpConnection>> sslPool
stateLockback to summary
private final ReentrantLock stateLock
stoppedback to summary
pack-priv volatile boolean stopped
timeSourceback to summary
private final TimeLine timeSource

Constructor Detail

ConnectionPoolback to summary
pack-priv ConnectionPool(long clientId)
ConnectionPoolback to summary
pack-priv ConnectionPool(long clientId, TimeLine timeSource)
ConnectionPoolback to summary
private ConnectionPool(String tag, TimeLine timeSource)

There should be one of these per HttpClient.

Method Detail

cacheKeyback to summary
pack-priv static ConnectionPool.CacheKey cacheKey(boolean secure, InetSocketAddress destination, InetSocketAddress proxy)
cleanupback to summary
pack-priv void cleanup(HttpConnection c, long pendingData, Throwable error)
closeback to summary
private void close(HttpConnection c)
containsback to summary
pack-priv boolean contains(HttpConnection c)
contains0back to summary
private boolean contains0(HttpConnection c)
dbgStringback to summary
pack-priv final String dbgString()
findConnectionback to summary
private HttpConnection findConnection(ConnectionPool.CacheKey key, HashMap<ConnectionPool.CacheKey, LinkedList<HttpConnection>> pool)
getConnectionback to summary
pack-priv HttpConnection getConnection(boolean secure, InetSocketAddress addr, InetSocketAddress proxy)
getConnection0back to summary
private HttpConnection getConnection0(boolean secure, InetSocketAddress addr, InetSocketAddress proxy)
purgeExpiredConnectionsAndReturnNextDeadlineback to summary
pack-priv long purgeExpiredConnectionsAndReturnNextDeadline()

Purge expired connection and return the number of milliseconds in which the next connection is scheduled to expire. If no connections are scheduled to be purged return 0.

Returns:long

the delay in milliseconds in which the next connection will expire.

purgeExpiredConnectionsAndReturnNextDeadlineback to summary
pack-priv long purgeExpiredConnectionsAndReturnNextDeadline(Deadline now)
putConnectionback to summary
private void putConnection(HttpConnection c, HashMap<ConnectionPool.CacheKey, LinkedList<HttpConnection>> pool)
registerCleanupTriggerback to summary
private ConnectionPool.CleanupTrigger registerCleanupTrigger(HttpConnection conn)
removeFromPoolback to summary
private boolean removeFromPool(HttpConnection c, HashMap<ConnectionPool.CacheKey, LinkedList<HttpConnection>> pool)
removeFromPoolback to summary
private boolean removeFromPool(HttpConnection c)
returnToPoolback to summary
pack-priv void returnToPool(HttpConnection conn)

Returns the connection to the pool.

returnToPoolback to summary
pack-priv void returnToPool(HttpConnection conn, Deadline now, long keepAlive)
startback to summary
pack-priv void start()
stopback to summary
pack-priv void stop()
jdk.internal.net.http back to summary

pack-priv Class ConnectionPool.CacheKey

extends Object
Class Inheritance

Entries in connection pool are keyed by destination address and/or proxy address: case 1: plain TCP not via proxy (destination IP only) case 2: plain TCP via proxy (proxy only) case 3: SSL not via proxy (destination IP+hostname only) case 4: SSL over tunnel (destination IP+hostname and proxy)

Field Summary

Modifier and TypeField and Description
pack-priv final InetSocketAddress
pack-priv final InetSocketAddress
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
private
CacheKey(boolean secure, InetSocketAddress destination, InetSocketAddress proxy)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

destinationback to summary
pack-priv final InetSocketAddress destination
proxyback to summary
pack-priv final InetSocketAddress proxy
secureback to summary
pack-priv final boolean secure

Constructor Detail

CacheKeyback to summary
private CacheKey(boolean secure, InetSocketAddress destination, InetSocketAddress proxy)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
jdk.internal.net.http back to summary

private final Class ConnectionPool.CleanupTrigger

extends Object
implements TubeSubscriber, TubePublisher, Subscription
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Flow.Subscription, jdk.internal.net.http.common.FlowTube.TubePublisher, java.util.concurrent.Flow.Publisher, jdk.internal.net.http.common.FlowTube.TubeSubscriber, java.util.concurrent.Flow.Subscriber

An object that subscribes to the flow while the connection is in the pool. Anything that comes in will cause the connection to be closed and removed from the pool.

Field Summary

Modifier and TypeField and Description
private final HttpConnection
private volatile boolean
private volatile boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages.

public void
dropSubscription()

Overrides default jdk.internal.net.http.common.FlowTube.TubeSubscriber.dropSubscription.

Called when the flow is connected again, and the subscription is handed over to a new subscriber.

public boolean
public void
onComplete()

Implements java.util.concurrent.Flow.Subscriber.onComplete.

Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription.

public void
onError(Throwable error)

Implements java.util.concurrent.Flow.Subscriber.onError.

Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription.

public void
onNext(List<ByteBuffer> item)

Implements java.util.concurrent.Flow.Subscriber.onNext.

Method invoked with a Subscription's next item.

public void
onSubscribe(Flow.Subscription subscription)

Implements java.util.concurrent.Flow.Subscriber.onSubscribe.

Method invoked prior to invoking any other Subscriber methods for the given Subscription.

public void
request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription.

public void
subscribe(Flow.Subscriber<? super List<ByteBuffer>> subscriber)

Implements java.util.concurrent.Flow.Publisher.subscribe.

Adds the given Subscriber if possible.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
triggerCleanup(long pendingData, Throwable error)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

connectionback to summary
private final HttpConnection connection
doneback to summary
private volatile boolean done
droppedback to summary
private volatile boolean dropped

Constructor Detail

CleanupTriggerback to summary
public CleanupTrigger(HttpConnection connection)

Method Detail

cancelback to summary
public void cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Doc from java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages. Implementation is best-effort -- additional messages may be received after invoking this method. A cancelled subscription need not ever receive an onComplete or onError signal.

Annotations
@Override
dropSubscriptionback to summary
public void dropSubscription()

Overrides default jdk.internal.net.http.common.FlowTube.TubeSubscriber.dropSubscription.

Doc from jdk.internal.net.http.common.FlowTube.TubeSubscriber.dropSubscription.

Called when the flow is connected again, and the subscription is handed over to a new subscriber. Once dropSubscription() is called, the TubeSubscriber should stop calling any method on its subscription.

Annotations
@Override
isDoneback to summary
public boolean isDone()
onCompleteback to summary
public void onComplete()

Implements java.util.concurrent.Flow.Subscriber.onComplete.

Doc from java.util.concurrent.Flow.Subscriber.onComplete.

Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription. If this method throws an exception, resulting behavior is undefined.

Annotations
@Override
onErrorback to summary
public void onError(Throwable error)

Implements java.util.concurrent.Flow.Subscriber.onError.

Doc from java.util.concurrent.Flow.Subscriber.onError.

Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription. If this method itself throws an exception, resulting behavior is undefined.

Annotations
@Override
onNextback to summary
public void onNext(List<ByteBuffer> item)

Implements java.util.concurrent.Flow.Subscriber.onNext.

Doc from java.util.concurrent.Flow.Subscriber.onNext.

Method invoked with a Subscription's next item. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription to be cancelled.

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Flow.Subscription subscription)

Implements java.util.concurrent.Flow.Subscriber.onSubscribe.

Doc from java.util.concurrent.Flow.Subscriber.onSubscribe.

Method invoked prior to invoking any other Subscriber methods for the given Subscription. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription not to be established or to be cancelled.

Typically, implementations of this method invoke subscription.request to enable receiving items.

Annotations
@Override
requestback to summary
public void request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Doc from java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription. If n is less than or equal to zero, the Subscriber will receive an onError signal with an IllegalArgumentException argument. Otherwise, the Subscriber will receive up to n additional onNext invocations (or fewer if terminated).

Annotations
@Override
subscribeback to summary
public void subscribe(Flow.Subscriber<? super List<ByteBuffer>> subscriber)

Implements java.util.concurrent.Flow.Publisher.subscribe.

Doc from java.util.concurrent.Flow.Publisher.subscribe.

Adds the given Subscriber if possible. If already subscribed, or the attempt to subscribe fails due to policy violations or errors, the Subscriber's onError method is invoked with an IllegalStateException. Otherwise, the Subscriber's onSubscribe method is invoked with a new Subscription. Subscribers may enable receiving items by invoking the request method of this Subscription, and may unsubscribe by invoking its cancel method.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
triggerCleanupback to summary
private void triggerCleanup(long pendingData, Throwable error)
jdk.internal.net.http back to summary

pack-priv final Class ConnectionPool.ExpiryEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final HttpConnection
pack-priv final Deadline

Constructor Summary

AccessConstructor and Description
pack-priv
ExpiryEntry(HttpConnection connection, Deadline expiry)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
pack-priv final HttpConnection connection
expiryback to summary
pack-priv final Deadline expiry

Constructor Detail

ExpiryEntryback to summary
pack-priv ExpiryEntry(HttpConnection connection, Deadline expiry)
jdk.internal.net.http back to summary

private final Class ConnectionPool.ExpiryList

extends Object
Class Inheritance

Manages a LinkedList of sorted ExpiryEntry. The entry with the closer deadline is at the tail of the list, and the entry with the farther deadline is at the head. In the most common situation, new elements will need to be added at the head (or close to it), and expired elements will need to be purged from the tail.

Field Summary

Modifier and TypeField and Description
private final LinkedList<ConnectionPool.ExpiryEntry>
private volatile boolean
private final TimeLine

Constructor Summary

AccessConstructor and Description
pack-priv
ExpiryList(TimeLine timeSource)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
add(HttpConnection conn, Deadline now, long keepAlive)

pack-priv void
pack-priv Optional<Deadline>
pack-priv boolean
pack-priv List<HttpConnection>
pack-priv void
pack-priv HttpConnection
pack-priv int
size()

pack-priv Stream<ConnectionPool.ExpiryEntry>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

listback to summary
private final LinkedList<ConnectionPool.ExpiryEntry> list
mayContainEntriesback to summary
private volatile boolean mayContainEntries
timeSourceback to summary
private final TimeLine timeSource

Constructor Detail

ExpiryListback to summary
pack-priv ExpiryList(TimeLine timeSource)

Method Detail

addback to summary
pack-priv void add(HttpConnection conn)
addback to summary
pack-priv void add(HttpConnection conn, Deadline now, long keepAlive)
clearback to summary
pack-priv void clear()
nextExpiryDeadlineback to summary
pack-priv Optional<Deadline> nextExpiryDeadline()
purgeMaybeRequiredback to summary
pack-priv boolean purgeMaybeRequired()
purgeUntilback to summary
pack-priv List<HttpConnection> purgeUntil(Deadline now)
removeback to summary
pack-priv void remove(HttpConnection c)
removeOldestback to summary
pack-priv HttpConnection removeOldest()
sizeback to summary
pack-priv int size()
streamback to summary
pack-priv Stream<ConnectionPool.ExpiryEntry> stream()