The instructions and command line examples assume that you have extracted the Java Coherence 3.4 archive and the C++ Coherence 3.4 archive onto your file system:
the Java Coherence 3.4 archive was extracted into the top-level of your file system. For example, it would appear as C:\coherence on Windows.
the C++ Coherence 3.4 archive was extracted into the Java Coherence 3.4 root directory. The root directory for the C++ version is coherence-cpp. Thus, on Windows it would appear in the file system as C:\coherence\coherence-cpp.
See Chapter 1, "Requirements, Installation, and Deployment for Coherence for C++" for more information on installing Coherence for C++.
Note:
Coherence C++ does not have any local dependencies on the Java installation. While this section assumes that you have installed both the Java and C++ versions of Coherence on the machine that will be used to run the examples, installation of the Java version is optional. If the Java version is not installed, the Cache Server will need to be running on a remote machine and the Java console example will not be available.Coherence for C++ provides the following sample applications in the coherence-cpp/examples directory of the installed product:
console—A command line application that enables you to interact with the cache using simple commands.
hellogrid—An example of basic cache access.
contacts—An example of how to store pre-existing (that is, non-Coherence) C++ classes in the grid.
The requirements for running a sample include:
The Coherence C++ shared library, found under the platform specific coherence-cpp/lib directory of the installation.
A Coherence extend cache configuration file, found under the coherence-cpp/examples/config directory.
A running Coherence 3.4 Proxy Service and Cache Server; these are Java components.
A sample command to start the proxy service and cache server is listed below. You must be sure to point the proxy at the server cache configuration file, such as extend-server-config.xml provided in the config directory. For example, on Windows execute:
Example 6-1 Sample Command to Start the Proxy Service and the Cache Server
c:\coherence\lib> java -Dtangosol.coherence.cacheconfig=c:\coherence\coherence-cpp\examples\config\extend-server-config.xml -cp coherence.jar "com.tangosol.net.DefaultCacheServer"
Note:
For the contacts example you will also need to use the additional POF configuration and custom classes included in theexamples/java/ContactCache directory.The Coherence for C++ distribution includes platform specific build scripts. Each script takes a single command line parameter, which is the name of the sample to build. For example, to build the console example on Windows, open a new command prompt window and execute:
c:\coherence\coherence-cpp\examples> build console
The sample executable will be created within the particular examples subdirectory, that is:
c:\coherence\coherence-cpp\examples\console\console.exe
Note:
On UNIX platforms you may need to mark the build script as executable firstchmod +x build from the examples directory.Now that configuration has been specified and the proxy/cache server has been started, you can start the client. For example, to run the console example on Windows, run the following command from the examples directory:
c:\coherence\coherence-cpp\examples> run console
The Coherence logging for the application will be directed to console.log in the examples directory.
The console example enables you to enter data into the cache through a C++ console, then read it out through a Java console. Once you start the console example (by running run console), you will be provided with the familiar Map(?): prompt from the console. The C++ console supports a subset of the commands available from Java, enter help to get the list. The caches you can interact with are defined within the extend-cache-config.xml configuration file, but basically all you need to worry about is that local-* caches will be local only, and dist-* caches will be remote and use PIF/POF, and near-* will pull remote data into an in-process coherent near cache.
Enter cache dist-hello to connect to the cache. Enter the commands illustrated in the following example to enter data into the cache and display it.
Map(?): cache dist-hello Map(dist-hello): put hello world NULL Map(dist-hello): get hello world Map(dist-hello): size 1 Map(dist-hello): put from C++ NULL Map(dist-hello): list from = C++ hello = world Map(dist-hello):
Launch a Java console to interact with the C++ console. Note that in the startup command, the Java client application must point to the same cache configuration as the C++ client. For example, on Windows, open a new command prompt window and execute the following command. (Note, the command is broken into two lines for formatting purposes).
c:\coherence\lib> java -Dtangosol.coherence.cacheconfig= c:\coherence\coherence-cpp\examples\config\extend-cache-config.xml -jar coherence.jar
Use the same console syntax that you used in the C++ console to access the cache. For example, on Windows, open a new command prompt window and execute the commands illustrated in the following figure:
Map(?): cache dist-hello
2008-04-25 09:01:02.207 Oracle Coherence GE 3.4/396 Alpha <D5> (thread=DistributedCache, member=3): Service
DistributedCache joined the cluster with senior service member 1
2008-04-25 09:01:02.239 Oracle Coherence GE 3.4/396 Alpha <D5> (thread=DistributedCache, member=3): Service
DistributedCache: received ServiceConfigSync containing 259 entries
<distributed-scheme>
<scheme-name>example-distributed</scheme-name>
<service-name>DistributedCache</service-name>
<lease-granularity>member</lease-granularity>
<backing-map-scheme>
<local-scheme//>
</backing-map-scheme>
<autostart>true
Now that you've run the example, you are encouraged to have a look at the code. See "Sample Code for the console Example". Each sample has a corresponding directory under examples which contains its sample specific source. There is also a common directory which contains source used in all samples.
The hellogrid example exercises the cache by entering various types of data into the cache and reading them out, printing cache contents, querying the cache, and so on. Follow these steps to build and run the hellogrid example:
Stop any instance of the proxy and cache server that may be currently running.
Build the hellogrid example. For example, on Windows, open a new command prompt window and invoke the build file.
C:\coherence\coherence-cpp\examples>build hellogrid building hellogrid\hellogrid.exe ... hellogrid.cpp ContactInfo.cpp PortableContactInfo.cpp StreamParser.cpp Generating Code... C:\coherence\coherence-cpp\examples>
Run the hellogrid example. The window will display output similar to the following:
C:\coherence\coherence-cpp\examples>run hellogrid
retrieved cache "dist-hello" containing 0 entries
put: hello = grid
get: hello = grid
get: dummy = NULL
entire cache contents:
34567 = 8.9
23456 = 7.8
12345 = 6.7
hello = grid
updated cache contents:
34567 = 8.9
23456 = 7.8
12345 = 6.7
45678 = 9.1
filtered cache contents by coherence::util::filter::GreaterFilter: (IdentityExtr
actor, 7)
34567 = 8.9
23456 = 7.8
45678 = 9.1
minimum: 6.7
increment results by 6.7
34567 = 15.6
23456 = 14.5
12345 = 13.4
45678 = 15.8
C:\coherence\coherence-cpp\examples>
Now that you've run the example, you are encouraged to have a look at the code. See "Sample Code for the hellogrid Example". Each sample has a corresponding directory under examples which contains its sample specific source. There is also a common directory which contains source used in all samples.
The contact example enables you to enter names and addresses into the cache, then query to display the entries. The following commands can be run from the example:
help—returns a list of commands that the example can run
bye—stops the example and returns you to the command prompt
create—responds with prompts for a person's contact information: name, street address, city, state, zip code
find—prompts you for a name. The example will return the contact information associated with the name.
Follow these steps to build and run the contacts example:
Stop any instance of the proxy and cache server that may be currently running.
Build the contacts example. For example, on Windows, open a new command prompt window and invoke the build file.
C:\coherence\coherence-cpp\examples>build contacts building contacts\contacts.exe ... contacts.cpp ContactInfo.cpp PortableContactInfo.cpp StreamParser.cpp Generating Code... C:\coherence\coherence-cpp\examples>
Run the contacts example. The window will display output similar to the following:
C:\coherence\coherence-cpp\examples>run contacts contacts> help commands are: bye create find <street | city | state | zip | all> contacts>
Exercise the example by entering the commands help, create, find, and bye.
contacts> help commands are: bye create find <street | city | state | zip | all> contacts> create Name: Tom Street: Oracle Parkway City: Redwood Shores State: California Zip: 94065 storing: ContactInfo(Name=Tom, Street=Oracle Parkway, City=Redwood Shores, State =California, Zip=94065) contacts> find Name: Tom ContactInfo(Name=Tom, Street=Oracle Parkway, City=Redwood Shores, State=California, Zip=94065) contacts> bye C:\coherence\coherence-cpp\examples>
Now that you've run the example, you are encouraged to have a look at the code. See "Sample Code for the contacts Example". Each sample has a corresponding directory under examples which contains its sample specific source. There is also a common directory which contains source used in all samples.