GemFire Enterprise Native Client

C# Programming Example

March 2008

Tiered, or hierarchical caching, lets you isolate data management to one or more servers, allowing multiple clients to connect and use the server caches. This is the model for scalability, with many clients benefitting from the management resources of just a few servers.

In GemFire Enterprise hierarchical caching, there is a server-side distributed system and one or more client-side distributed systems. The server VMs run BridgeServers that listen on unique ports for data requests and updates from clients. The clients forward all data requests their caches cannot fulfill to the servers. To do this, they use a custom data loader, the BridgeLoader. The clients might also be configured with a custom listener, called the BridgeWriter, that updates the servers when data is modified on the client side. In the HierarchicalServer.xml file for the cache server used in this example, note that the BridgeServer is defined for the entire cache. It services requests from any client for any region in the cache.

About the HierarchicalClient Example

The HierarchicalClient example is an interactive C# program that uses Microsoft .NET Framework 2.0 to access the GemFire C++ API for modifying and viewing cache contents.

Microsoft .NET Framework 2.0 must be installed before running this example. For information about installing the .NET Framework, see Chapter 1 in the GemFire Enterprise Native Client Guide.

HierarchicalClient demonstrates a server in a tiered hierarchical caching setup. The client application comes with a cache configuration file, HierarchicalClient.xml, which is configured to create a root region and establish the native client endpoints to the locally-run server by specifying localhost:40404.

The HierarchicalClient cache listens for client requests at a specific port (see HierarchicalServer.xml). The client connects to the cache server's port, sending data requests and updates. At the beginning, both the server and client cache regions are empty.

When you run the example it will:

Configuring the Environment

Examples that interact with a Java cache server require specific environment configurations so the Java cache server will run properly. Follow the configuration steps listed below that apply to your operating system:

  1. From the GemFire Enterprise product installation directory, run the appropriate bin/setenv script for your system. Refer to the developer's guide if you need help with this step.

  2. Set the JAVA_HOME and GF_JAVA_HOME environment variables to your installed Java JRE or JDK. See the Installation chapter of the GemFire Enterprise System Administrator's Guide for the versions of Java that are compatible with GemFire Enterprise. The JAVA_HOME setting is for your applications, and GF_JAVA_HOME is for the GemFire scripts. You must have a compatible Java JRE or JDK installed and you must set JAVA_HOME and GF_JAVA_HOME to point to it.

  3. Add $JAVA_HOME/bin to the start of your PATH.

The following is a list of the environment configuration commands for the HierarchicalClient example. Choose the set of commands that are appropriate for your operating system. The text that you type is shown in bold. These configurations only need to be performed for the sessions that invoke the Java cache server.

Bourne and Korn shells (sh, ksh, bash)

% cd GemFireInstallDirectory
% . bin/setenv.sh
% CLASSPATH=$CLASSPATH:$GEMFIRE/quickstart/classes; export CLASSPATH
% cd $GEMFIRE/quickstart
% JAVA_HOME=<Installed JRE PATH>; export JAVA_HOME
% PATH=$JAVA_HOME/bin:$PATH; export PATH


> cd GemFireInstallDirectory
> bin\setenv.bat
> set CLASSPATH=%GEMFIRE%\quickstart\classes;%CLASSPATH%
> cd %GEMFIRE%\quickstart
> set JAVA_HOME=<Installed JRE PATH>
> set PATH=%JAVA_HOME%\bin;%PATH%

Starting HierarchicalClient

To run the HierarchicalClient example, create a session and complete the following steps. Throughout this example, when you're prompted to enter the native client directory, replace the xxxx in NativeClient_xxxx with the actual four-digit product version number.

This first session will start the Java cache server.

  1. Configure the session environment according to the steps listed in Configuring the Environment.

  2. If you have not already done so, go to the %GEMFIRE%/quickstart directory.

  3. cd %GEMFIRE%/quickstart

  4. Enter this command to start the Java cache server:

    java quickstart.HierarchicalServer

    The server creates /root/exampleRegion and prompts you to start the HierarchicalClient application.

  5. Create another session and go to the cli_HierarchicalClient example directory:

    cd NativeClient_xxxx/examples/cli_HierarchicalClient

  6. Start the HierarchicalClient application:
  7. HierarchicalClient.exe

Running the Example

The client session does a get for Key0, Key1, Key2, and Key3, then forwards the requests to the cache server. The server session reports that the values have been retrieved.

In the client session

Press Enter, as prompted. The client session reports a series of entry updates and destroys, which are forwarded to the cache server.

In the server session

The listener for the cache server reports create, update, and destroy events resulting from the modified entries.

In the client session

Press Enter to end the application, then type Exit to close the session.

In the server session

Press Enter to end the cache server, then type Exit to close the session.

Changing System Parameters

First copy the gfcpp.properties file into your cli_BenchmarkHierarchi calClient directory from the defaultSystem directory. Then edit the gfcpp.properties file in your cli_BenchmarkHierarchicalClient directory as needed.

This product ships configured to run with default system properties. If you need to run in a non-default configuration, GemFire also takes a system-level configuration file. First copy the gfcpp.properties file into your cli_HierarchicalClient directory from the defaultSystem directory. Then edit the gfcpp.properties file in your cli_HierarchicalClient directory as needed.

If you also need to make a non-default configuration for the Java cache server, first make a copy of the gemfire.properties file in the %GEMFIRE%/quickstart directory and then edit it. For example, to change the name of the cache.xml file, uncomment this line and change the file name:


When you're done with this example, delete your edited version of the gemfire.properties file and restore the renamed original version so other examples can use the unedited file.


Copyright © 2005-2008 by GemStone Systems, Inc. All rights reserved. GemStone®, GemFire®, and the GemStone logo are trademarks or registered trademarks of GemStone Systems, Inc. All other trade names or trademarks are the property of their respective owners. Information in this document is subject to change without notice.