|Getting Started with Pivotal GemFire / QuickStart Examples|
With large data sets, moving function behavior to the application member hosting the data can provide better performance than moving data to the application that will run the function.
In this example of peer-to-peer function execution, one member sends a request for function execution to a peer member. FunctionExecutionPeer2 creates a region, populates the region and sends a function execution request to FunctionExecutionPeer1 while simultaneously executing the function on its own region. It collects the result from its own execution as well as from FunctionExecutionPeer1. The function executed is programmed in MultiGetFunction, as an implementation of GemFire's FunctionAdapter. The results from the function are handled by MyArrayListResultCollector, which is an implementation of GemFire's ResultCollector.
In one session, start the first member:
$ java quickstart.FunctionExecutionPeer1
When the first member tells you to do so, start the second member in another session:
$ java quickstart.FunctionExecutionPeer2
Program and cache configuration files for the function execution on JVMs 1 and 2. Both JVMs use the same cache XML configuration file.
|FunctionExecutionPeer.xml||Configures a region as a client region in a client/server cache.|
|FunctionExecutionPeer1.java||This is the peer to which FunctionExecutionPeer2 connects for function execution.|
|FunctionExecutionPeer2.java||Creates a region, populates the region, and sends a function execution request to FunctionExecutionPeer1 while simultaneously executing the function on its own region.|
|MultiGetFunction.java||Application Function to retrieve values for multiple keys in a region.|
|MyArrayListResultCollector.java||Gathers result from all members where the function is executed.|