Class SimpleServiceLoadBalancer<S extends Service,T extends ServiceLoad>

java.lang.Object
com.tangosol.util.Base
com.tangosol.net.AbstractServiceLoadBalancer<S,T>
com.tangosol.net.SimpleServiceLoadBalancer<S,T>
All Implemented Interfaces:
ServiceLoadBalancer<S,T>, Comparator<T>
Direct Known Subclasses:
DefaultProxyServiceLoadBalancer

public class SimpleServiceLoadBalancer<S extends Service,T extends ServiceLoad> extends AbstractServiceLoadBalancer<S,T>
A simple ServiceLoadBalancer implementation.
Author:
jh 2010.12.07
  • Field Details

    • m_mapLoad

      protected final Map<Member,T extends ServiceLoad> m_mapLoad
      A Map of ServiceLoad objects keyed by their associated Member.
    • m_mapMember

      protected final SortedMap<T extends ServiceLoad,List<Member>> m_mapMember
      A SortedMap of List of Member objects keyed by their associated ServiceLoad.
  • Constructor Details

    • SimpleServiceLoadBalancer

      public SimpleServiceLoadBalancer()
      Default constructor.
    • SimpleServiceLoadBalancer

      public SimpleServiceLoadBalancer(Comparator<T> comparator)
      Create a new SimpleServiceLoadBalancer that will order ServiceLoad objects using the specified Comparator. If null, the natural ordering of the ServiceLoad objects will be used.
      Parameters:
      comparator - the Comparator used to order ServiceLoad objects
  • Method Details

    • update

      public void update(Member member, T load)
      Update the load balancing strategy in response to a change in a Service utilization.
      Parameters:
      member - the Member for which the utilization changed
      load - the updated ServiceLoad; if null, the utilization for the specified Member is unknown (e.g. when the Service on the specified Member leaves the cluster)
    • getMemberList

      public List<Member> getMemberList(Member client)
      Called by the Service when a new client connects to obtain an ordered list of Members to which the new client should be redirected. If the returned list is null, empty, or contains a single Member that is the "local" Member, the client will remain connected to the calling Service.
      Parameters:
      client - the Member object that represents the remote client
      Returns:
      the ordered list of Member objects to which the client should be redirected
    • compare

      public int compare(T load1, T load2)
      Description copied from interface: ServiceLoadBalancer
      Compare to ServerLoad objects.
      Parameters:
      load1 - the first ServiceLoad
      load2 - the second ServiceLoad
      Returns:
      a negative integer, zero, or a positive integer indicating if load1 is less then, equal, or greater then load2