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.
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.
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:
bin/setenv script for your system. Refer to the developer's
guide if you need help with this step.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.$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/setenv.sh
% JAVA_HOME=<installed JRE PATH>; export JAVA_HOME
% GF_JAVA_HOME=$JAVA_HOME; export GF_JAVA_HOME
% PATH=$JAVA_HOME/bin:$PATH; export PATH
Windows
> cd GemFireInstallDirectory
> bin\setenv.bat
> set JAVA_HOME=<installed JRE PATH>
> set GF_JAVA_HOME=%JAVA_HOME%
> set PATH=%JAVA_HOME%\bin;%PATH%
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.
Configure the session environment according to the steps listed in Configuring the Environment.
cli_ProductBrowser directory:
cd NativeClient_xxxx/examples/cli_ProductBrowser
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:
Cacheserver pid: 2120 status: running
The Java client uses productClient.jar in the lib directory. To start the Java client:
Create another session and configure its environment by entering the following command:
bin\setenv.bat
Add the classes for productClient.jar to your CLASSPATH by entering the following in a single line:
set CLASSPATH=NativeClient_xxxx\examples\cli_ProductBrowser\
lib\productClient.jar;%CLASSPATH%
ProductBrowser
Java client:
java com.examples.gemfire.net.ProductBrowser
The ProductBrowser Java client is initialized and connects with the cache server. In a moment, the following prompt appears:
Enter the operation to execute. 'Get' to find an object, 'Put' to insert/update an object, or 'Exit' to end:
To complete the client setup, start the .NET client by following these steps:
cli_ProductBrowser directory.
cd native_client/examples/cli_ProductBrowser
ProductBrowser.exe
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.
Enter data in the Product Browser form and put the data into the cache.
In the Product Browser form:
Product Id101Product NamewidgetProduct Number123Stock Amt15Reorder Amt10Cost1.5List Price5.0Days to Mfg5Sell Date3/15Discontinue Date9/12
Put button to enter the data into the cache server.
Next, specify the Product ID to update the Java client with the data you entered in the Product Browser form.
In the Java client:
Get
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
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:
Put
ProductId:101Product Name:widgetProduct Number:123Color:BlueStock Level (int):30Reorder Point (int):15Product Cost (double):2.0List Price (double):6.0Available as of (string):6/15Discontinue as of (string):11/12
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.
cacheserver stop -dir=defaultConfig
Now close the cache server session:
exit
End the Java client, then close its session:
exit
exit
Close the .NET client session:
exit
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.
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 gfcpp.properties file into your cli_ProductBrowser directory from the defaultSystem directory. Edit the gfcpp.properties 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:
#cache-xml-file=cache.xml
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.