com.edustructures.sifworks.tools
Class LoadBalancer

java.lang.Object
  extended by com.edustructures.sifworks.tools.LoadBalancer

public class LoadBalancer
extends java.lang.Object

A LoadBalancer manages a free pool of Baton objects representing the right of a thread to perform a resource-intensive task. For example, you could create a LoadBalancer that represents the task "query all students" and assign it an initial pool of 5 Batons, meaning at most 5 threads will be able to carry out this task at once. A thread must check out a Baton in order to perform the task, and must release it back to the LoadBalancer when finished.

Refer to the Baton class for a description of how to use the LoadBalancer and Baton classes and the LoadBalancerListener interface. These classes can be used to introduce internal load balancing into an agent to significantly improve scalability when connecting to tens or hundreds of zones concurrently.

Version:
ADK 1.0

Field Summary
static boolean TRACE
           
 
Constructor Summary
LoadBalancer(java.lang.Object id, int batons, long timeout)
          Constructs a LoadBalancer to represent a specific logical task.
 
Method Summary
 void addLoadBalancerListener(LoadBalancerListener listener)
          Register a LoadBalancerListener with this LoadBalancer.
 void checkinBaton(Baton baton)
          Check-in a Baton.
 Baton checkoutBaton()
          Check-out a Baton.
static void define(LoadBalancer balancer)
          Define a LoadBalancer that may be subsequently returned by the lookup method.
 int getFreeBatons()
          Gets the number of Batons
 int getLoad()
          Gets the current load (the number of Batons in use)
 int getTotalBatons()
          Gets the total number of Batons
static LoadBalancer lookup(java.lang.Object id)
          Lookup a LoadBalancer that was previously defined by the define method.
 void removeLoadBalancerListener(LoadBalancerListener listener)
          Remove a LoadBalancerListener previously registered with the addLoadBalancerListener method
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACE

public static boolean TRACE
Constructor Detail

LoadBalancer

public LoadBalancer(java.lang.Object id,
                    int batons,
                    long timeout)
Constructs a LoadBalancer to represent a specific logical task.

Parameters:
id - A unique arbitrary ID that the agent will use to request this LoadBalancer (e.g. "Request_StudentPersonal")
batons - The number of Batons that will be available to threads
timeout - The timeout period (in milliseconds) applied to the checkoutBaton method. The timeout period should be less than the HTTP or other transport timeout period so that the connection to the ZIS does not timeout before the load balancer does.
Method Detail

define

public static void define(LoadBalancer balancer)
Define a LoadBalancer that may be subsequently returned by the lookup method.

Parameters:
balancer - A LoadBalancer instance

lookup

public static LoadBalancer lookup(java.lang.Object id)
Lookup a LoadBalancer that was previously defined by the define method.

Parameters:
id - The ID of the LoadBalancer to obtain
Returns:
The LoadBalancer or null if no LoadBalancer with this id has been previously defined by the define method

checkoutBaton

public Baton checkoutBaton()
Check-out a Baton.


checkinBaton

public void checkinBaton(Baton baton)
Check-in a Baton.


getLoad

public int getLoad()
Gets the current load (the number of Batons in use)


getTotalBatons

public int getTotalBatons()
Gets the total number of Batons


getFreeBatons

public int getFreeBatons()
Gets the number of Batons


addLoadBalancerListener

public void addLoadBalancerListener(LoadBalancerListener listener)
Register a LoadBalancerListener with this LoadBalancer. The listener will be called when the free pool is empty and subsequently contains at least two Batons (or one Baton if this LoadBalancer was defined to have a pool size of one).


removeLoadBalancerListener

public void removeLoadBalancerListener(LoadBalancerListener listener)
Remove a LoadBalancerListener previously registered with the addLoadBalancerListener method



Copyright © 2001-2007 Edustructures LLC. All Rights Reserved. SIFWorks® and ADK® are registered trademarks of Edustructures LLC. SIF™ and Schools Interoperability Framework are trademarks of the Schools Interoperability Framework Association.