Under the hood

The section will explain what is going on under the
hood when you register a cluster and execute a
Requests.

When you register a Cluster with the
Request, a RequestExecutor is created behind
the scene. This RequestExecutor is stored in a
Map using the cluster name as key. When a request is
executed the provided cluster name is used to find the associated
RequestExecutor and execute the request.

The reason the RequestExecutor
is hidden by default, is so you don't have to keep track of it. You may
only create one RequestExecutor per cluster, so if you use
it directly you need to store a reference to it throughout your
application. Using Request.registerCluster(cluster) means
that you can blissfully ignore the RequestExecutor and
lifecycle rules.

The RequestExecutor contains the necessary state and
logic which provides the load balancing and failover features. Using
the RequestExecutor directly also offers a few extra
features, which we will look at.