The GemFire Enterprise native client QuickStart Guide provides a set of examples that demonstrate the capabilities of the GemFire Enterprise native client product. Reviewing the operation of these QuickStart examples, along with studying the source files for the examples, can help you quickly get started with C++ and Microsoft .NET code development for the GemFire Enterprise native client. The examples can be invoked individually from the command line, or by using the QuickStart menu.
The examples and their source files are located in the NativeClient_xxxx\quickstart directory, where xxxx represents the four-digit product version. The C++ examples are in the cpp directory, and the C# examples are in the csharp directory. The Interop example is in its own interop directory. Note that the C# examples are only available for Windows.
Each example has a pair of companion XML files in the XMLs directory that it uses to configure the server and the client. For example, BasicOperations uses serverBasicOperations.xml to configure the cache server and clientBasicOperations.xml to configure the client. Additional support files are stored in the lib directory.
The C++ and C# example files are packaged as Microsoft Visual Studio 2005 solutions (quickstart_cpp.sln and quickstart_csharp.sln), and can be accessed through the IDE or through any editor.
The GemFire Enterprise native client provides access for C++ and Microsoft .NET clients to the GemFire Enterprise distributed system. GemFire Enterprise native clients in C++ and .NET communicate only with the cache server and do not communicate with each other. C++ and .NET native clients provide access to the full region API, including support for application plugins. All of this is transparent to the end user.
This figure provides a conceptual overview of how .NET and C++ applications access the GemFire cache server:

