public class HostAvailabilityListener extends Object implements QueryFailureListener, WriteFailureListener
HostAvailabilityListener is automatically registered with all QueryBatcher and WriteBatcher instances to monitor for failover scenarios. When HostAvailabilityListener detects that a host is unavailable (matches one of getHostUnavailableExceptions()), it black-lists the host for a period of time equal to getSuspendTimeForHostUnavailable(). After that time, it calls DataMovementManager.readForestConfig() then passes that updated ForestConfiguration to batcher.withForestConfig() so the batcher will fall back to using the hosts the server says are available. Directly after black-listing (and before updating the ForestConfiguration) this calls batcher.retry with the failed WriteBatch or QueryBatchException so the batch can succeed if possible. The main objective here is to gracefully handle a failover scenario by temporarily routing requests to hosts other than the failed host(s), retry-ing requests that failed, and eventually reverting to utilizing the full cluster that’s available. Nevertheless, there will definitely be failure scenarios not addressed by HostAvailabilityListener and therefore we recommend that production installations of Data Movement SDK use HostAvailabilityListener as an example and install their own failure-handling listeners complete with retry and updates to the batcher’s ForestConfiguration as appropriate.
If you would like to change the default settings, you can change them on the pre-registered HostAvailabilityListener which you can access via WriteBatcher.getBatchFailureListeners() or QueryBatcher.getQueryFailureListeners().
| Constructor and Description |
|---|
HostAvailabilityListener(DataMovementManager moveMgr) |
| Modifier and Type | Method and Description |
|---|---|
Throwable[] |
getHostUnavailableExceptions() |
int |
getMinHosts() |
Duration |
getSuspendTimeForHostUnavailable() |
void |
processFailure(QueryBatchException queryBatch)
This implements the QueryFailureListener interface
|
void |
processFailure(WriteBatch batch,
Throwable throwable)
This implements the WriteFailureListener interface
|
HostAvailabilityListener |
withHostUnavailableExceptions(Class<Throwable>... exceptionTypes)
Overwrites the list of exceptions for which a host will be blacklisted
|
HostAvailabilityListener |
withMinHosts(int numHosts)
If less than minHosts are left, calls stopJob.
|
HostAvailabilityListener |
withSuspendTimeForHostUnavailable(Duration duration)
If a host becomes unavailable (NoHttpResponseException, SocketException, SSLException, UnknownHostException), adds it to the blacklist
|
public HostAvailabilityListener(DataMovementManager moveMgr)
moveMgr - the DataMovementManager (used to call readForestConfig to reset after black-listing an unavailable host)public HostAvailabilityListener withSuspendTimeForHostUnavailable(Duration duration)
If a host becomes unavailable (NoHttpResponseException, SocketException, SSLException, UnknownHostException), adds it to the blacklist
duration - the amount of time an unavailable host will be suspendedpublic HostAvailabilityListener withMinHosts(int numHosts)
If less than minHosts are left, calls stopJob.
numHosts - the minimum number of hosts before this will call dataMovementMangaer.stopJob(batcher)public HostAvailabilityListener withHostUnavailableExceptions(Class<Throwable>... exceptionTypes)
Overwrites the list of exceptions for which a host will be blacklisted
exceptionTypes - the list of types of Throwable, any of which constitute a host that’s unavailablepublic Throwable[] getHostUnavailableExceptions()
public Duration getSuspendTimeForHostUnavailable()
public int getMinHosts()
public void processFailure(WriteBatch batch, Throwable throwable)
This implements the WriteFailureListener interface
processFailure in interface BatchFailureListener<WriteBatch>processFailure in interface WriteFailureListenerbatch - the batch of WriteEventsthrowable - the exceptionpublic void processFailure(QueryBatchException queryBatch)
This implements the QueryFailureListener interface
processFailure in interface FailureListener<QueryBatchException>processFailure in interface QueryFailureListenerqueryBatch - the exception with information about the failed query attemptCopyright © 2013-2017 MarkLogic Corporation.