项目作者: oracle

项目描述 :
Coherence C++ client library
高级语言: C++
项目地址: git://github.com/oracle/coherence-cpp-extend-client.git
创建时间: 2020-02-27T17:04:15Z
项目社区:https://github.com/oracle/coherence-cpp-extend-client

开源协议:Other

下载



CI Build
License

Oracle Coherence for C++ Community Edition

Contents

  1. Introduction to Coherence
  2. How to Get Coherence Community Edition
  3. Introduction to Coherence for C++
  4. Building
  5. CLI Hello Coherence Example
  6. Programmatic Hello Coherence Example
  7. Testing
  8. Documentation
  9. Contributing

Introduction to Coherence" class="reference-link">Introduction to Coherence

Coherence is a scalable, fault-tolerant, cloud-ready,
distributed platform for building grid-based applications and reliably storing data.
The product is used at scale, for both compute and raw storage, in a vast array of
industries such as critical financial trading systems, high performance telecommunication
products and eCommerce applications.

Typically these deployments do not tolerate any downtime and Coherence is chosen due to its
novel features in death detection, application data evolvability, and the robust,
battle-hardened core of the product that enables it to be seamlessly deployed and
adapted within any ecosystem.

At a high level, Coherence provides an implementation of the familiar Map
interface but rather than storing the associated data in the local process it is partitioned
(or sharded) across a number of designated remote nodes. This partitioning enables
applications to not only distribute (and therefore scale) their storage across multiple
processes, machines, racks, and data centers but also to perform grid-based processing
to truly harness the CPU resources of the machines.

The Coherence interface NamedCache (an extension of Map) provides methods
to query, aggregate (map/reduce style) and compute (send functions to storage nodes
for locally executed mutations) the data set. These capabilities, in addition to
numerous other features, enable Coherence to be used as a framework for writing robust,
distributed applications.

How to Get Coherence Community Edition" class="reference-link">How to Get Coherence Community Edition

For more details on how to obtain and use Coherence, please see the Coherence CE README.

Introduction to Coherence for C++" class="reference-link">Introduction to Coherence for C++

Coherence for C++ allows C++ applications to access Coherence clustered services, including data,
data events, and data processing from outside the Coherence cluster. Typical uses of Coherence
for C++ include desktop and web applications that require access to Coherence caches.

Coherence for C++ consists of a native C++ library that connects to a Coherence*Extend clustered
service instance running within the Coherence cluster using a high performance TCP/IP-based
communication layer. This library sends all client requests to the Coherence*Extend clustered
service which, in turn, responds to client requests by delegating to an actual Coherence
clustered service (for example, a partitioned or replicated cache service).

A NamedCache instance is retrieved by using the CacheFactory::getCache(...) API call.
After it is obtained, a client accesses the NamedCache in the same way as it would if it
were part of the Coherence cluster. The fact that NamedCache operations are being sent to a
remote cluster node (over TCP/IP) is completely transparent to the client application.

NOTE: The C++ client follows the interface and concepts of the Java client, and
users familiar with Coherence for Java should find migrating to Coherence for C++ straightforward.

See Developing Remote Clients for Oracle Coherence
for further details.

Building" class="reference-link">Building

Prerequisites

  1. A supported hardware platform and C++ compiler. See Supported Environments for Coherence C++ Client.
  2. Oracle Java 8 JDK
  3. Apache Ant version 1.7.0 or later
  4. Ant-Contrib version 1.0b3
  5. Ant-Contrib cpptasks version 1.0b4

Building the shared library

The Coherence for C++ build system is based on Ant. To build Coherence for C++:

  1. Clone this repository
  2. Download Apache Ant version 1.7.0 or later and install it at tools/internal/common/ant
  3. Download ant-contrib-1.0b3.jar and install it at tools/internal/common/ant-contrib/lib
  4. Download cpptasks-1.0b4.jar and install it at tools/internal/common/ant-contrib/lib
  5. Set the JAVA_HOME environment variable to point to the Oracle JDK 8 home
  6. cd bin
  7. On unix flavor platforms source cfglocal.sh from a bash shell (e.g. . cfglocal.sh). On windows open a Visual Studio native tools command prompt and run cfgwindows.cmd
  8. cd ../prj/coherence
  9. ant -Dbuild.type=release clean build dist - can take from 20 minutes to over an hour depending on platform type and CPU speed

The resulting files:

  • dist/14.1.2.0.0b0/include - the public header files
  • dist/14.1.2.0.0b0/lib - the Coherence for C++ shared library

CLI Hello Coherence Example" class="reference-link">CLI Hello Coherence Example

The following example illustrates starting a storage enabled Coherence Server,
followed by a Coherence for C++ console application. Using the console, data is
inserted and retrieved. The console is then terminated and restarted and data is once again
retrieved to illustrate the permanence of the data.

Prerequisites

  1. The Coherence for C++ shared library see Building
  2. Coherence Community Edition coherence.jar

Build Sanka

Sanka is a command line tool which can be used to run the main method on Coherence C++ classes

  1. Set the JAVA_HOME environment variable to point to the Oracle JDK 8 home
  2. cd bin
  3. On unix flavor platforms source cfglocal.sh from a bash shell (e.g. . cfglocal.sh). On windows open a Visual Studio native tools command prompt and run cfgwindows.cmd
  4. cd ../prj/sanka
  5. ant -Dbuild.type=release build dist

Start a Coherence server

Unix shell:

```shell script
$JAVA_HOME/bin/java -Dcoherence.pof.enabled=true -Dcoherence.log.level=6 -jar coherence.jar

  1. Windows command prompt:
  2. ```shell script
  3. "%JAVA_HOME%/bin/java" -Dcoherence.pof.enabled=true -Dcoherence.log.level=6 -jar coherence.jar

