Class MultiEndpoint (1.11.0)

public final class MultiEndpoint

MultiEndpoint holds a list of endpoints, tracks their availability and defines the current endpoint. An endpoint has a priority defined by its position in the list (first item has top priority). MultiEndpoint returns top priority endpoint that is available as current. If no endpoint is available, MultiEndpoint returns the top priority endpoint.

Sometimes switching between endpoints can be costly, and it is worth waiting for some time after current endpoint becomes unavailable. For this case, use Builder#withRecoveryTimeout to set the recovery timeout. MultiEndpoint will keep the current endpoint for up to recovery timeout after it became unavailable to give it some time to recover.

The list of endpoints can be changed at any time with #setEndpoints method. MultiEndpoint will preserve endpoints' state and update their priority according to their new positions.

After updating the list of endpoints, MultiEndpoint will switch the current endpoint to the top-priority available endpoint. If you have many processes using MultiEndpoint, this may lead to immediate shift of all traffic which may be undesired. To smooth this transfer, use Builder#withSwitchingDelay with randomized value to introduce a jitter. MultiEndpoint will delay switching from an available endpoint to another endpoint for this amount of time.

The initial state of endpoint is "unavailable" or "recovering" if using recovery timeout.

Inheritance

java.lang.Object > MultiEndpoint

Methods

getCurrentId()

public String getCurrentId()

Returns current endpoint id.

Note that the read is not synchronized and in case of a race condition there is a chance of getting an outdated current id.

Returns
Type Description
String

getEndpoints()

public List<String> getEndpoints()
Returns
Type Description
List<String>

getFallbackCnt()

public long getFallbackCnt()
Returns
Type Description
long

getRecoverCnt()

public long getRecoverCnt()
Returns
Type Description
long

getReplaceCnt()

public long getReplaceCnt()
Returns
Type Description
long

setEndpointAvailable(String endpointId, boolean available)

public synchronized void setEndpointAvailable(String endpointId, boolean available)

Inform MultiEndpoint when an endpoint becomes available or unavailable.

Parameters
Name Description
endpointId String
available boolean

setEndpoints(List<String> endpoints)

public synchronized void setEndpoints(List<String> endpoints)

Provide an updated list of endpoints to MultiEndpoint.

MultiEndpoint will preserve current endpoints' state and update their priority according to their new positions.

Parameter
Name Description
endpoints List<String>

toString()

public String toString()
Returns
Type Description
String
Overrides