Class DefaultLoadBalancer<T>

    • Constructor Detail

      • DefaultLoadBalancer

        public DefaultLoadBalancer()
    • Method Detail

      • route

        public ClusterNodeId route​(T msg,
                                   LoadBalancerContext ctx)
                            throws LoadBalancerException
        Description copied from interface: LoadBalancer
        Selects one of the cluster nodes from the load balancer context. Note that the provided context contains only those nodes that are capable of receiving messages of this channel (i.e. have MessageReceiver) and match the channel's topology filtering rules.

        Returning null from this method (if target node can't be selected for some reason) will cause message sending operation to fail with LoadBalancerException.

        Specified by:
        route in interface LoadBalancer<T>
        Parameters:
        msg - Message.
        ctx - Load balancer context.
        Returns:
        Node that should be used for the messaging operation.
        Throws:
        LoadBalancerException - if failed to perform load balancing.
      • nonAffinityRoute

        protected ClusterNode nonAffinityRoute​(T msg,
                                               LoadBalancerContext ctx)
                                        throws LoadBalancerException
        Selects a random node from the load balancer context. If the selected node is known to be failed then another random non-failed node will be selected. If all nodes are known to be failed then this method will fallback to the initially selected node.
        Parameters:
        msg - Message.
        ctx - Load balancer context.
        Returns:
        Selected node.
        Throws:
        LoadBalancerException - if failed to perform load balancing.