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

public Class LoadBalancingProxyClient

extends Object
implements ProxyClient
Class Inheritance
All Implemented Interfaces
io.undertow.server.handlers.proxy.ProxyClient
Imports
io.undertow.UndertowLogger, io.undertow.client.ClientConnection, .UndertowClient, io.undertow.server.HttpServerExchange, .ServerConnection, io.undertow.server.handlers.Cookie, io.undertow.util.AttachmentKey, .AttachmentList, .CopyOnWriteMap, org.xnio.OptionMap, org.xnio.ssl.XnioSsl, java.net.InetSocketAddress, .URI, java.util.Iterator, .Map, .Set, .ArrayList, .List, java.util.concurrent.CopyOnWriteArraySet, .TimeUnit, java.util.concurrent.atomic.AtomicInteger

Initial implementation of a load balancing proxy client. This initial implementation is rather simplistic, and will likely change.
Authors
Stuart Douglas, Richard Opalka

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public class
public static interface
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final AttachmentKey<AttachmentList<LoadBalancingProxyClient.Host>>
private final UndertowClient
private volatile int
connectionsPerThread

The number of connections to create per thread

private final AttachmentKey<LoadBalancingProxyClient.ExclusiveConnectionHolder>
exclusiveConnectionKey

The attachment key that is used to attach the proxy connection to the exchange.

private final ExclusivityChecker
private volatile LoadBalancingProxyClient.Host[]
hosts

The hosts list.

private final LoadBalancingProxyClient.HostSelector
private volatile int
private volatile int
problemServerRetry

Time in seconds between retries for problem servers

private static final ProxyClient.ProxyTarget
private RouteIteratorFactory
private final Map<String, LoadBalancingProxyClient.Host>
private final Set<String>
private volatile int
private volatile int

Constructor Summary

AccessConstructor and Description
public
public
public
public
public

Method Summary

Modifier and TypeMethod and Description
public synchronized LoadBalancingProxyClient
addHost(final URI host)

public synchronized LoadBalancingProxyClient
addHost(final URI host, XnioSsl ssl)

public synchronized LoadBalancingProxyClient
addHost(final URI host, String jvmRoute)

public synchronized LoadBalancingProxyClient
addHost(final URI host, String jvmRoute, XnioSsl ssl)

public synchronized LoadBalancingProxyClient
addHost(final URI host, String jvmRoute, XnioSsl ssl, OptionMap options)

public synchronized LoadBalancingProxyClient
addHost(final InetSocketAddress bindAddress, final URI host, String jvmRoute, XnioSsl ssl, OptionMap options)

public LoadBalancingProxyClient
addSessionCookieName(final String sessionCookieName)

public void
closeCurrentConnections()

Should only be used for tests DO NOT CALL THIS METHOD WHEN REQUESTS ARE IN PROGRESS It is not thread safe so internal state can get messed up.

public ProxyClient.ProxyTarget
findTarget(HttpServerExchange
The exchange
exchange
)

Implements io.undertow.server.handlers.proxy.ProxyClient.findTarget.

Finds a proxy target for this request, returning null if none can be found.

public List<ProxyClient.ProxyTarget>
public void
getConnection(ProxyClient.ProxyTarget target, HttpServerExchange
The exchange
exchange
,
final ProxyCallback<ProxyConnection>
The callback
callback
,
long
The timeout
timeout
,
TimeUnit
Time unit for the timeout
timeUnit
)

Implements io.undertow.server.handlers.proxy.ProxyClient.getConnection.

Gets a proxy connection for the given request.

public int
public int
public int
protected Iterator<CharSequence>
public synchronized LoadBalancingProxyClient
removeHost(final URI uri)

public LoadBalancingProxyClient
removeSessionCookieName(final String sessionCookieName)

protected LoadBalancingProxyClient.Host
public LoadBalancingProxyClient
setConnectionsPerThread(int connectionsPerThread)

public LoadBalancingProxyClient
setMaxQueueSize(int maxQueueSize)

