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.

Let's look at a short example


public static void main(String[] args) throws InterruptedException, RQLException {

    RoboServer server = new RoboServer("localhost", 50000);
    Cluster cluster = new Cluster("MyCluster", new RoboServer[]{ server}, false);
    Request.registerCluster(cluster);
    Request request = new Request("Library:/Tutorials/NewsMagazine.robot");
    request.setRobotLibrary(new DefaultRobotLibrary());
    RQLResult result = request.execute("MyCluster");
    System.out.println(result);
}
                          

Normal execution


Now let's write the same example by using the hidden RequestExecutor directly


public static void main(String[] args) throws InterruptedException, RQLException {

    RoboServer server = new RoboServer("localhost", 50000);
    Cluster cluster = new Cluster("MyCluster", new RoboServer[]{ server}, false);
    RequestExecutor executor = new RequestExecutor(cluster);

    Request request = new Request("Library:/Tutorials/NewsMagazine.robot");
    request.setRobotLibrary(new DefaultRobotLibrary());
    RQLResult result = executor.execute(request);
    System.out.println(result);
}
                          

under the hood execution


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.