/* * The HA QuickStart Example. * * This example takes the following steps: * * 1. Connect to a GemFire Distributed System which has two cache servers. * 2. Create a GemFire Cache with redundancy level = 1. * 3. Get the example Region from the Cache. * 4. Call registerKeys() on the Region. * 5. Call registerRegex() on the Region. * 6. Put two keys in the Region. * 7. Verify that the keys are destroyed via expiration in server. * 8. Close the Cache. * 9. Disconnect from the Distributed System. * */ // Include the GemFire library. #include // Use the "gemfire" namespace. using namespace gemfire; // The HA 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 "clientHACache.xml" Cache XML file. CachePtr cachePtr = CacheFactory::create("ExampleCache", dSysPtr, "XMLs/clientHACache.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 Some Keys. VectorOfCacheableKey keys; CacheableKeyPtr key1 = CacheableInt32::create(123); CacheableKeyPtr key2 = CacheableString::create("Key-123"); keys.push_back( key1 ); keys.push_back( key2 ); regionPtr->registerKeys(keys); regionPtr->registerRegex("Key.*"); LOGINFO("Called registerKeys() and registerKeysRegex()"); regionPtr->put(key1, 1); regionPtr->put(key2, 2); LOGINFO("Called put() on Region"); LOGINFO("Waiting for updates on keys"); millisleep(10000); int count=0; if (regionPtr->get(key1) == NULLPTR) { LOGINFO("Verified that key1 has been destroyed"); count++; } if (regionPtr->get(key2) == NULLPTR) { LOGINFO("Verified that key2 has been destroyed"); count++; } if (count == 2) { LOGINFO("Verified all updates"); } else { LOGINFO("Could not verify all updates"); } regionPtr->unregisterKeys(keys); regionPtr->unregisterRegex("Key.*"); LOGINFO("Unregistered keys"); // 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("HACache GemFire Exception: %s", gemfireExcp.getMessage()); } }