Package com.tangosol.net
Class LoadBalancer
java.lang.Object
com.tangosol.util.Base
com.tangosol.net.LoadBalancer
- All Implemented Interfaces:
Runnable
A non-sticky HTTP load-balancer.
- Version:
- 1.0, 2002-07-29
- Author:
- Cameron Purdy
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An AddressPort is an immutable combination of an IP address and a port number.static class
A Queue is used to effeciently queue up items for daemon threads to work on.class
A RequestHandler is a daemon thread that processes a request from a queue.class
A ResponseHandler is a daemon thread that processes an outgoing response from a destination server.static class
A SocketHandler is an abstract daemon thread.Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionprotected LoadBalancer.AddressPort[]
The AddressPort combinations that the load balancer will balance to.protected LoadBalancer.AddressPort
The AddressPort combination that the load balancer will listen on.protected boolean
Toggles between random and round-robin load balancing.protected int
Round-robin index.protected List
The list of RequestHandler daemons.protected Properties
The optional settings that the load balancer will use.protected LoadBalancer.Queue
The queue of pending requests.protected Random
Random number generator.protected Thread
The Thread that the load balancer is started on. -
Constructor Summary
ConstructorDescriptionLoadBalancer
(LoadBalancer.AddressPort addrportHost, LoadBalancer.AddressPort[] aAddrPortDest, Properties propOptions) Instantiate a LoadBalancer object that will listen on a host address/port and redirect requests to destination addresses/ports. -
Method Summary
Modifier and TypeMethodDescriptiongetDestination
(int i) Determine one of the AddressPort combinations that the load balancer balances requests to.int
Determine the number of AddressPort combinations that the load balancer balances requests to.getHost()
Determine the AddressPort that the load balancer listens on.protected LoadBalancer.AddressPort
Determine the next AddressPort combination to route to.Open a socket to route to.boolean
getProperty
(String sName, boolean fDefault) Determine the value of a boolean option.int
getProperty
(String sName, int nDefault) Determine the value of an integer option.getProperty
(String sName, String sDefault) Determine the value of a String option.protected LoadBalancer.Queue
getQueue()
Determine the Queue that Socket connections are placed into.protected LoadBalancer.AddressPort
Determine a random AddressPort combination to route to.protected LoadBalancer.AddressPort
Using a round-robin algorithm, determine the next AddressPort combination to route to.protected LoadBalancer.Queue
Factory method: Create a queue.protected LoadBalancer.RequestHandler
Factory method: Create a RequestHandler.protected LoadBalancer.ResponseHandler
instantiateResponseHandler
(LoadBalancer.RequestHandler daemonRequest) Factory method: Create a ResponseHandler.static void
Command-line capability to start the load balancer.protected static String
parseThreadExtension
(Daemon daemon) Parse the extension glued onto the end of a daemon's thread's name.void
run()
Start the LoadBalancer.static void
Display the instructions for the command-line utility.Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Field Details
-
m_addrportHost
The AddressPort combination that the load balancer will listen on. -
m_aAddrPortDest
The AddressPort combinations that the load balancer will balance to. -
m_propOptions
The optional settings that the load balancer will use. -
m_threadRunning
The Thread that the load balancer is started on. -
m_queue
The queue of pending requests. -
m_listHandler
The list of RequestHandler daemons. -
m_fRoundRobin
protected boolean m_fRoundRobinToggles between random and round-robin load balancing. -
m_random
Random number generator. -
m_iNextDestination
protected int m_iNextDestinationRound-robin index.
-
-
Constructor Details
-
LoadBalancer
public LoadBalancer(LoadBalancer.AddressPort addrportHost, LoadBalancer.AddressPort[] aAddrPortDest, Properties propOptions) Instantiate a LoadBalancer object that will listen on a host address/port and redirect requests to destination addresses/ports.- Parameters:
addrportHost
- the AddressPort combination for this hostaAddrPortDest
- the array of AddressPort combinations that requests will be sent to
-
-
Method Details
-
main
Command-line capability to start the load balancer. -
showInstructions
public static void showInstructions()Display the instructions for the command-line utility. -
run
public void run()Start the LoadBalancer. -
getHost
Determine the AddressPort that the load balancer listens on.- Returns:
- the AddressPort that the load balancer listens on
-
getDestinationCount
public int getDestinationCount()Determine the number of AddressPort combinations that the load balancer balances requests to. -
getDestination
Determine one of the AddressPort combinations that the load balancer balances requests to. (Indexed property "Destination".)- Parameters:
i
- an index in the range 0 < i < getDesinationCount()- Returns:
- the AddressPort that the load balancer listens on
-
getNextDestinationSocket
Open a socket to route to.- Returns:
- the next available Socket to route a request to
-
getNextDestination
Determine the next AddressPort combination to route to.- Returns:
- the next AddressPort combination to route a request to
-
getRandomDestination
Determine a random AddressPort combination to route to.- Returns:
- a random AddressPort combination to route a request to
-
getRoundRobinDestination
Using a round-robin algorithm, determine the next AddressPort combination to route to.- Returns:
- the next AddressPort combination to route a request to
-
getQueue
Determine the Queue that Socket connections are placed into.- Returns:
- the Queue of Socket objects that have been accepted
-
getProperty
Determine the value of a String option.- Parameters:
sName
- the property name that specifies the option to look upsDefault
- the default option value to use if the option is not set- Returns:
- the value of the specified option, or the passed default value if the option is not set
-
getProperty
Determine the value of an integer option.- Parameters:
sName
- the property name that specifies the option to look upnDefault
- the default option value to use if the option is not set- Returns:
- the value of the specified option, or the passed default value if the option is not set
-
getProperty
Determine the value of a boolean option.- Parameters:
sName
- the property name that specifies the option to look upfDefault
- the default option value to use if the option is not set- Returns:
- the value of the specified option, or the passed default value if the option is not set
-
parseThreadExtension
Parse the extension glued onto the end of a daemon's thread's name.- Parameters:
daemon
- a Daemon object- Returns:
- the extension glued onto the end of a daemon's thread's name
-
instantiateQueue
Factory method: Create a queue.- Returns:
- a Queue instance
-
instantiateRequestHandler
Factory method: Create a RequestHandler.- Parameters:
queue
- a Queue of Socket objects- Returns:
- a RequestHandler instance
-
instantiateResponseHandler
protected LoadBalancer.ResponseHandler instantiateResponseHandler(LoadBalancer.RequestHandler daemonRequest) Factory method: Create a ResponseHandler.- Parameters:
daemonRequest
- the RequestHandler that the ResponseHandler will belong to- Returns:
- a ResponseHandler instance
-