Run the coherence::net::CacheFactory::main() (console) using sanka

Unix shell:

```shell script
cd dist/14.1.2.0.0b0/bin
./sanka -l ../lib/libcoherence.so coherence::net::CacheFactory

  1. Windows command prompt:
  2. ```shell script
  3. .\sanka -l ..\lib\coherence.dll coherence::net::CacheFactory

Console:

```shell script
Map (?): cache welcomes

Map (welcomes): get english
NULL

Map (welcomes): put english Hello
NULL

Map (welcomes): put spanish Hola
NULL

Map (welcomes): put french Bonjour
NULL

Map (welcomes): get english
Hello

Map (welcomes): list
french = Bonjour
english = Hello
spanish = Hola

Map (welcomes): bye

  1. Start the console again
  2. Unix shell:
  3. ```shell script
  4. ./sanka -l ../lib/libcoherence.so coherence::net::CacheFactory

Windows command prompt:

```shell script
.\sanka -l ..\lib\coherence.dll coherence::net::CacheFactory

  1. Console:
  2. ```shell script
  3. Map (?): cache welcomes
  4. Map (welcomes): list
  5. french = Bonjour
  6. english = Hello
  7. spanish = Hola

Programmatic Hello Coherence Example" class="reference-link">Programmatic Hello Coherence Example

The following example illustrates starting a storage enabled Coherence server,
followed by running the HelloCoherence application. The HelloCoherence application
inserts and retrieves data from the Coherence server.

Prerequisites

  1. The Coherence for C++ shared library see Building
  2. Coherence Community Edition coherence.jar

Build HelloCoherence

Copy and paste the following source to a file named HelloCoherence.cpp:

  1. #include "coherence/lang.ns"
  2. #include "coherence/net/CacheFactory.hpp"
  3. #include "coherence/net/NamedCache.hpp"
  4. #include "coherence/util/Iterator.hpp"
  5. #include <iostream>
  6. using namespace coherence::lang;
  7. using coherence::net::CacheFactory;
  8. using coherence::net::NamedCache;
  9. using coherence::util::Iterator;
  10. int main()
  11. {
  12. try
  13. {
  14. // access/create the "welcomes" cache in the Coherence cluster
  15. NamedCache::Handle hCache = CacheFactory::getCache("welcomes");
  16. std::cout << "Accessing cache \"" << hCache->getCacheName()
  17. << "\" containing " << hCache->size() << " entries"
  18. << std::endl;
  19. hCache->put(String::create("english"), String::create("Hello"));
  20. hCache->put(String::create("spanish"), String::create("Hola"));
  21. hCache->put(String::create("french"), String::create("Bonjour"));
  22. // list
  23. for (Iterator::Handle hIterator = hCache->entrySet()->iterator();
  24. hIterator->hasNext(); )
  25. {
  26. std::cout << hIterator->next() << std::endl;
  27. }
  28. // disconnect from the Coherence cluster
  29. CacheFactory::shutdown();
  30. }
  31. catch (const std::exception& e)
  32. {
  33. std::cerr << "error: " << e.what() << std::endl;
  34. return 1;
  35. }
  36. return 0;
  37. }

Compile HelloCoherence.cpp using the Coherence for C++ header files and shared library:

Using GCC on Linux and macOS:

```shell script
g++ -Idist/14.1.2.0.0b0/include -lcoherence -L dist/14.1.2.0.0b0/lib -o HelloCoherence HelloCoherence.cpp

  1. From a Visual Studio native tools command prompt on Windows:
  2. ```shell script
  3. cl -Idist\14.1.2.0.0b0\include dist\14.1.2.0.0b0\lib\coherence.lib -o HelloCoherence HelloCoherence.cpp

Start a Coherence server

Unix shell:

```shell script
$JAVA_HOME/bin/java -Dcoherence.pof.enabled=true -Dcoherence.log.level=6 -jar coherence.jar

  1. Windows command prompt:
  2. ```shell script
  3. "%JAVA_HOME%/bin/java" -coherence.pof.enabled=true -Dcoherence.log.level=6 -jar coherence.jar

Run HelloCoherence

Unix shell:

```shell script
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:dist/14.1.2.0.0b0/lib
./HelloCoherence

  1. Windows command prompt:
  2. ```shell script
  3. set PATH=%DEV_ROOT%\dist\14.1.2.0.0b0\lib;%PATH%
  4. HelloCoherence

Testing" class="reference-link">Testing

Coherence for C++ has unit and functional tests to validate builds and code changes.

Prerequisites

  1. The Coherence for C++ shared library see Building
  2. Perl
  3. Download CxxTest version 3.10.1 and install it at tools/internal/common/cxxtest
  4. Comment out the -Werror flag in prj/build-import.xml
    (e.g. <!-- compilerarg if="cc.g++" value="-Werror"/ -->) as CxxTest source
    files will produce warnings when compiling with GCC

Building and running the tests

  1. Set the JAVA_HOME environment variable to point to the Oracle JDK 8 home
  2. cd bin
  3. On unix flavor platforms source cfglocal.sh from a bash shell (e.g. . cfglocal.sh). On windows open a Visual Studio native tools command prompt and run cfgwindows.cmd

shell script cd ../prj/tests/unit (or cd ../prj/tests/functional) ant -Dbuild.type=release build test

Contributing

Interested in contributing? See our contribution guidelines for details.

Security

Please consult the security guide for our responsible security vulnerability disclosure process