Section Summary: C++ applications can communicate with the space by wrapping objects using the C++ projection of the ExternalEntry class, and using the C++ projections of the JavaSpaces methods.
The GigaSpaces C++ interface is based on a C++ projection of the JavaSpaces API. C++ applications can access the space directly using the projected versions of the regular JavaSpaces methods. Objects must be wrapped using the C++ projection of the ExternalEntry class (com::j_spaces::core::client::ExternalEntry; see C++ API Documentation). The C++ package is located at <GigaSpaces Root>/CPP.
Working with Projected Classes
Please note the following when working with GigaSpaces classes projected to C++:
Package names – in the package filenames of Java classes projected to C++, periods change into underscores. For example, the Java package name com.j_spaces.core.client.java becomes com_j_spaces_core_client_pkg.h when you project it into C++.
Namespaces – use normal C++ namespaces when referring to a projected class in the code. For example, to refer to the class SpaceFinder, enter com::j_spaces::core::client::SpaceFinder.
Objects returned by projected classes – C++ methods that are projections of static Java methods always return a generic Java object, regardless of the type of object stated in the header. To cast the object back into the original type, call the dyna_cast method from within the class the object belongs to (all projected C++ classes provide this method). Pass the object as an argument. The method returns the object cast into its original type.
Importing C++ Classes into GigaSpaces
According to the JavaSpaces specification, only Entries can be written to and read from a space. To write C++ objects to a space, you must use the ExternalEntry wrapper, which stores the meta data of a class in a JavaSpaces-compatible format. You can then write this wrapper to the space (see Using ExternalEntry for more details).
You must use the C++ projection of the ExternalEntry class (com::j_spaces::core::client::ExternalEntry; see C++ API Documentation). A JavaSpaces-compatible wrapper is returned to you transparently. You can then call the C++ projection of the Write() method, passing xe (external entry) and the wrapped object as arguments.
Section Contents
CPP Examples — Finding a space; writing to and reading from space; working with transactions; using notifications; working with exceptions.
Java-to-CPP Mapping of Strings — Creating and using a Java String instance; extracting native characters; using strings in printf calls; mixing MFC CString and Java String instances.
We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.
Add Comment