/* * The PoolWithEndpoints QuickStart Example. * * This example takes the following steps: * * 1. Connect to a GemFire Distributed System. * 2. Create a GemFire Cache. * 3. Creates pool factory to create the Pool. * 4. Adds server to pool factory. * 5. Then create pool with poolname "examplePool". * 6. Creates region with pool. And then creates subregion with pool. * 7. Put Entries (Key and Value pairs) into the Region. * 8. Get Entries from the Region. * 9. Invalidate an Entry in the Region. * 10. Destroy an Entry in the Region. * 11. Close the Cache. * 12. Disconnect from the Distributed System. * */ // Include the GemFire library. #include // Use the "gemfire" namespace. using namespace gemfire; // The PoolWithEndpoints 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 pool factory to create the pool. PoolFactoryPtr poolFacPtr = PoolManager::createFactory(); //adding host(endpoint) in pool poolFacPtr->addServer("localhost", 40404); //enabling subscription on pool poolFacPtr->setSubscriptionEnabled(true); //creating pool with name "examplePool" poolFacPtr->create("examplePool"); //now creating region with pool AttributesFactory af; af.setCachingEnabled( true ); //setting pool to attach with region af.setPoolName("examplePool"); RegionAttributesPtr rattrsPtr = af.createRegionAttributes( ); //creating first root region RegionPtr parentRegionPtr = cachePtr->createRegion( "root", rattrsPtr ); //Now creating subregion of region root RegionPtr regionPtr = parentRegionPtr->createSubregion( "exampleRegion", rattrsPtr ); LOGINFO("Created Region."); // Put an Entry (Key and Value pair) into the Region using the direct/shortcut method. regionPtr->put("Key1", "Value1"); LOGINFO("Put the first Entry into the Region"); // Put an Entry into the Region by manually creating a Key and a Value pair. CacheableKeyPtr keyPtr = CacheableInt32::create(123); CacheablePtr valuePtr = CacheableString::create("123"); regionPtr->put(keyPtr, valuePtr); LOGINFO("Put the second Entry into the Region"); // Get Entries back out of the Region. CacheablePtr result1Ptr = regionPtr->get("Key1"); LOGINFO("Obtained the first Entry from the Region"); CacheablePtr result2Ptr = regionPtr->get(keyPtr); LOGINFO("Obtained the second Entry from the Region"); // Invalidate an Entry in the Region. regionPtr->invalidate("Key1"); LOGINFO("Invalidated the first Entry in the Region"); // Destroy an Entry in the Region. regionPtr->destroy(keyPtr); LOGINFO("Destroyed the second Entry in 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("PoolWithEndpoints GemFire Exception: %s", gemfireExcp.getMessage()); } }