-
Notifications
You must be signed in to change notification settings - Fork 30
io microsphere spring cloud fault tolerance loadbalancer WeightedRoundRobin
Type: Class | Module: microsphere-spring-cloud-commons | Package: io.microsphere.spring.cloud.fault.tolerance.loadbalancer | Since: 1.0.0
Weighed Round-Robin
public class WeightedRoundRobinAuthor: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.2.20-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
String id = wrr.getId(); // "server-1"WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
int weight = wrr.getWeight(); // 5WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(10);WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
long current = wrr.increaseCurrent(); // 5
current = wrr.increaseCurrent(); // 10WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
wrr.increaseCurrent();
wrr.sel(10); // subtract total weight of all entriesWeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setLastUpdate(System.currentTimeMillis());
long lastUpdate = wrr.getLastUpdate();WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setLastUpdate(System.currentTimeMillis());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 io.microsphere.spring.cloud.fault.tolerance.loadbalancer.WeightedRoundRobin;| 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. |
public String getId()Create a new WeightedRoundRobin instance with the given identifier.
Example Usage:
`WeightedRoundRobin wrr = new WeightedRoundRobin("server-1");
wrr.setWeight(5);
`
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
`
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);
`
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
`
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
`
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();
`
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.
spring-cloud-commons
- AbstractServiceRegistrationEndpoint
- CommonsPropertyConstants
- ConditionalOnAutoServiceRegistrationAvailable
- ConditionalOnAutoServiceRegistrationEnabled
- ConditionalOnBlockingDiscoveryAvailable
- ConditionalOnFeaturesAvailable
- ConditionalOnFeaturesEnabled
- ConditionalOnLoadBalancerEnabled
- ConditionalOnMultipleRegistrationEnabled
- ConditionalOnReactiveDiscoveryAvailable
- ConditionalOnUtilEnabled
- ConfigurationPropertyHasFeaturesAutoConfiguration
- DefaultRegistration
- DiscoveryClientAutoConfiguration
- DiscoveryClientConstants
- DiscoveryUtils
- EventPublishingRegistrationAspect
- FaultTolerancePropertyConstants
- FeaturesConstants
- FeaturesProperties
- FeaturesUtils
- InMemoryServiceRegistry
- InstanceConstants
- LoadBalancerUtils
- MultipleAutoServiceRegistration
- MultipleRegistration
- MultipleServiceRegistry
- NamedFeatureComparator
- ReactiveDiscoveryClientAdapter
- ReactiveDiscoveryClientAutoConfiguration
- RegistrationCustomizer
- RegistrationDeregisteredEvent
- RegistrationEvent
- RegistrationMetaData
- RegistrationPreDeregisteredEvent
- RegistrationPreRegisteredEvent
- RegistrationRegisteredEvent
- ServiceDeregistrationEndpoint
- ServiceInstanceUtils
- ServiceInstancesChangedEvent
- ServiceRegistrationEndpoint
- ServiceRegistrationEndpointAutoConfiguration
- ServiceRegistryAutoConfiguration
- SimpleAutoServiceRegistration
- SimpleAutoServiceRegistrationAutoConfiguration
- SimpleServiceRegistry
- SpecificationAutoConfiguration
- SpecificationBeanPostProcessor
- SpecificationCustomizer
- SpringCloudPropertyConstants
- TomcatDynamicConfigurationListener
- TomcatFaultToleranceAutoConfiguration
- UnionDiscoveryClient
- WebFluxServiceRegistryAutoConfiguration
- WebMvcServiceRegistryAutoConfiguration
- WebServiceRegistryAutoConfiguration
- WeightedRoundRobin
spring-cloud-openfeign
- AutoRefreshCapability
- AutoRefreshCapabilityCustomizer
- CompositedRequestInterceptor
- DecoratedContract
- DecoratedDecoder
- DecoratedEncoder
- DecoratedErrorDecoder
- DecoratedFeignComponent
- DecoratedQueryMapEncoder
- DecoratedRetryer
- EnableFeignAutoRefresh
- FeignAutoConfiguration
- FeignClientAutoRefreshAutoConfiguration
- FeignClientConfigurationChangedListener
- FeignComponentRegistry
- NoOpRequestInterceptor
- Refreshable