public LoadBalancingProxyClient
setProblemServerRetry(int problemServerRetry)

public LoadBalancingProxyClient
setRankedRoutingDelimiter(String rankedRoutingDelimiter)

Configures ranked route delimiter, enabling ranked routing parsing strategy.

public LoadBalancingProxyClient
public LoadBalancingProxyClient
setSoftMaxConnectionsPerThread(int softMaxConnectionsPerThread)

public LoadBalancingProxyClient
setTtl(int ttl)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ATTEMPTED_HOSTSback to summary
private static final AttachmentKey<AttachmentList<LoadBalancingProxyClient.Host>> ATTEMPTED_HOSTS
clientback to summary
private final UndertowClient client
connectionsPerThreadback to summary
private volatile int connectionsPerThread

The number of connections to create per thread

exclusiveConnectionKeyback to summary
private final AttachmentKey<LoadBalancingProxyClient.ExclusiveConnectionHolder> exclusiveConnectionKey

The attachment key that is used to attach the proxy connection to the exchange.

This cannot be static as otherwise a connection from a different client could be re-used.

exclusivityCheckerback to summary
private final ExclusivityChecker exclusivityChecker
hostsback to summary
private volatile LoadBalancingProxyClient.Host[] hosts

The hosts list.

hostSelectorback to summary
private final LoadBalancingProxyClient.HostSelector hostSelector
maxQueueSizeback to summary
private volatile int maxQueueSize
problemServerRetryback to summary
private volatile int problemServerRetry

Time in seconds between retries for problem servers

PROXY_TARGETback to summary
private static final ProxyClient.ProxyTarget PROXY_TARGET
routeIteratorFactoryback to summary
private RouteIteratorFactory routeIteratorFactory
routesback to summary
private final Map<String, LoadBalancingProxyClient.Host> routes
sessionCookieNamesback to summary
private final Set<String> sessionCookieNames
softMaxConnectionsPerThreadback to summary
private volatile int softMaxConnectionsPerThread
ttlback to summary
private volatile int ttl

Constructor Detail

LoadBalancingProxyClientback to summary
public LoadBalancingProxyClient()
LoadBalancingProxyClientback to summary
public LoadBalancingProxyClient(UndertowClient client)
LoadBalancingProxyClientback to summary
public LoadBalancingProxyClient(ExclusivityChecker client)
LoadBalancingProxyClientback to summary
public LoadBalancingProxyClient(UndertowClient client, ExclusivityChecker exclusivityChecker)
LoadBalancingProxyClientback to summary
public LoadBalancingProxyClient(UndertowClient client, ExclusivityChecker exclusivityChecker, LoadBalancingProxyClient.HostSelector hostSelector)

Method Detail

addHostback to summary
public synchronized LoadBalancingProxyClient addHost(final URI host)
addHostback to summary
public synchronized LoadBalancingProxyClient addHost(final URI host, XnioSsl ssl)
addHostback to summary
public synchronized LoadBalancingProxyClient addHost(final URI host, String jvmRoute)
addHostback to summary
public synchronized LoadBalancingProxyClient addHost(final URI host, String jvmRoute, XnioSsl ssl)
addHostback to summary
public synchronized LoadBalancingProxyClient addHost(final URI host, String jvmRoute, XnioSsl ssl, OptionMap options)
addHostback to summary
public synchronized LoadBalancingProxyClient addHost(final InetSocketAddress bindAddress, final URI host, String jvmRoute, XnioSsl ssl, OptionMap options)
addSessionCookieNameback to summary
public LoadBalancingProxyClient addSessionCookieName(final String sessionCookieName)
closeCurrentConnectionsback to summary
public void closeCurrentConnections()

Should only be used for tests DO NOT CALL THIS METHOD WHEN REQUESTS ARE IN PROGRESS It is not thread safe so internal state can get messed up.

findTargetback to summary
public ProxyClient.ProxyTarget findTarget(HttpServerExchange exchange)

