Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


com.tangosol.net
Class LoadBalancer

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.net.LoadBalancer

All Implemented Interfaces:
java.lang.Runnable

public class LoadBalancer
extends Base
implements java.lang.Runnable

A non-sticky HTTP load-balancer.

Version:
1.0, 2002-07-29
Author:
Cameron Purdy

Nested Class Summary
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.

 

Field Summary
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  java.util.List m_listHandler
          The list of RequestHandler daemons.
protected  java.util.Properties m_propOptions
          The optional settings that the load balancer will use.
protected  LoadBalancer.Queue m_queue
          The queue of pending requests.
protected  java.util.Random m_random
          Random number generator.
protected  java.lang.Thread m_threadRunning
          The Thread that the load balancer is started on.

 

Constructor Summary
LoadBalancer(LoadBalancer.AddressPort addrportHost, LoadBalancer.AddressPort[] aAddrPortDest, java.util.Properties propOptions)
          Instantiate a LoadBalancer object that will listen on a host address/port and redirect requests to destination addresses/ports.

 

Method Summary
 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.
 java.net.Socket getNextDestinationSocket()
          Open a socket to route to.
 boolean getProperty(java.lang.String sName, boolean fDefault)
          Determine the value of a boolean option.
 int getProperty(java.lang.String sName, int nDefault)
          Determine the value of an integer option.
 java.lang.String getProperty(java.lang.String sName, java.lang.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(java.lang.String[] asArgs)
          Command-line capability to start the load balancer.
protected static java.lang.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.

 

Field Detail

m_addrportHost

protected LoadBalancer.AddressPort m_addrportHost
The AddressPort combination that the load balancer will listen on.

m_aAddrPortDest

protected LoadBalancer.AddressPort[] m_aAddrPortDest
The AddressPort combinations that the load balancer will balance to.

m_propOptions

protected java.util.Properties m_propOptions
The optional settings that the load balancer will use.

m_threadRunning

protected java.lang.Thread m_threadRunning
The Thread that the load balancer is started on.

m_queue

protected LoadBalancer.Queue m_queue
The queue of pending requests.

m_listHandler

protected java.util.List m_listHandler
The list of RequestHandler daemons.

m_fRoundRobin

protected boolean m_fRoundRobin
Toggles between random and round-robin load balancing.

m_random

protected java.util.Random m_random
Random number generator.

m_iNextDestination

protected int m_iNextDestination
Round-robin index.

Constructor Detail

LoadBalancer

public LoadBalancer(LoadBalancer.AddressPort addrportHost,
                    LoadBalancer.AddressPort[] aAddrPortDest,
                    java.util.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 host
aAddrPortDest - the array of AddressPort combinations that requests will be sent to

Method Detail

main

public static void main(java.lang.String[] asArgs)
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.
Specified by:
run in interface java.lang.Runnable
See Also:
Thread.run()

getHost

public LoadBalancer.AddressPort 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

public LoadBalancer.AddressPort getDestination(int i)
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

public java.net.Socket getNextDestinationSocket()
Open a socket to route to.
Returns:
the next available Socket to route a request to

getNextDestination

protected LoadBalancer.AddressPort getNextDestination()
Determine the next AddressPort combination to route to.
Returns:
the next AddressPort combination to route a request to

getRandomDestination

protected LoadBalancer.AddressPort getRandomDestination()
Determine a random AddressPort combination to route to.
Returns:
a random AddressPort combination to route a request to

getRoundRobinDestination

protected LoadBalancer.AddressPort 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

protected LoadBalancer.Queue getQueue()
Determine the Queue that Socket connections are placed into.
Returns:
the Queue of Socket objects that have been accepted

getProperty

public java.lang.String getProperty(java.lang.String sName,
                                    java.lang.String sDefault)
Determine the value of a String option.
Parameters:
sName - the property name that specifies the option to look up
sDefault - 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

public int getProperty(java.lang.String sName,
                       int nDefault)
Determine the value of an integer option.
Parameters:
sName - the property name that specifies the option to look up
nDefault - 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

public boolean getProperty(java.lang.String sName,
                           boolean fDefault)
Determine the value of a boolean option.
Parameters:
sName - the property name that specifies the option to look up
fDefault - 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

protected static java.lang.String parseThreadExtension(Daemon daemon)
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

protected LoadBalancer.Queue instantiateQueue()
Factory method: Create a queue.
Returns:
a Queue instance

instantiateRequestHandler

protected LoadBalancer.RequestHandler instantiateRequestHandler(LoadBalancer.Queue queue)
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

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.