Top Inners Fields Constructors Methods
org.eclipse.jetty.client

public abstract Class AbstractConnectionPool

extends ContainerLifeCycle
implements ConnectionPool, Dumpable, Sweepable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.thread.Sweeper.Sweepable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.client.ConnectionPool
Known Direct Subclasses
org.eclipse.jetty.client.DuplexConnectionPool, org.eclipse.jetty.client.MultiplexConnectionPool
Annotations
@ManagedObject
Imports
java.io.IOException, java.util.ArrayDeque, .ArrayList, .Collection, .List, .Objects, java.util.concurrent.CompletableFuture, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, java.util.stream.Collectors, org.eclipse.jetty.client.transport.HttpDestination, org.eclipse.jetty.util.Attachable, .IO, .NanoTime, .Pool, .Promise, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.component.ContainerLifeCycle, .Dumpable, org.eclipse.jetty.util.thread.Sweeper, org.slf4j.Logger, .LoggerFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class

Field Summary

Modifier and TypeField and Description
private final HttpDestination
private volatile int
private static final Logger
private volatile long
private boolean
private volatile int
private final AtomicInteger
private Pool<Connection>
private final Pool.Factory<Connection>

Constructor Summary

AccessConstructor and Description
protected
AbstractConnectionPool(Destination destination, Pool.Factory<Connection> poolFactory, int initialMaxMultiplex)

Method Summary

Modifier and TypeMethod and Description
public boolean
accept(Connection
the connection to accept
connection
)

Implements org.eclipse.jetty.client.ConnectionPool.accept.

Accepts the given connection to be managed by this ConnectionPool.

public Connection

Returns:

an idle connection or null if no idle connections are available
acquire
(boolean
a hint to attempt to open a new connection if no idle connections are available
create
)

Implements org.eclipse.jetty.client.ConnectionPool.acquire.

Returns an idle connection, if available; if an idle connection is not available, and the given create parameter is true or isMaximizeConnections() is true, then attempts to open a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise it attempts to open a new connection, if the number of queued requests is greater than the number of pending connections; if no connection is available even after the attempts to open, return null.

protected void
acquired(Connection connection)

protected Connection
private void
protected boolean
deactivate(Connection connection)

protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

protected void
doStop()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.

public int
pack-priv Collection<Connection>
public int
public int
pack-priv Collection<Connection>
protected int
public int
public long

Returns:

the max usage duration, in milliseconds, of a pooled connection
getMaxDuration
()

Returns the max usage duration in milliseconds of a pooled connection.

public int

Returns:

the max number of times a pooled connection can be used
getMaxUsage
()

Returns the max number of times a pooled connection can be used.

public int
protected boolean
idle(Connection connection, boolean close)

public boolean
isActive(Connection
the connection to test
connection
)

Implements org.eclipse.jetty.client.ConnectionPool.isActive.

public boolean
public boolean
protected void
onCreated(Connection connection)

public CompletableFuture<Void>
preCreateConnections(int
the number of connections to pre-start.
connectionCount
)

Overrides default org.eclipse.jetty.client.ConnectionPool.preCreateConnections.

Optionally pre-create up to connectionCount connections so they are immediately ready for use.

protected void
public boolean
release(Connection
the connection to release
connection
)

Implements org.eclipse.jetty.client.ConnectionPool.release.

Returns the given connection, previously obtained via acquire(boolean), back to this ConnectionPool.

protected void
released(Connection connection)

public boolean
remove(Connection
the connection to remove
connection
)

Implements org.eclipse.jetty.client.ConnectionPool.remove.

Removes the given connection from this ConnectionPool.

protected void
removed(Connection connection)

protected void
setInitialMaxMultiplex(int initialMaxMultiplex)

public void
setMaxDuration(long maxDurationInMs)

public void
setMaximizeConnections(boolean
whether the number of connections should be maximized
maximizeConnections
)

Sets whether the number of connections should be maximized.

public void
setMaxUsage(int maxUsage)

public boolean
public String
toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Returns a string representation of the object.

protected void
tryCreate(boolean
a hint to request to create a connection
create
)

Tries to create a new connection.

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans

Field Detail

destinationback to summary
private final HttpDestination destination
initialMaxMultiplexback to summary
private volatile int initialMaxMultiplex
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.ContainerLifeCycle.LOG.

maxDurationNanosback to summary
private volatile long maxDurationNanos
maximizeConnectionsback to summary
private boolean maximizeConnections
maxUsageback to summary
private volatile int maxUsage
pendingback to summary
private final AtomicInteger pending
poolback to summary
private Pool<Connection> pool
poolFactoryback to summary
private final Pool.Factory<Connection> poolFactory

Constructor Detail

