Modifier and Type | Class and Description |
---|---|
static class |
LoadBalancer.AddressPort
An AddressPort is an immutable combination of an IP address and a port
number.
|
static class |
LoadBalancer.Queue
A Queue is used to effeciently queue up items for daemon threads to
work on.
|
class |
LoadBalancer.RequestHandler
A RequestHandler is a daemon thread that processes a request from a
queue.
|
class |
LoadBalancer.ResponseHandler
A ResponseHandler is a daemon thread that processes an outgoing
response from a destination server.
|
static class |
LoadBalancer.SocketHandler
A SocketHandler is an abstract daemon thread.
|
Base.LoggingWriter, Base.StackFrame
Modifier and Type | Field and Description |
---|---|
protected LoadBalancer.AddressPort[] |
m_aAddrPortDest
The AddressPort combinations that the load balancer will balance to.
|
protected LoadBalancer.AddressPort |
m_addrportHost
The AddressPort combination that the load balancer will listen on.
|
protected boolean |
m_fRoundRobin
Toggles between random and round-robin load balancing.
|
protected int |
m_iNextDestination
Round-robin index.
|
protected List |
m_listHandler
The list of RequestHandler daemons.
|
protected Properties |
m_propOptions
The optional settings that the load balancer will use.
|
protected LoadBalancer.Queue |
m_queue
The queue of pending requests.
|
protected Random |
m_random
Random number generator.
|
protected Thread |
m_threadRunning
The Thread that the load balancer is started on.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
LoadBalancer.AddressPort |
getDestination(int i)
Determine one of the AddressPort combinations that the load balancer
balances requests to.
|
int |
getDestinationCount()
Determine the number of AddressPort combinations that the load balancer
balances requests to.
|
LoadBalancer.AddressPort |
getHost()
Determine the AddressPort that the load balancer listens on.
|
protected LoadBalancer.AddressPort |
getNextDestination()
Determine the next AddressPort combination to route to.
|
Socket |
getNextDestinationSocket()
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.
|
String |
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 |
getRandomDestination()
Determine a random AddressPort combination to route to.
|
protected LoadBalancer.AddressPort |
getRoundRobinDestination()
Using a round-robin algorithm, determine the next AddressPort
combination to route to.
|
protected LoadBalancer.Queue |
instantiateQueue()
Factory method: Create a queue.
|
protected LoadBalancer.RequestHandler |
instantiateRequestHandler(LoadBalancer.Queue queue)
Factory method: Create a RequestHandler.
|
protected LoadBalancer.ResponseHandler |
instantiateResponseHandler(LoadBalancer.RequestHandler daemonRequest)
Factory method: Create a ResponseHandler.
|
static void |
main(String[] asArgs)
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 |
showInstructions()
Display the instructions for the command-line utility.
|
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, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, 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
protected LoadBalancer.AddressPort m_addrportHost
protected LoadBalancer.AddressPort[] m_aAddrPortDest
protected Properties m_propOptions
protected Thread m_threadRunning
protected LoadBalancer.Queue m_queue
protected List m_listHandler
protected boolean m_fRoundRobin
protected Random m_random
protected int m_iNextDestination
public LoadBalancer(LoadBalancer.AddressPort addrportHost, LoadBalancer.AddressPort[] aAddrPortDest, Properties propOptions)
addrportHost
- the AddressPort combination for this hostaAddrPortDest
- the array of AddressPort combinations that
requests will be sent topublic static void main(String[] asArgs)
public static void showInstructions()
public LoadBalancer.AddressPort getHost()
public int getDestinationCount()
public LoadBalancer.AddressPort getDestination(int i)
i
- an index in the range 0 < i < getDesinationCount()public Socket getNextDestinationSocket()
protected LoadBalancer.AddressPort getNextDestination()
protected LoadBalancer.AddressPort getRandomDestination()
protected LoadBalancer.AddressPort getRoundRobinDestination()
protected LoadBalancer.Queue getQueue()
public String getProperty(String sName, String sDefault)
sName
- the property name that specifies the option to look upsDefault
- the default option value to use if the option is not
setpublic int getProperty(String sName, int nDefault)
sName
- the property name that specifies the option to look upnDefault
- the default option value to use if the option is not
setpublic boolean getProperty(String sName, boolean fDefault)
sName
- the property name that specifies the option to look upfDefault
- the default option value to use if the option is not
setprotected static String parseThreadExtension(Daemon daemon)
daemon
- a Daemon objectprotected LoadBalancer.Queue instantiateQueue()
protected LoadBalancer.RequestHandler instantiateRequestHandler(LoadBalancer.Queue queue)
queue
- a Queue of Socket objectsprotected LoadBalancer.ResponseHandler instantiateResponseHandler(LoadBalancer.RequestHandler daemonRequest)
daemonRequest
- the RequestHandler that the ResponseHandler will
belong to