/* * The RegisterInterest QuickStart Example. * * This example takes the following steps: * * 1. Connect to a GemFire Distributed System. * 2. Create a GemFire Cache. * 3. Get the example Region from the Cache. * 4. Call registerAllKeys() and unregisterAllKeys() on the Region. * 5. Call registerKeys() and unregisterKeys() on the Region. * 6. Call registerRegex() and unregisterRegex() on the Region. * 7. Close the Cache. * 8. Disconnect from the Distributed System. * */ // Include the GemFire library. #include // Use the "gemfire" namespace. using namespace gemfire; // The RegisterInterest QuickStart example. int main(int argc, char ** argv) { try { // Connect to the GemFire Distributed System using the settings from the gfcpp.properties file by default. DistributedSystemPtr dSysPtr = DistributedSystem::connect("ExampleDistributedSystem"); LOGINFO("Connected to the GemFire Distributed System"); // Create a GemFire Cache with the "clientRegisterInterest.xml" Cache XML file. CachePtr cachePtr = CacheFactory::create("ExampleCache", dSysPtr, "XMLs/clientRegisterInterest.xml"); LOGINFO("Created the GemFire Cache"); // Get the example Region from the Cache which is declared in the Cache XML file. RegionPtr regionPtr = cachePtr->getRegion("/root/exampleRegion"); LOGINFO("Obtained the Region from the Cache"); // Register and Unregister Interest on Region for All Keys. regionPtr->registerAllKeys(); regionPtr->unregisterAllKeys(); LOGINFO("Called registerAllKeys() and unregisterAllKeys()"); // Register and Unregister Interest on Region for Some Keys. VectorOfCacheableKey keys; keys.push_back( CacheableInt32::create(123) ); keys.push_back( CacheableString::create("Key-123") ); regionPtr->registerKeys(keys); regionPtr->unregisterKeys(keys); LOGINFO("Called registerKeys() and unregisterKeys()"); // Register and Unregister Interest on Region for Keys matching a Regular Expression. regionPtr->registerRegex("Keys-*"); regionPtr->unregisterRegex("Keys-*"); LOGINFO("Called registerRegex() and unregisterRegex()"); //Register Interest on Region for All Keys with getInitialValues to populate the cache with values of all keys from the server. regionPtr->registerAllKeys(false, NULLPTR, true); // Where the 3rd argument is getInitialValues. //Unregister Interest on Region for All Keys. regionPtr->unregisterAllKeys(); LOGINFO("Called registerAllKeys() and unregisterAllKeys() with getInitialValues argument"); //Register Interest on Region for Some Keys with getInitialValues. keys.push_back( CacheableInt32::create(123) ); keys.push_back( CacheableString::create("Key-123") ); regionPtr->registerKeys(keys, false, true); // Where the 3rd argument is getInitialValues. LOGINFO("Called registerKeys() and unregisterKeys() with getInitialValues argument"); //Unregister Interest on Region for Some Keys. regionPtr->unregisterKeys(keys); //Register and Unregister Interest on Region for Keys matching a Regular Expression with getInitialValues. regionPtr->registerRegex("Keys-*", false, NULLPTR, true); regionPtr->unregisterRegex("Keys-*"); LOGINFO("Called registerRegex() and unregisterRegex() with getInitialValues argument"); // Close the GemFire Cache. cachePtr->close(); LOGINFO("Closed the GemFire Cache"); // Disconnect from the GemFire Distributed System. dSysPtr->disconnect(); LOGINFO("Disconnected from the GemFire Distributed System"); } // An exception should not occur catch(const Exception & gemfireExcp) { LOGERROR("RegisterInterest GemFire Exception: %s", gemfireExcp.getMessage()); } }