/* * The PutAllGetAllOperations QuickStart Example. * * This example takes the following steps: * * 1. Connect to a GemFire Distributed System. * 2. Create a GemFire Cache. * 3. Create a Example Region. * 4. Get the example Region from the Cache. * 5. PutAll Entries (Key and Value pairs) into the Region. * 6. GetAll Entries from 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 PutAllGetAllOperations 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. CachePtr cachePtr = CacheFactory::create("ExampleCache", dSysPtr); LOGINFO("Created the GemFire Cache"); //Create Region Attributes AttributesFactory af; af.setCachingEnabled(true); af.setEndpoints("localhost:40404"); af.setClientNotificationEnabled(true); RegionAttributesPtr regAttrsPtr = af.createRegionAttributes( ); //Create exampleRegion. cachePtr->createRegion( "exampleRegion", regAttrsPtr ); // Get the example Region from the Cache. RegionPtr regionPtr = cachePtr->getRegion("exampleRegion"); LOGINFO("Obtained the Region from the Cache"); // Put bulk Entries (Key and Value pairs) into the Region. HashMapOfCacheable entryMap; char key[2048]; char value[2048]; for (int32_t item = 0; item < 100; item++) { sprintf(key, "key-%d", item); sprintf(value, "%d", item); entryMap.insert(CacheableKey::create(key), CacheableString::create(value)); } regionPtr->putAll(entryMap); LOGINFO("PutAll 100 entries into the Region"); //GetAll Entries back out of the Region VectorOfCacheableKey keys; for (int32_t item = 0; item < 100; item++) { sprintf(key, "key-%d", item); keys.push_back(CacheableKey::create(key)); } HashMapOfCacheablePtr values(new HashMapOfCacheable()); regionPtr->getAll(keys, values, NULLPTR, true); LOGINFO("Obtained 100 entries from the Region"); // 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("PutAllGetAllOperations GemFire Exception: %s", gemfireExcp.getMessage()); } }