Implements io.undertow.server.handlers.proxy.ProxyClient.findTarget.

Doc from io.undertow.server.handlers.proxy.ProxyClient.findTarget.

Finds a proxy target for this request, returning null if none can be found. If this method returns null it means that there is no backend available to handle this request, and it should proceed as normal.

Parameters
exchange:HttpServerExchange

The exchange

Returns:ProxyClient.ProxyTarget

The proxy target

Annotations
@Override
getAllTargetsback to summary
public List<ProxyClient.ProxyTarget> getAllTargets()

Overrides default io.undertow.server.handlers.proxy.ProxyClient.getAllTargets.

Annotations
@Override
getConnectionback to summary
public void getConnection(ProxyClient.ProxyTarget target, HttpServerExchange exchange, final ProxyCallback<ProxyConnection> callback, long timeout, TimeUnit timeUnit)

Implements io.undertow.server.handlers.proxy.ProxyClient.getConnection.

Doc from io.undertow.server.handlers.proxy.ProxyClient.getConnection.

Gets a proxy connection for the given request.

Parameters
exchange:HttpServerExchange

The exchange

callback:ProxyCallback<ProxyConnection>

The callback

timeout:long

The timeout

timeUnit:TimeUnit

Time unit for the timeout

Annotations
@Override
getConnectionsPerThreadback to summary
public int getConnectionsPerThread()
getMaxQueueSizeback to summary
public int getMaxQueueSize()
getProblemServerRetryback to summary
public int getProblemServerRetry()
parseRoutesback to summary
protected Iterator<CharSequence> parseRoutes(HttpServerExchange exchange)
removeHostback to summary
public synchronized LoadBalancingProxyClient removeHost(final URI uri)
removeSessionCookieNameback to summary
public LoadBalancingProxyClient removeSessionCookieName(final String sessionCookieName)
selectHostback to summary
protected LoadBalancingProxyClient.Host selectHost(HttpServerExchange exchange)
setConnectionsPerThreadback to summary
public LoadBalancingProxyClient setConnectionsPerThread(int connectionsPerThread)
setMaxQueueSizeback to summary
public LoadBalancingProxyClient setMaxQueueSize(int maxQueueSize)
setProblemServerRetryback to summary
public LoadBalancingProxyClient setProblemServerRetry(int problemServerRetry)
setRankedRoutingDelimiterback to summary
public LoadBalancingProxyClient setRankedRoutingDelimiter(String rankedRoutingDelimiter)

Configures ranked route delimiter, enabling ranked routing parsing strategy.

setRouteParsingStrategyback to summary
public LoadBalancingProxyClient setRouteParsingStrategy(RouteParsingStrategy routeParsingStrategy)
setSoftMaxConnectionsPerThreadback to summary
public LoadBalancingProxyClient setSoftMaxConnectionsPerThread(int softMaxConnectionsPerThread)
setTtlback to summary
public LoadBalancingProxyClient setTtl(int ttl)
io.undertow.server.handlers.proxy back to summary

private Class LoadBalancingProxyClient.ExclusiveConnectionHolder

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.proxy.LoadBalancingProxyClient.ExclusiveConnectionHolder

Field Summary

Modifier and TypeField and Description
private ProxyConnection

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
private ProxyConnection connection

Constructor Detail

ExclusiveConnectionHolderback to summary
private ExclusiveConnectionHolder()
io.undertow.server.handlers.proxy back to summary

public final Class LoadBalancingProxyClient.Host

extends SimpleConnectionPoolErrorHandler
implements ConnectionPoolManager
Class Inheritance
All Implemented Interfaces
io.undertow.server.handlers.proxy.ConnectionPoolManager, io.undertow.server.handlers.proxy.ConnectionPoolErrorHandler, io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig

Field Summary

Modifier and TypeField and Description
pack-priv final ProxyConnectionPool
pack-priv final String
pack-priv final XnioSsl
pack-priv final URI

Constructor Summary

