GemFire Enterprise Native Client

Programming Example

March 2008

The ProductBrowser example demonstrates heterogeneous client access by using both a .NET client and a Java client to interact with a Java cache server and exchange data between the clients. Both clients have Product for their DataSerializable class, and the .NET client implements a cache listener to display events as they occur. Use ProductBrowser to put product data into the cache server from one client, retrieve the data in another client, make modifications, then update the clients with the new data. The example is located in the native client installation under NativeClient_xxxx/examples/cli_ProductBrowser.

Running ProductBrowser

The ProductBrowser example runs both a .NET client and a Java client with a GemFire Java cache server. The example uses product.xml to configure the Java cache server. When the Java cache server starts, product.xml creates a root region named product.

In the procedures, the lines you type are shown in a boldface fixed font. System output is in a regular fixed font.

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 ProductBrowser 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/
% JAVA_HOME=<installed JRE PATH>; export JAVA_HOME
% PATH=$JAVA_HOME/bin:$PATH; export PATH


> cd GemFireInstallDirectory
> bin\setenv.bat
> set JAVA_HOME=<installed JRE PATH>
> set PATH=%JAVA_HOME%\bin;%PATH%

Starting the Cache Server

To start the cache server for the ProductBrowser 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.

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

  2. Go to the cli_ProductBrowser directory:

    cd NativeClient_xxxx/examples/cli_ProductBrowser

  3. Start the cache server, specifying product.xml in the defaultConfig directory as its configuration file. Enter the entire cacheserver start command below on a single line, replacing the xxxx in NativeClient_xxxx with the actual four-digit product version:

    cacheserver start -dir=NativeClient_xxxx\examples\
    cli_ProductBrowser\defaultConfig cache-xml-file=product.xml

    The cache server is initialized using the settings in the product.xml file. A message similar to the following appears, indicating that the cache server is running:

  4. Cacheserver pid: 2120 status: running

Starting the ProductBrowser Java client

The Java client uses productClient.jar in the lib directory. To start the Java client:

  1. Create another session and configure its environment by entering the following command:

  2. bin\setenv.bat

  3. Add the classes for productClient.jar to your CLASSPATH by entering the following in a single line:

  4. set CLASSPATH=NativeClient_xxxx\examples\cli_ProductBrowser\

  5. Start the ProductBrowser Java client:


    The ProductBrowser Java client is initialized and connects with the cache server. In a moment, the following prompt appears:

  6. Enter the operation to execute. 'Get' to find an object, 'Put' to insert/update an object, or 'Exit' to end:

Starting the ProductBrowser .NET Client

To complete the client setup, start the .NET client by following these steps:

  1. Create another session, then go to the cli_ProductBrowser directory.

    cd native_client/examples/cli_ProductBrowser

  2. Start the .NET client:


    The Product Browser form appears. The form consists of a set of fields where you enter product data. The Event Message area is a cache listener interface that displays events as they occur in the clients.

Entering Data in the Product Browser Form

Enter data in the Product Browser form and put the data into the cache.

In the Product Browser form:

  1. Type the following data into each of the fields:
  2. Product Id 101
    Product Name widget
    Product Number 123
    Stock Amt 15
    Reorder Amt 10
    Cost 1.5
    List Price 5.0
    Days to Mfg 5
    Sell Date 3/15
    Discontinue Date 9/12
  3. Click the Put button to enter the data into the cache server.

Retrieving the Data in the Java Client

Next, specify the Product ID to update the Java client with the data you entered in the Product Browser form.

In the Java client:

  1. Get the product data previously entered into the Product Browser form:


  2. When the following prompt appears, enter 101 for the Product ID that was defined in the Product Browser:

    Enter the Product ID to search for: 101

    The data associated with Product ID 101 is retrieved from the cacheserver:

    Product ID = 101
    Product Name = widget
    Product Number = 123
    Color = Black
    Stock Level = 15
    Reorder Point = 10
    Product Cost = 1.5
    List Price = 5.0
    Available as of = 3/15
    Discontinue as of = 9/12

Modifying the Data With the Java Client

Enter some new product values into the Java client and see both the original and the new values displayed in the .NET client (Product Browser).

In the Java client:

  1. Put new data into the cache. You're prompted with the same input fields as the Product Browser form:


  2. For each of the following prompts, enter the values shown:

  3. ProductId: 101
    Product Name: widget
    Product Number: 123
    Color: Blue
    Stock Level (int): 30
    Reorder Point (int): 15
    Product Cost (double): 2.0
    List Price (double): 6.0
    Available as of (string): 6/15
    Discontinue as of (string): 11/12
  4. Look at the Product Browser. Its Event Message area displays the original values for Product ID 101, along with the updated values that you just entered in the Java client.

  5. In the cache server session, enter the following command to stop the cache server:

    cacheserver stop -dir=defaultConfig

  6. Now close the cache server session:


  7. End the Java client, then close its session:



  8. Close the .NET client session:


  9. Close the Product Browser form by clicking the 'X' button in the right part of its titlebar, or by clicking the icon in the left part of its titlebar and then clicking Close.

Changing System Parameters

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. Copy the file into your cli_ProductBrowser directory from the defaultSystem directory. Edit the file in your cli_ProductBrowser directory as needed. For example, to change the name of the cache.xml file, uncomment this line and change the file name:




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.