UpgradeSample.cpp shows usage of the V10 API, with examples of the V9 API provided for comparison.

#include <iostream>
#include <thread>

#include <geode/CacheFactory.hpp>
#include <geode/PoolManager.hpp>
#include <geode/RegionFactory.hpp>
#include <geode/RegionShortcut.hpp>

using namespace apache::geode::client;

int main(int argc, char** argv) {
    try {

	    // *** Create the cache *********************************************************

	    // OLD:
	    //   CacheFactoryPtr cacheFactory = CacheFactory::createCacheFactory();
	    //   CachePtr cachePtr = cacheFactory->create();

	    // NEW:
	    auto cacheFactory = CacheFactory();
	    auto cache = cacheFactory.create();

	    // *** Create the region ********************************************************

	    // OLD:
	    //  RegionFactoryPtr regionFactory = cachePtr->createRegionFactory(CACHING_PROXY);
	    //  RegionPtr regionPtr = regionFactory->create("exampleRegion");

	    // NEW: (pool required)
	    auto poolFactory = cache.getPoolManager().createFactory();
	    auto pool = poolFactory.addLocator("localhost", 10334).create("pool");
	    auto regionFactory = cache.createRegionFactory(RegionShortcut::PROXY);
	    auto region = regionFactory.setPoolName("pool").create("exampleRegion");

	    // *** Put constant data into the region ****************************************

	    // OLD:
	    //regionPtr->put("blue", "The color of the sky");

	    // NEW:
	    region->put("blue", "The color of the sky");

	    // *** Put variable data into the region ****************************************

	    // OLD:
	    // CacheableKeyPtr keyPtr = CacheableString::create("green");
	    // CacheablePtr valuePtr = CacheableString::create("The color of life");
	    // regionPtr->put(keyPtr, valuePtr);

	    // NEW:
	    auto key = CacheableString::create("green");
	    auto value = CacheableString::create("The color of life");
	    region->put(key, value);

	    // *** Get data from the region *************************************************

	    // OLD:
	    //CacheablePtr result1Ptr = regionPtr->get("Key1");
	    //CacheablePtr result2Ptr = regionPtr->get(keyPtr);

	    // NEW:
	    auto result1 = region->get("Key1");
	    auto result2 = region->get(key);

	    // *** Invalidate an Entry in the Region ****************************************

	    // OLD:
	    //regionPtr->invalidate("Key1");
	    //regionPtr->invalidate(keyPtr);

	    // NEW:
	    region->invalidate("Key1");
	    region->invalidate(key);

	    // *** Destroy an Entry in the Region *******************************************

	    // OLD:
	    //regionPtr->destroy("Key1");
	    //regionPtr->destroy(keyPtr);

	    // NEW:
	    region->destroy("Key1");
	    region->destroy(key);

	    // *** Close the cache **********************************************************

	    // OLD:
	    //cachePtr->close();

	    // NEW:
	    cache.close();
    }
    catch (Exception ex) {}
}
check-circle-line exclamation-circle-line close-line
Scroll to top icon