Top Description Inners Fields Constructors Methods
io.undertow.server.handlers.proxy

public Class ProxyConnectionPool

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .IOException, java.net.InetSocketAddress, .URI, java.util.ArrayDeque, .Deque, .Map, java.util.concurrent.ConcurrentMap, .CountDownLatch, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, .AtomicLong, io.undertow.UndertowLogger, .UndertowMessages, io.undertow.client.ClientCallback, .ClientConnection, .ClientStatistics, .UndertowClient, io.undertow.server.ExchangeCompletionListener, .HttpServerExchange, io.undertow.util.CopyOnWriteMap, .Headers, .WorkerUtils, org.xnio.ChannelListener, .IoUtils, .OptionMap, .XnioExecutor, .XnioIoThread, org.xnio.ssl.XnioSsl

A pool of connections to a target host. This pool can also be used to open connections in exclusive mode, in which case they will not be added to the connection pool. In this case the caller is responsible for closing any connections.
Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
private static class
private static class
private class

Field Summary

Modifier and TypeField and Description
private final InetSocketAddress
private final UndertowClient
private volatile boolean
closed

Set to true when the connection pool is closed.

private final ConnectionPoolManager
private final int
coreCachedConnections

The minimum number of connections that this proxy connection pool will try and keep established.

private final ConcurrentMap<XnioIoThread, ProxyConnectionPool.HostThreadData>
private final int
maxCachedConnections

The maximum number of connections that will be kept alive once they are idle.

private final int
maxConnections

The maximum number of connections that can be established to the target

private final AtomicInteger
openConnections

The total number of open connections, across all threads

private final OptionMap
private final AtomicLong
read

read bytes for all closed connections

private final AtomicLong
requestCount

request count for all closed connections

private final XnioSsl
private final long
timeToLive

The timeout for idle connections.

private final URI
private final AtomicLong
written

written bytes for all closed connections

Constructor Summary

AccessConstructor and Description
public
ProxyConnectionPool(ConnectionPoolManager connectionPoolManager, URI uri, UndertowClient client, OptionMap options)

public
ProxyConnectionPool(ConnectionPoolManager connectionPoolManager, InetSocketAddress bindAddress, URI uri, UndertowClient client, OptionMap options)

public
ProxyConnectionPool(ConnectionPoolManager connectionPoolManager, URI uri, XnioSsl ssl, UndertowClient client, OptionMap options)

public
ProxyConnectionPool(ConnectionPoolManager connectionPoolManager, InetSocketAddress bindAddress, URI uri, XnioSsl ssl, UndertowClient client, OptionMap options)

Method Summary

Modifier and TypeMethod and Description
public ProxyConnectionPool.AvailabilityType
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

pack-priv void
closeCurrentConnections()

Should only be used for tests.

public void
connect(ProxyClient.ProxyTarget proxyTarget, HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, final long timeout, final TimeUnit timeUnit, boolean
- Is connection for the exclusive use of one client?
exclusive
)

private void
connectionReady(final ProxyConnectionPool.ConnectionHolder result, final ProxyCallback<ProxyConnection> callback, final HttpServerExchange exchange, final boolean exclusive)

public InetSocketAddress
public ClientStatistics
private ProxyConnectionPool.HostThreadData

Returns:

The data for this thread
getData
()

Gets the host data for this thread

public int

Returns:

The total number of open connections
getOpenConnections
()

public URI
private void
private void
openConnection(final HttpServerExchange exchange, final ProxyCallback<ProxyConnection> callback, final ProxyConnectionPool.HostThreadData data, final boolean exclusive)

private void
private void
returnConnection(final ProxyConnectionPool.ConnectionHolder
The client connection holder
connectionHolder
)

Called when the IO thread has completed a successful request

private void
scheduleFailedHostRetry(final HttpServerExchange
The server exchange
exchange
)

If a host fails we periodically retry

private void
timeoutConnections(final long
the current time
currentTime
,
final ProxyConnectionPool.HostThreadData
the local host thread data
data
)

Timeout idle connections which are above the soft max cached connections limit.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bindAddressback to summary
private final InetSocketAddress bindAddress
clientback to summary
private final UndertowClient client
closedback to summary
private volatile boolean closed

Set to true when the connection pool is closed.

connectionPoolManagerback to summary
private final ConnectionPoolManager connectionPoolManager
coreCachedConnectionsback to summary
private final int coreCachedConnections

The minimum number of connections that this proxy connection pool will try and keep established. Once the pool is down to this number of connections no more connections will be timed out.

Note

This value is per IO thread, so to get the actual value this must be multiplied by the number of IO threads

hostThreadDataback to summary
private final ConcurrentMap<XnioIoThread, ProxyConnectionPool.HostThreadData> hostThreadData
maxCachedConnectionsback to summary
private final int maxCachedConnections

