Class MultiEndpoint
Sometimes switching between endpoints can be costly, and it is worth waiting for some time
after current endpoint becomes unavailable. For this case, use MultiEndpoint.Builder.withRecoveryTimeout(java.time.Duration) 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(java.util.List<java.lang.String>) 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 MultiEndpoint.Builder.withSwitchingDelay(java.time.Duration) 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for MultiEndpoint. -
Method Summary
Modifier and TypeMethodDescriptionReturns current endpoint id.longlonglongvoidsetEndpointAvailable(String endpointId, boolean available) Inform MultiEndpoint when an endpoint becomes available or unavailable.voidsetEndpoints(List<String> endpoints) Provide an updated list of endpoints to MultiEndpoint.toString()
-
Method Details
-
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.
-
getFallbackCnt
public long getFallbackCnt() -
getRecoverCnt
public long getRecoverCnt() -
getReplaceCnt
public long getReplaceCnt() -
getEndpoints
-
setEndpointAvailable
Inform MultiEndpoint when an endpoint becomes available or unavailable. -
setEndpoints
Provide an updated list of endpoints to MultiEndpoint.MultiEndpoint will preserve current endpoints' state and update their priority according to their new positions.
-
toString
-