AbstractConnectionPoolback to summary
protected AbstractConnectionPool(Destination destination, Pool.Factory<Connection> poolFactory, int initialMaxMultiplex)

Method Detail

acceptback to summary
public boolean accept(Connection connection)

Implements org.eclipse.jetty.client.ConnectionPool.accept.

Doc from org.eclipse.jetty.client.ConnectionPool.accept.

Accepts the given connection to be managed by this ConnectionPool.

Parameters
connection:Connection

the connection to accept

Returns:boolean

whether the connection has been accepted

Annotations
@Override
acquireback to summary
public Connection acquire(boolean create)

Implements org.eclipse.jetty.client.ConnectionPool.acquire.

Returns an idle connection, if available; if an idle connection is not available, and the given create parameter is true or isMaximizeConnections() is true, then attempts to open a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise it attempts to open a new connection, if the number of queued requests is greater than the number of pending connections; if no connection is available even after the attempts to open, return null.

The create parameter is just a hint: the connection may be created even if false, or may not be created even if true.

Parameters
create:boolean

a hint to attempt to open a new connection if no idle connections are available

Returns:Connection

an idle connection or null if no idle connections are available

Annotations
@Override
See Also
tryCreate(boolean)
acquiredback to summary
protected void acquired(Connection connection)
activateback to summary
protected Connection activate()
closeback to summary
private void close(Pool.Entry<Connection> entry)
deactivateback to summary
protected boolean deactivate(Connection connection)
doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

If there was a problem starting. Will cause a transition to FAILED state

doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

If there was a problem stopping. Will cause a transition to FAILED state

dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
getActiveConnectionCountback to summary
public int getActiveConnectionCount()
Annotations
@ManagedAttribute:The number of active connections
readonly:true
getActiveConnectionsback to summary
pack-priv Collection<Connection> getActiveConnections()
getConnectionCountback to summary
public int getConnectionCount()
Annotations
@ManagedAttribute:The number of connections
readonly:true
getIdleConnectionCountback to summary
public int getIdleConnectionCount()
Annotations
@ManagedAttribute:The number of idle connections
readonly:true
getIdleConnectionsback to summary
pack-priv Collection<Connection> getIdleConnections()
getInitialMaxMultiplexback to summary
protected int getInitialMaxMultiplex()
getMaxConnectionCountback to summary
public int getMaxConnectionCount()
Annotations
@ManagedAttribute:The max number of connections
readonly:true
getMaxDurationback to summary
public long getMaxDuration()

Returns the max usage duration in milliseconds of a pooled connection.

Values 0 and negative mean that there is no limit.

This property only guarantees that a connection cannot be acquired after the configured duration elapses, so that is only enforced when acquire(boolean) is called.

If a pool stays completely idle for a duration longer than the value returned by this method, the max duration will not be enforced. It's up to the idle timeout mechanism (see HttpClient#getIdleTimeout()) to handle closing idle connections.

Returns:long

the max usage duration, in milliseconds, of a pooled connection

Annotations
@ManagedAttribute:The maximum duration in milliseconds a connection can be used for before it gets closed
getMaxUsageback to summary
public int getMaxUsage()

Returns the max number of times a pooled connection can be used.

Values 0 and negative mean that there is no limit.

Returns:int

the max number of times a pooled connection can be used

Annotations
@ManagedAttribute:The maximum amount of times a connection is used before it gets closed
getPendingConnectionCountback to summary
public int getPendingConnectionCount()
Annotations
@ManagedAttribute:The number of pending connections
readonly:true
idleback to summary
protected boolean idle(Connection connection, boolean close)
isActiveback to summary
public boolean isActive(Connection connection)

Implements org.eclipse.jetty.client.ConnectionPool.isActive.

Parameters
connection:Connection

Doc from org.eclipse.jetty.client.ConnectionPool.isActive.

the connection to test

Returns:boolean

Doc from org.eclipse.jetty.client.ConnectionPool.isActive.

whether the given connection is currently in use

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements org.eclipse.jetty.client.ConnectionPool.isEmpty.

Returns:boolean

Doc from org.eclipse.jetty.client.ConnectionPool.isEmpty.

whether this ConnectionPool has no open connections

Annotations
@Override
isMaximizeConnectionsback to summary
public boolean isMaximizeConnections()
Annotations
@ManagedAttribute:Whether the pool tries to maximize the number of connections used
onCreatedback to summary
protected void onCreated(Connection connection)
preCreateConnectionsback to summary
public CompletableFuture<Void> preCreateConnections(int connectionCount)

Overrides default org.eclipse.jetty.client.ConnectionPool.preCreateConnections.

Doc from org.eclipse.jetty.client.ConnectionPool.preCreateConnections.

Optionally pre-create up to connectionCount connections so they are immediately ready for use.

