public class RebalanceManager extends Object
| Modifier and Type | Method and Description |
|---|---|
void |
addBgHealthCheckInstance() |
void |
clearAllForTest() |
void |
connected(List<Endpoint> endpoints,
int index)
Mark the specified endpoint as online when connection is successful
|
void |
decrementConnectionCount(Endpoint endpoint)
Decrement the connection count of the specified endpoint
Called when a connection is closed to the endpoint
|
void |
disconnected(ConnectionParam original,
int index,
InFlightRequest inFlightRequest)
Handle endpoint disconnection event
1.
|
void |
disconnectedBySelf(ConnectionParam original,
int index)
Handle self-initiated disconnection (only decrement connection count)
|
void |
endpointUp(ConnectionParam param,
Endpoint endpoint)
Mark endpoint as online and trigger rebalancing if conditions are met
|
int |
getBgHealthCheckInstanceCount() |
int[] |
getConnectCountsAsc(List<Endpoint> endpoints)
Get endpoint indexes sorted by connection count in ascending order
Used for load balancing to select the least loaded endpoint
|
EndpointInfo |
getEndpointInfo(Endpoint endpoint)
Get the metadata (connection count + health status) of the specified endpoint
|
static RebalanceManager |
getInstance()
Get the singleton instance of RebalanceManager
This is the only way to access the manager's functionality
|
int |
getMinConnectionEndpointIndex(ConnectionParam param)
Get the index of the endpoint with the minimum connection count
Used to select the least loaded endpoint for rebalancing
|
boolean |
handleRebalancing(ConnectionParam param,
Endpoint currentEndpoint)
Handle rebalancing logic for the current connection
1.
|
void |
incrementConnectionCount(Endpoint endpoint)
Increment the connection count of the specified endpoint
Called when a new connection is established to the endpoint
|
boolean |
isRebalancing()
Check if there is any cluster in global rebalancing state
|
boolean |
isRebalancing(Endpoint endpoint)
Check if the cluster of the specified endpoint is in rebalancing state
|
void |
newCluster(List<Endpoint> endpoints)
Register a new cluster and initialize endpoint metadata
Idempotent operation: no effect if the cluster is already registered
|
void |
removeBgHealthCheck(BgHealthCheck bgHealthCheck) |
void |
removeBgHealthCheckInstance() |
void |
startBackgroundHealthCheck(ConnectionParam original,
int index,
InFlightRequest inFlightRequest)
Start background health check for offline endpoints
Monitors endpoint recovery status and updates state when online
|
public static RebalanceManager getInstance()
public boolean isRebalancing(Endpoint endpoint)
endpoint - Target endpoint to checkpublic boolean isRebalancing()
public void incrementConnectionCount(Endpoint endpoint)
endpoint - Target endpointpublic void decrementConnectionCount(Endpoint endpoint)
endpoint - Target endpointpublic void connected(List<Endpoint> endpoints, int index)
endpoints - List of cluster endpointsindex - Index of the connected endpoint in the listpublic void disconnected(ConnectionParam original, int index, InFlightRequest inFlightRequest)
original - Original connection parametersindex - Index of the disconnected endpoint in the listinFlightRequest - In-flight request container for health check response handlingpublic void disconnectedBySelf(ConnectionParam original, int index)
original - Original connection parametersindex - Index of the disconnected endpoint in the listpublic void newCluster(List<Endpoint> endpoints)
endpoints - List of endpoints in the new clusterpublic void endpointUp(ConnectionParam param, Endpoint endpoint)
param - Connection parameters (contains rebalance thresholds)endpoint - The endpoint that recovered to online statepublic EndpointInfo getEndpointInfo(Endpoint endpoint)
endpoint - Target endpointpublic int[] getConnectCountsAsc(List<Endpoint> endpoints)
endpoints - List of cluster endpointspublic void startBackgroundHealthCheck(ConnectionParam original, int index, InFlightRequest inFlightRequest)
original - Original connection parametersindex - Index of the offline endpoint in the listinFlightRequest - In-flight request container for health check responsespublic boolean handleRebalancing(ConnectionParam param, Endpoint currentEndpoint)
param - Connection parameters with rebalance thresholdscurrentEndpoint - The endpoint currently connected topublic int getMinConnectionEndpointIndex(ConnectionParam param)
param - Connection parameters with endpoint listpublic void addBgHealthCheckInstance()
public void removeBgHealthCheckInstance()
public int getBgHealthCheckInstanceCount()
public void removeBgHealthCheck(BgHealthCheck bgHealthCheck)
public void clearAllForTest()
Copyright © 2025. All rights reserved.