The maximum number of connections that will be kept alive once they are idle. If a time to live is set these connections may be timed out, depending on the value of coreCachedConnections.

Note

This value is per IO thread, so to get the actual value this must be multiplied by the number of IO threads

maxConnectionsback to summary
private final int maxConnections

The maximum number of connections that can be established to the target

openConnectionsback to summary
private final AtomicInteger openConnections

The total number of open connections, across all threads

optionsback to summary
private final OptionMap options
readback to summary
private final AtomicLong read

read bytes for all closed connections

requestCountback to summary
private final AtomicLong requestCount

request count for all closed connections

sslback to summary
private final XnioSsl ssl
timeToLiveback to summary
private final long timeToLive

The timeout for idle connections. Note that if #coreCachedConnections is set then once the pool is down to the core size no more connections will be timed out.

uriback to summary
private final URI uri
writtenback to summary
private final AtomicLong written

written bytes for all closed connections

Constructor Detail

ProxyConnectionPoolback to summary
public ProxyConnectionPool(ConnectionPoolManager connectionPoolManager, URI uri, UndertowClient client, OptionMap options)
ProxyConnectionPoolback to summary
public ProxyConnectionPool(ConnectionPoolManager connectionPoolManager, InetSocketAddress bindAddress, URI uri, UndertowClient client, OptionMap options)
ProxyConnectionPoolback to summary
public ProxyConnectionPool(ConnectionPoolManager connectionPoolManager, URI uri, XnioSsl ssl, UndertowClient client, OptionMap options)
ProxyConnectionPoolback to summary
public ProxyConnectionPool(ConnectionPoolManager connectionPoolManager, InetSocketAddress bindAddress, URI uri, XnioSsl ssl, UndertowClient client, OptionMap options)

Method Detail

availableback to summary
public ProxyConnectionPool.AvailabilityType available()
closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

closeCurrentConnectionsback to summary
pack-priv void closeCurrentConnections()

Should only be used for tests.

connectback to summary
public void connect(ProxyClient.ProxyTarget proxyTarget, HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, final long timeout, final TimeUnit timeUnit, boolean exclusive)
Parameters
exclusive:boolean

- Is connection for the exclusive use of one client?

connectionReadyback to summary
private void connectionReady(final ProxyConnectionPool.ConnectionHolder result, final ProxyCallback<ProxyConnection> callback, final HttpServerExchange exchange, final boolean exclusive)
getBindAddressback to summary
public InetSocketAddress getBindAddress()
getClientStatisticsback to summary
public ClientStatistics getClientStatistics()
getDataback to summary
private ProxyConnectionPool.HostThreadData getData()

Gets the host data for this thread

Returns:ProxyConnectionPool.HostThreadData

The data for this thread

getOpenConnectionsback to summary
public int getOpenConnections()
Returns:int

The total number of open connections

getUriback to summary
public URI getUri()
handleClosedConnectionback to summary
private void handleClosedConnection(ProxyConnectionPool.HostThreadData hostData, final ProxyConnectionPool.ConnectionHolder connection)
openConnectionback to summary
private void openConnection(final HttpServerExchange exchange, final ProxyCallback<ProxyConnection> callback, final ProxyConnectionPool.HostThreadData data, final boolean exclusive)
redistributeQueuedback to summary
private void redistributeQueued(ProxyConnectionPool.HostThreadData hostData)
returnConnectionback to summary
private void returnConnection(final ProxyConnectionPool.ConnectionHolder connectionHolder)

Called when the IO thread has completed a successful request

Parameters
connectionHolder:ProxyConnectionPool.ConnectionHolder

The client connection holder

scheduleFailedHostRetryback to summary
private void scheduleFailedHostRetry(final HttpServerExchange exchange)

If a host fails we periodically retry

Parameters
exchange:HttpServerExchange

The server exchange

timeoutConnectionsback to summary
private void timeoutConnections(final long currentTime, final ProxyConnectionPool.HostThreadData data)

Timeout idle connections which are above the soft max cached connections limit.

Parameters
currentTime:long

the current time

data:ProxyConnectionPool.HostThreadData

the local host thread data

io.undertow.server.handlers.proxy back to summary

public final Enum ProxyConnectionPool.AvailabilityType

extends Enum<ProxyConnectionPool.AvailabilityType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final ProxyConnectionPool.AvailabilityType
AVAILABLE

The host is read to accept requests

public static final ProxyConnectionPool.AvailabilityType
CLOSED

The host is closed.

public static final ProxyConnectionPool.AvailabilityType
DRAIN

The host is stopped.

public static final ProxyConnectionPool.AvailabilityType
FULL

All connections are in use, connections will be queued

public static final ProxyConnectionPool.AvailabilityType
FULL_QUEUE

All connections are in use and the queue is full.

public static final ProxyConnectionPool.AvailabilityType
PROBLEM

The host is probably down, only try as a last resort

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ProxyConnectionPool.AvailabilityType
public static ProxyConnectionPool.AvailabilityType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AVAILABLEback to summary
public static final ProxyConnectionPool.AvailabilityType AVAILABLE

The host is read to accept requests

CLOSEDback to summary
public static final ProxyConnectionPool.AvailabilityType CLOSED

The host is closed. connections will always fail

DRAINback to summary
public static final ProxyConnectionPool.AvailabilityType DRAIN

The host is stopped. No request should be forwarded that are not tied to this node via sticky sessions

FULLback to summary
public static final ProxyConnectionPool.AvailabilityType FULL

All connections are in use, connections will be queued

FULL_QUEUEback to summary
public static final ProxyConnectionPool.AvailabilityType FULL_QUEUE

All connections are in use and the queue is full. Requests will be rejected.

PROBLEMback to summary
public static final ProxyConnectionPool.AvailabilityType PROBLEM

The host is probably down, only try as a last resort

Constructor Detail

AvailabilityTypeback to summary
private AvailabilityType()

Method Detail

valueOfback to summary
public static ProxyConnectionPool.AvailabilityType valueOf(String name)
valuesback to summary
public static ProxyConnectionPool.AvailabilityType[] values()
io.undertow.server.handlers.proxy back to summary

private final Class ProxyConnectionPool.CallbackHolder

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.proxy.ProxyConnectionPool.CallbackHolder
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
pack-priv final ProxyCallback<ProxyConnection>
pack-priv boolean
pack-priv final HttpServerExchange
pack-priv final long
pack-priv final ProxyClient.ProxyTarget
pack-priv XnioExecutor.Key

Constructor Summary

AccessConstructor and Description
private
CallbackHolder(ProxyClient.ProxyTarget proxyTarget, ProxyCallback<ProxyConnection> callback, HttpServerExchange exchange, long expireTime)

Method Summary

Modifier and TypeMethod and Description
private ProxyCallback<ProxyConnection>
private HttpServerExchange
private long
public ProxyClient.ProxyTarget
private XnioExecutor.Key
private boolean
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callbackback to summary
pack-priv final ProxyCallback<ProxyConnection> callback
cancelledback to summary
pack-priv boolean cancelled
exchangeback to summary
pack-priv final HttpServerExchange exchange
expireTimeback to summary
pack-priv final long expireTime
proxyTargetback to summary
pack-priv final ProxyClient.ProxyTarget proxyTarget
timeoutKeyback to summary
pack-priv XnioExecutor.Key timeoutKey

Constructor Detail

CallbackHolderback to summary
private CallbackHolder(ProxyClient.ProxyTarget proxyTarget, ProxyCallback<ProxyConnection> callback, HttpServerExchange exchange, long expireTime)

Method Detail

getCallbackback to summary
private ProxyCallback<ProxyConnection> getCallback()
getExchangeback to summary
private HttpServerExchange getExchange()
getExpireTimeback to summary
private long getExpireTime()
getProxyTargetback to summary
public ProxyClient.ProxyTarget getProxyTarget()
getTimeoutKeyback to summary
private XnioExecutor.Key getTimeoutKey()
isCancelledback to summary
private boolean isCancelled()
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
setTimeoutKeyback to summary
private void setTimeoutKey(XnioExecutor.Key timeoutKey)
io.undertow.server.handlers.proxy back to summary

private final Class ProxyConnectionPool.ConnectionHolder

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.proxy.ProxyConnectionPool.ConnectionHolder

Field Summary

Modifier and TypeField and Description
private final ClientConnection
private long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

clientConnectionback to summary
private final ClientConnection clientConnection
timeoutback to summary
private long timeout

Constructor Detail

ConnectionHolderback to summary
private ConnectionHolder(ClientConnection clientConnection)
io.undertow.server.handlers.proxy back to summary

private final Class ProxyConnectionPool.HostThreadData

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.proxy.ProxyConnectionPool.HostThreadData

Field Summary

Modifier and TypeField and Description
pack-priv final Deque<ProxyConnectionPool.ConnectionHolder>
pack-priv final Deque<ProxyConnectionPool.CallbackHolder>
pack-priv int
pack-priv long
pack-priv XnioExecutor.Key
pack-priv final Runnable

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

availableConnectionsback to summary
pack-priv final Deque<ProxyConnectionPool.ConnectionHolder> availableConnections
awaitingConnectionsback to summary
pack-priv final Deque<ProxyConnectionPool.CallbackHolder> awaitingConnections
connectionsback to summary
pack-priv int connections
nextTimeoutback to summary
pack-priv long nextTimeout
timeoutKeyback to summary
pack-priv XnioExecutor.Key timeoutKey
timeoutTaskback to summary
pack-priv final Runnable timeoutTask

Constructor Detail

HostThreadDataback to summary
private HostThreadData()