LATEST VERSION: 8.2.7 - CHANGELOG
Pivotal GemFire® v8.2

Function Execution Example

Function Execution Example

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.

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 for Running the Examples.
  1. In one session, start the first member:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.FunctionExecutionPeer1
    
  2. When the first member tells you to do so, start the second member in another session:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" 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 SampleCode//quickstart/xml
FunctionExecutionPeer.xml Configures a region as a client region in a client/server cache.
Table 2. Java program files, located in SampleCode//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

  • com.gemstone.gemfire.cache.execute