AccessConstructor and Description
private
Host(String jvmRoute, InetSocketAddress bindAddress, URI uri, XnioSsl ssl, OptionMap options)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public int
getMaxCachedConnections()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxCachedConnections.

Get the maximum number of cached (idle) connections per thread.

public int
getMaxConnections()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxConnections.

Get the maximum number of connections per thread.

public int
getMaxQueueSize()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxQueueSize.

Get the maximum number of requests which can be queued if there are no connections available.

public int
public int
getSMaxConnections()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getSMaxConnections.

Get number of cached connections above which are closed after the time to live.

public long
getTtl()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getTtl.

Get the time to live for idle connections.

public URI
Inherited from io.undertow.server.handlers.proxy.ConnectionPoolErrorHandler.SimpleConnectionPoolErrorHandler:
clearErrorhandleErrorisAvailable

Field Detail

connectionPoolback to summary
pack-priv final ProxyConnectionPool connectionPool
jvmRouteback to summary
pack-priv final String jvmRoute
sslback to summary
pack-priv final XnioSsl ssl
uriback to summary
pack-priv final URI uri

Constructor Detail

Hostback to summary
private Host(String jvmRoute, InetSocketAddress bindAddress, URI uri, XnioSsl ssl, OptionMap options)

Method Detail

closeCurrentConnectionsback to summary
pack-priv void closeCurrentConnections()
getMaxCachedConnectionsback to summary
public int getMaxCachedConnections()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxCachedConnections.

Doc from io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxCachedConnections.

Get the maximum number of cached (idle) connections per thread.

Annotations
@Override
getMaxConnectionsback to summary
public int getMaxConnections()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxConnections.

Doc from io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxConnections.

Get the maximum number of connections per thread.

Annotations
@Override
getMaxQueueSizeback to summary
public int getMaxQueueSize()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxQueueSize.

Doc from io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getMaxQueueSize.

Get the maximum number of requests which can be queued if there are no connections available.

Annotations
@Override
getProblemServerRetryback to summary
public int getProblemServerRetry()

Implements io.undertow.server.handlers.proxy.ConnectionPoolManager.getProblemServerRetry.

Returns:int

Doc from io.undertow.server.handlers.proxy.ConnectionPoolManager.getProblemServerRetry.

The amount of time that we should wait before re-testing a problem server

Annotations
@Override
getSMaxConnectionsback to summary
public int getSMaxConnections()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getSMaxConnections.

Doc from io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getSMaxConnections.

Get number of cached connections above which are closed after the time to live.

Annotations
@Override
getTtlback to summary
public long getTtl()

Implements io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getTtl.

Doc from io.undertow.server.handlers.proxy.ProxyConnectionPoolConfig.getTtl.

Get the time to live for idle connections.

Annotations
@Override
getUriback to summary
public URI getUri()
io.undertow.server.handlers.proxy back to summary

public Interface LoadBalancingProxyClient.HostSelector

Known Direct Implementers
io.undertow.server.handlers.proxy.LoadBalancingProxyClient.RoundRobinHostSelector

Method Summary

Modifier and TypeMethod and Description
public int

Method Detail

selectHostback to summary
public int selectHost(LoadBalancingProxyClient.Host[] availableHosts)
io.undertow.server.handlers.proxy back to summary

pack-priv Class LoadBalancingProxyClient.RoundRobinHostSelector

extends Object
implements HostSelector
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.proxy.LoadBalancingProxyClient.RoundRobinHostSelector
All Implemented Interfaces
io.undertow.server.handlers.proxy.LoadBalancingProxyClient.HostSelector

Field Summary

Modifier and TypeField and Description
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentHostback to summary
private final AtomicInteger currentHost

Constructor Detail

RoundRobinHostSelectorback to summary
pack-priv RoundRobinHostSelector()

Method Detail

selectHostback to summary
public int selectHost(LoadBalancingProxyClient.Host[] availableHosts)

Implements io.undertow.server.handlers.proxy.LoadBalancingProxyClient.HostSelector.selectHost.

Annotations
@Override