Follow these steps to prepare your system environment to run the QuickStart examples. Throughout this QuickStart Guide, text that you type is shown in bold.
bin/setenv.sh script.bin/setenv script. To enable security in GemFire, the security plugin securityImpl needs to be compiled. The security plugin optionally depends on OpenSSL for its PKCS sample template, so OpenSSL needs to be compiled or installed first.
For Linux and Solaris, you can download the latest tarball archive for OpenSSL. For Windows users, you can get the OpenSSL installer here.
To compile OpenSSL (Linux and Solaris):
Copy the downloaded OpenSSL tarball to your appropriate
LinuxorSunOSfolder atNativeClient_xxxx/templates/security/openssl, then executebuildit.shfrom the shell.To install OpenSSL (Windows):
Run the downloaded OpenSSL installer and accept the default installation path (
C:\OpenSSL).
JAVA_HOME and GF_JAVA_HOME environment variables to your installed JRE or JDK. See the installation information in 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 JRE or JDK installed and you must set JAVA_HOME and GF_JAVA_HOME to point to it. See the Sun Java web site at http://java.sun.com for the latest Java version for your operating system. $JAVA_HOME/bin to the start of your PATH.GFCPP environment variable to point to NativeClient_xxxx.OPENSSL environment variable. For Linux and Solaris, point it to the parent folder for the OpenSSL binaries created from the tarball. For Windows, if you accept the default installation path in step 2, it will be set OPENSSL=C:\OpenSSL\. LD_LIBRARY_PATH environment variable to point to the NativeClient_xxxx/lib directory and $OPENSSL/lib directory for running the Security example.PATH environment variable to point to the NativeClient_xxxx\bin directory and %OPENSSL%\bin directory for running the Security example.The following environment configuration list is a summary of the commands described in steps 1 through 6 that you need to run for the QuickStart Guide. Choose the set of commands that are appropriate for your operating system. The text that you type is shown in bold.
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
% GFCPP=<full path to NativeClient_xxxx>; export GFCPP
% OPENSSL=<parent folder for OpenSSL binaries>; export OPENSSL
% LD_LIBRARY_PATH=$GFCPP/bin:${LD_LIBRARY_PATH}; export LD_LIBRARY_PATH
% LD_LIBRARY_PATH=$OPENSSL/bin:${LD_LIBRARY_PATH}; export LD_LIBRARY_PATH
Windows
> cd GemFireInstallDirectory
> bin\setenv.bat
> set JAVA_HOME=<installed JRE PATH>
> set GF_JAVA_HOME=%JAVA_HOME%
> set GFCPP=C:\NativeClient_xxxx
> set OPENSSL=C:\OpenSSL
> set PATH=%JAVA_HOME%\bin;%GFCPP%\bin;%OPENSSL%\bin;%PATH%
To compile the securityImpl security plugin on Linux and Solaris:
Execute the
buildit.batscript in theNativeClient_xxxx/templates/securitydirectory.
To compile the securityImpl security plugin on Windows:
Execute the
buildit.batscript in theNativeClient_xxxx/templates/securitydirectory.
quickstart directory for the native client:cd NativeClient_xxxx\quickstart
The examples are briefly described in this section. Each example performs the following steps:
Note the messages that appear in the example's session as it runs and performs the steps in the list.
The BasicOperations example puts entries (key and value pairs) into a region, gets entries from the region, invalidates an entry in the region, and destroys an entry in the region.
The BasicOperations example uses the built-in serializable types CacheableInt32 and CacheableString. There are other built-in types which can be used for an entry. Some types can be used as keys or values, while others can only be used as values. The types are listed in the following table:
Cacheable Types For Keys or Values |
Cacheable Types Only For Values |
CacheableInt32 |
CacheableBytes |
CacheableString |
CacheableDoubleArray |
CacheableBoolean |
CacheableFloatArray |
CacheableByte |
CacheableInt16Array |
CacheableDouble |
CacheableInt32Array |
CacheableFloat |
CacheableInt64Array |
CacheableInt16 |
CacheableStringArray |
CacheableInt64 |
CacheableObjectArray |
CacheableWideChar |
CacheableVector |
CacheableDate |
CacheableHashMap |
CacheableFileName |
CacheableHashSet |
You can also provide your own serializable objects. Examples of custom serializable objects are Position and Portfolio in the RemoteQuery example. For more information regarding serialization, refer to the GemFire Enterprise Native Client Guide and the online API documentation for the native client.
The DataExpiration example is configured with an expiration action of destroy that has a 10 second timeout. It performs the following operations:
SimpleCacheListener plugin on a regionSimpleCacheListenerMultiple eviction action options are available, including overflow. For detailed information, see the GemFire Enterprise Native Client Guide.
The LoaderListenerWriter example sets the SimpleCacheLoader, SimpleCacheListener, and SimpleCacheWriter plugins on a region. These plugins report the events that occur during the following region operations:
The RegisterInterest example calls the interest API on a region. These are the functions that are called:
registerAllKeysunregisterAllKeysregisterKeysunregisterKeysregisterRegexunregisterRegexThe RemoteQuery example populates some query objects on a region, executes a query that returns a ResultSet, executes a query that returns a StructSet, and executes the region shortcut query methods.
The Interop example is a simple demonstration that starts a cache server with a C++ client, a C# client, and a Java client to demonstrate their interoperability. The C# client is not started on Linux or Solaris.
Each client populates a single entry on a region, then waits for the other clients to populate their entries. Each client then gets and prints out every entry populated on the server. You might see multiple lines output every second with the message Checking server for keys... displayed while the clients wait for the others to complete their puts. You should eventually see the output from each client printing its own entry and the entries from the other clients.
The Interop example is not included on the QuickStart menu, so it can only be started from the command line. See Running the Interop Example for more information.
The HA Cache example uses client and server XMLs configured to provide high availability functionality for client queues. The example calls the interest API on a region and does simple puts.
The Exceptions example performs some operations in incorrect ways, then logs the exceptions thrown by GemFire to demonstrate error handling.
The DurableClient example demonstrates durable client messaging. If the client loses its connection with a cache server, the primary server and any redundant servers maintain an event queue until the client reconnects. The queued messages are then sent to the client. This example demonstrates the following functionality:
durable-client-id, durable-timeout)readyForEvents cache APIisDurable optionkeepalive optionCacheListener with the afterRegionLive APIThe Security example demonstrates how native client credentials are authenticated when the client connects to a cache server. Authorization for client cache operations is also shown.
You can run the QuickStart examples by starting each C++ or C# example individually from the command line, or by starting the examples from a menu. The menu provides a numbered list of the example names, so you just enter the example number to start it.
The C# examples are only available for Windows.
C++ examples
For Windows:
runcpp ExampleName(for example,runcpp DataExpiration)For Linux or Solaris:
./runcpp.sh ExampleName(for example,./runcpp.sh BasicOperations)C# examples
runcs ExampleName(for example,runcs RemoteQuery)
For Windows:
- Start the C++ menu.
runcpp- Enter a number from the list to start that example.
For Linux or Solaris:
- Start the C++ menu.
./runcpp.sh- Enter a number from the list to start that example
runcs
The
Interopexample can only be run from the command line, so it's not listed on the QuickStart menu. Follow these steps to runInterop.For Windows:
- Start the
Interopexample.
runinterop- When the example has finished, stop the Java cache server by entering this command in the cache server's open terminal session:
cacheserver stop -dir=gfecsFor Linux or Solaris:
- Start the
Interopexample.
./runinterop.sh- When the example has finished, stop the Java cache server by entering this command in the cache server's open terminal session:
cacheserver stop -dir=gfecs
This section discusses problems you might encounter when you run the examples, and suggests corrective actions. If your problems aren't covered or resolved here, please contact GemStone Technical Support:
Web: http://support.gemstone.com
E-mail: support@gemstone.com
Phone: (800) 243-4772 or (503) 533-3503
Exception ... Region:put not connected to GemFire
Verify that the cache server has successfully started by reviewing the
cacheserver.logfile in thegfecsdirectory. The log may indicate why the cache server failed to start.
Exception ... NoClassDefFoundError
This error may appear in the
cacheserver.logfile in thegfecsdirectory. Verify that you have followed all the steps in the Configuring the QuickStart Environment section. You must run thesetenvscript with a leading dot (.) on Linux and Solaris so that the environment settings are made for the current shell. You must also run the example from thequickstartdirectory with theruncpporruncsscripts for theCLASSPATHsetting to work, and so the example can find its XML files.
Exception ... XML file/resource does not exist or not found
This error might appear in the
cacheserver.logfile in thegfecsdirectory, or in the example's screen output. Verify that you have followed all the steps in the Configuring the QuickStart Environment section. You must run the example from thequickstartdirectory with theruncpporruncsscripts so the example can find its XML files.
GemFire is a network-centric distributed system, so if you have a firewall running it could cause connection problems. For example, your connections may fail if your firewall places restrictions on inbound or outbound permissions for sockets. You may need to modify your firewall configuration to permit traffic to applications running on your machine. The specific configuration depends on the firewall you're using.
If you want to build the QuickStart examples yourself from the source files provided, follow these steps:
set GEMFIRE=<full path to the GemFire Enterprise directory>
set GFCPP=NativeClient_xxxx
set JAVA_HOME=<installed JDK PATH>
set PATH=%PATH%;%JAVE_HOME%/bin;%GFCPP%\bin
quickstart directory:
cd %GFCPP%\quickstart
In the command shell, run the appropriate build script for your system. The build script uses the quickstart_cpp.sln and quickstart_csharp.sln Visual Studio solution files in the quickstart directory.
For Windows: .\
buildit.batFor Linux and Solaris:
./buildit.sh
GemStone Systems, Inc.
1260 NW Waterhouse Ave.
Suite 200
Beaverton, OR 97006
Phone: (503) 533-3000 , Fax: (503) 533-3220 , info@gemstone.com , www.gemstone.com
Copyright 2006-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.