Gluon Cloudlink Function Mapper with JavaFX applications


We previously talked about using Gluon CloudLink with mobile apps. In this blog post, we talk about how any JavaFX application (e.g. on desktop) can take advantage of Gluon CloudLink.

Gluon CloudLink allows us to use a Function Mapper for creating a simple and decoupled infrastructure. Gluon Cloudlink connects the client application and the data endpoints in cloud or server infrastructure. The Function Mapper allows the client application and the data endpoints to be developed and maintained separately. The Function Mapper manages the coupling between the client application and the data endpoints. This decoupling clearly benefits mobile apps, but also desktop applications become much simpler and easier to maintain. For example, when the location of an endpoint changes, or if some parameter names are modified, the Function Mapper allows you to reconfigure the mapping without having to change the code for the client application. This makes Java client applications much more resilient to changes in backend infrastructure.

On the client, we simply use the Gluon CloudLink SDK to call a function that is defined at Gluon CloudLink. The definition of the function at Gluon CloudLink maps the function name to a remote invocation, which can be a REST endpoint or an invocation of a serverless Function.

A complete guide on how to use the Function Mapper is available at https://docs.gluonhq.com/samples/functionmapperdesktop and a sample showing how this work can be found at Github. In this sample, we use the StackOverflow endpoint based on its Stack Exchange API v2.2. We use
https://api.stackexchange.com/2.2/search?order=desc&sort=activity&site=stackoverflow endpoint to retrieve a list of questions based on tags from Stackoverflow. The user selected tag information is passed from the client to the endpoint via Gluon Cloudlink.

The client does not need to know all these details and can simply call the remote function on Gluon Cloudlink using the following piece of code:

public GluonObservableObject searchStackOverflow(String value) {
    RemoteFunctionObject function = RemoteFunctionBuilder
    .create("searchStackOverflow")
    .param("tagged", value)
    .object();
    return function.call(StackResponse.class);
}

Similarly, when a user selects a question we want to show the list of answers. To achieve this we create another remote function for querying answers in the Gluon Dashboard. This remote function now hits the API url: https://api.stackexchange.com/2.2/questions/$questionID/answers?order=desc&sort=activity&site=stackoverflow. But on the client side, we just use the code:

public GluonObservableObject answersStackOverflow(String value) {
    RemoteFunctionObject function = RemoteFunctionBuilder
            .create("answersStackOverflow")
            .param("questionID", value)
            .object();
    return function.call(StackResponse.class);
}

We can see how using Gluon CloudLink removes boiler plate code from the client. Moreover, if any of the Stackoverflow REST endpoints ever change, we do not need to change the client code. We can update the new API in the Gluon dashboard and all the clients will start using the new API. This is a huge advantage over legacy way of doing things, as it no longer requires the users to update their client. Make sure to read more information about Gluon CloudLink and feel free to start with a 30 day free trial.