Parameters
connectionCount:int

the number of connections to pre-start.

Annotations
@Override
proceedback to summary
protected void proceed()
releaseback to summary
public boolean release(Connection connection)

Implements org.eclipse.jetty.client.ConnectionPool.release.

Doc from org.eclipse.jetty.client.ConnectionPool.release.

Returns the given connection, previously obtained via acquire(boolean), back to this ConnectionPool.

Parameters
connection:Connection

the connection to release

Returns:boolean

true if the connection has been released, false if the connection should be closed

Annotations
@Override
releasedback to summary
protected void released(Connection connection)
removeback to summary
public boolean remove(Connection connection)

Implements org.eclipse.jetty.client.ConnectionPool.remove.

Doc from org.eclipse.jetty.client.ConnectionPool.remove.

Removes the given connection from this ConnectionPool.

Parameters
connection:Connection

the connection to remove

Returns:boolean

true if the connection was removed from this ConnectionPool

Annotations
@Override
removedback to summary
protected void removed(Connection connection)
setInitialMaxMultiplexback to summary
protected void setInitialMaxMultiplex(int initialMaxMultiplex)
setMaxDurationback to summary
public void setMaxDuration(long maxDurationInMs)
setMaximizeConnectionsback to summary
public void setMaximizeConnections(boolean maximizeConnections)

Sets whether the number of connections should be maximized.

Parameters
maximizeConnections:boolean

whether the number of connections should be maximized

setMaxUsageback to summary
public void setMaxUsage(int maxUsage)
sweepback to summary
public boolean sweep()

Implements org.eclipse.jetty.util.thread.Sweeper.Sweepable.sweep.

Returns:boolean

Doc from org.eclipse.jetty.util.thread.Sweeper.Sweepable.sweep.

whether this resource should be swept

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.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.

Returns:String

a string representation of the object

Annotations
@Override
tryCreateback to summary
protected void tryCreate(boolean create)

Tries to create a new connection.

Whether a new connection is created is determined by the create parameter and a count of demand and supply, where the demand is derived from the number of queued requests, and the supply is the number of pending connections time the getInitialMaxMultiplex() factor: if the demand is less than the supply, the connection will not be created.

Since the number of queued requests used to derive the demand may be a stale value, it is possible that few more connections than strictly necessary may be created, but enough to satisfy the demand.

Parameters
create:boolean

a hint to request to create a connection

org.eclipse.jetty.client back to summary

private Class AbstractConnectionPool.EntryHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long
private final Pool.Entry<Connection>
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private boolean
isExpired(long timeoutNanos)

public boolean
isOverUsed(int maxUsage)

private boolean
use(int maxUsage)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

creationNanoTimeback to summary
private final long creationNanoTime
entryback to summary
private final Pool.Entry<Connection> entry
usageback to summary
private final AtomicInteger usage

Constructor Detail

EntryHolderback to summary
private EntryHolder(Pool.Entry<Connection> entry)

Method Detail

isExpiredback to summary
private boolean isExpired(long timeoutNanos)
isOverUsedback to summary
public boolean isOverUsed(int maxUsage)
useback to summary
private boolean use(int maxUsage)
org.eclipse.jetty.client back to summary

private Class AbstractConnectionPool.FutureConnection

extends Promise.Completable<Connection>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Pool.Entry<Connection>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
failed(Throwable
the reason for the operation failure
x
)

Overrides org.eclipse.jetty.util.Promise.Completable.failed.

Overrides default org.eclipse.jetty.util.Promise.failed.

Callback invoked when the operation fails.

public void
succeeded(Connection
the context
connection
)

Overrides org.eclipse.jetty.util.Promise.Completable.succeeded.

Overrides default org.eclipse.jetty.util.Promise.succeeded.

Callback invoked when the operation completes.

Inherited from org.eclipse.jetty.util.Promise.Completable:
with

Field Detail

reservedback to summary
private final Pool.Entry<Connection> reserved

Constructor Detail

FutureConnectionback to summary
public FutureConnection(Pool.Entry<Connection> reserved)

Method Detail

failedback to summary
public void failed(Throwable x)

Overrides org.eclipse.jetty.util.Promise.Completable.failed.

Overrides default org.eclipse.jetty.util.Promise.failed.

Doc from org.eclipse.jetty.util.Promise.failed.

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

Annotations
@Override
succeededback to summary
public void succeeded(Connection connection)

Overrides org.eclipse.jetty.util.Promise.Completable.succeeded.

Overrides default org.eclipse.jetty.util.Promise.succeeded.

Doc from org.eclipse.jetty.util.Promise.succeeded.

Callback invoked when the operation completes.

Parameters
connection:Connection

the context

Annotations
@Override