|
Summary: Finding a space; writing to and reading from space; working with transactions; using notifications; working with exceptions.
OverviewThis section is based on the hello-world example, located at <GigaSpaces Root/CPP directory. Finding a SpaceTo locate a space, use the SpaceFinder class defined in com_j_spaces_core_client_pkg.h. The code snippet example below illustrates the use of this class in C++: include "net_jini_space_pkg.h" #include "com_j_spaces_core_client_pkg.h" #include "com_j_spaces_core_pkg.h" #include "java_lang_pkg.h" #include "java_rmi_pkg.h" #include "net_jini_core_lease_pkg.h" #include "net_jini_core_transaction_pkg.h" #include "net_jini_core_event_pkg.h" ... java::lang::String spaceURL(argv[1]); Object obj = SpaceFinder::find(spaceURL); IJSpace m_Space = IJSpace::dyna_cast(obj); ... The SpaceFinder class provides a static method called find, which returns a reference to a space object. Writing to and Reading from a Space
GigaSpaces supports transactional processing based on the Jini Transaction Specification. The code snippet example below shows a transactional write operation: ... LocalTransactionManager ltm(m_Space); Transaction::Created tCreated = TransactionFactory::create(ltm, 3600 * 1000); Transaction txn(*(tCreated.transaction)); m_Space.write(*pxe, txn, Lease::FOREVER); txn.commit(); ... Local Transaction Manager is a GigaSpaces implementation of the Jini Transaction Manager. It is located in com_j_space_core_client_pkg.h. After the operation is completed, the transaction can be committed, as evident in the final line of the code above. Using NotificationsGigaSpaces lets you create event-driven applications based on the JavaSpaces notification mechanism. GigaSpaces provides a special class, NotifyDelegator that functions as an interface, to which the GigaSpaces server can connect, in order to transmit notifications. This method is located in com_j_space_core_client_pkg.h. The steps for this process are described below:
Working with ExceptionsGigaSpaces C++ supports the handling of Java exception in C++ code. The code snippet example below demonstrates the use of exceptions: ... FinderException fe; IJSpace m_Space; try { java::lang::String spaceURL(argv[1]); Object obj = SpaceFinder::find(spaceURL); m_Space = IJSpace::dyna_cast(obj); } catch(FinderException e) { e.printStackTrace(); exit(-1); } ... Two crucial points regarding exceptions:
|
Wiki Content Tree
Your Feedback Needed!
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