Function Execution Example

Function execution allows you to move function behavior to the application member hosting the data. For large data sets, this can provide much better performance than moving the data to the application that needs to run the function.

Running the Example

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.

Note: To run this example, you must have terminal sessions configured for the QuickStart examples, as described in Setting Up Your Environment.

  1. In one session, start the first member:

    $ java quickstart.FunctionExecutionPeer1
    
  2. When the first member tells you to do so, start the second member in another session:

    $ java quickstart.FunctionExecutionPeer2

Example Source Files

Program and cache configuration files for the function execution on JVMs 1 and 2. Both JVMs use the same cache XML configuration file.

Table 1. Cache configuration files, located in $SamplesDirectory/quickstart/xml
FunctionExecutionPeer.xml Configures a region as a client region in a client/server cache.
Table 2. Java program files, located in $SamplesDirectory/quickstart/quickstart
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.
Related Topics
Function Execution

Related Javadocs