Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA RoundRobinRule

From Leeroopedia
Knowledge Sources
Domains Load_Balancing
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete round-robin load balancing rule implementation that distributes Discord instance selection evenly across available instances using an atomic counter.

Description

The RoundRobinRule class implements the `IRule` interface to provide a round-robin selection algorithm for Discord instance load balancing. It uses an `AtomicInteger` counter with compare-and-set to ensure thread-safe increment, cycling through available instances in order.

Usage

Use this rule when you want even distribution of tasks across all available Discord instances without considering instance load or wait time.

Code Reference

Source Location

Signature

public class RoundRobinRule implements IRule {
    private final AtomicInteger position = new AtomicInteger(0);

    @Override
    public DiscordInstance choose(List<DiscordInstance> instances);

    private int incrementAndGet();
}

Import

import com.intelligent.bot.api.midjourney.loadbalancer.rule.RoundRobinRule;

I/O Contract

Inputs

Name Type Required Description
instances List<DiscordInstance> Yes List of available Discord instances

Outputs

Name Type Description
returns DiscordInstance Selected instance (null if list is empty)

Usage Examples

Round-Robin Instance Selection

import com.intelligent.bot.api.midjourney.loadbalancer.rule.RoundRobinRule;

RoundRobinRule rule = new RoundRobinRule();
List<DiscordInstance> instances = loadBalancer.getAllInstances();

// Each call cycles to the next instance
DiscordInstance instance1 = rule.choose(instances);  // instance[0]
DiscordInstance instance2 = rule.choose(instances);  // instance[1]
DiscordInstance instance3 = rule.choose(instances);  // instance[2]
DiscordInstance instance4 = rule.choose(instances);  // instance[0] (wraps around)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment