Local fallback

The previous failover implementation was considering that there is an alternative system to contact if the primary one fails. This is not always the case and you may desire to replace a remote invocation by a local default in the case of an error. This sort of solution is available in the hystrix framework, which can be integrated with Java EE using the concurrency utilities that we saw earlier.

The high-level logic of defaulting is as follows:

try {    return getRemoteResponse();    } catch (final UnexpectedError error) {    return getLocalResponse();}

This is actually a generalization of the previous implementation. Instead of seeing a list of hosts to contact, you need to consider the remote invocations that you can do as a list ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.