A function is a body of code that resides on one or more servers and that an app can invoke without the need to send the function code itself. The app can direct a data-dependent function to operate on a particular dataset, or can direct a data-independent function to operate on a particular server.
Functions are implemented and executed on the server. See Function Execution in the VMware GemFire Documentation for more information.
Accessing region data on the servers with a data-dependent function may lead to a large performance gain. Without a server-side function, the same computation would likely require the app to invoke a query or an operation that acquired all the region data prior to running the computation in the app. The server-side function eliminates the transmission of a potentially large quantity of data from the servers to the app.
The function must be written in Java and deployed to the servers with the gfsh deploy
command. See Deploy an App JAR File to the Servers for instructions on deploying the function to a Cloud Cache service instance.
Within the app, invoke Region.executeFunction()
to cause the function to be executed. The function returns a Promise that resolves to an array containing the results of the function’s execution.
The function-execution example in the https://github.com/gemfire/node-examples repository presents a simple data-dependent function execution example. It contains the Java function implementation, and the app that invokes the function. The script that starts up the cluster also deploys the function to the cluster’s servers.
Data-independent functions allow an app to access a cluster’s administrative qualities. For example, a data-independent function could calculate memory usage across regions.
The function must be written in Java and deployed to the servers with the gfsh deploy
command. See Deploy an App JAR File to the Servers for instructions on deploying the function to a Cloud Cache service instance.
Within the app, invoke Pool.executeFunction()
to cause the data-independent function to be executed. The function returns a Promise that resolves to an array containing the results of the function’s execution.