Skip to content

io microsphere spring cloud fault tolerance loadbalancer WeightedRoundRobin

github-actions[bot] edited this page Jun 21, 2026 · 6 revisions

WeightedRoundRobin

Type: Class | Module: microsphere-spring-cloud-commons | Package: io.microsphere.spring.cloud.fault.tolerance.loadbalancer | Since: 1.0.0

Source: microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/fault/tolerance/loadbalancer/WeightedRoundRobin.java

Overview

Weighed Round-Robin

Declaration

public class WeightedRoundRobin

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.20-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

getId

WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
String id = wrr.getId(); // "server-1"

getWeight

WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
int weight = wrr.getWeight(); // 5

setWeight

WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(10);

increaseCurrent

WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
long current = wrr.increaseCurrent(); // 5
current = wrr.increaseCurrent();      // 10

sel

WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
wrr.increaseCurrent();
wrr.sel(10); // subtract total weight of all entries

getLastUpdate

WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setLastUpdate(System.currentTimeMillis());
long lastUpdate = wrr.getLastUpdate();

setLastUpdate

WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setLastUpdate(System.currentTimeMillis());

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-cloud-commons</artifactId>
    <version>${microsphere-spring-cloud.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-cloud-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.cloud.fault.tolerance.loadbalancer.WeightedRoundRobin;

API Reference

Public Methods

Method Description
getId Create a new WeightedRoundRobin instance with the given identifier.
getWeight Get the current weight of this WeightedRoundRobin entry.
setWeight Set the weight for this WeightedRoundRobin entry and reset the current counter.
increaseCurrent Increase the current counter by the weight value and return the updated value.
sel Subtract the total weight from the current counter after this entry has been selected.
getLastUpdate Get the timestamp of the last update to this WeightedRoundRobin entry.
setLastUpdate Set the timestamp of the last update to this WeightedRoundRobin entry.

Method Details

getId

public String getId()

Create a new WeightedRoundRobin instance with the given identifier.

Example Usage:

`WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
`

getWeight

public int getWeight()

Get the current weight of this WeightedRoundRobin entry.

Example Usage:

`WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
int weight = wrr.getWeight(); // 5
`

setWeight

public void setWeight(int weight)

Set the weight for this WeightedRoundRobin entry and reset the current counter.

Example Usage:

`WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(10);
`

increaseCurrent

public long increaseCurrent()

Increase the current counter by the weight value and return the updated value. Used during weighted round-robin selection to accumulate the weight for this entry.

Example Usage:

`WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
long current = wrr.increaseCurrent(); // 5
current = wrr.increaseCurrent();      // 10
`

sel

public void sel(int total)

Subtract the total weight from the current counter after this entry has been selected. This is part of the weighted round-robin algorithm to reduce the selected entry's counter.

Example Usage:

`WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
wrr.increaseCurrent();
wrr.sel(10); // subtract total weight of all entries
`

getLastUpdate

public long getLastUpdate()

Get the timestamp of the last update to this WeightedRoundRobin entry.

Example Usage:

`WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setLastUpdate(System.currentTimeMillis());
long lastUpdate = wrr.getLastUpdate();
`

setLastUpdate

public void setLastUpdate(long lastUpdate)

Set the timestamp of the last update to this WeightedRoundRobin entry.

Example Usage:

`WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setLastUpdate(System.currentTimeMillis());
`

This documentation was auto-generated from the source code of microsphere-spring-cloud.

Home

spring-cloud-commons

spring-cloud-openfeign

Clone this wiki locally