Running the Connection Pool Code

Examples demonstrate a simple procedure to create a pool factory and then create a pool instance in C++. They also help you to execute a query.

Ensure that you create a pool with locators or endpoints, but not both. The first example demonstrates creating a pool by adding locators. The second example demonstrates creating a pool by adding servers.

C++ Connection Pool Creation and Execution Using Locators

PropertiesPtr prptr = Properties::create();
systemPtr = CacheFactory::createCacheFactory(prptr);

cachePtr = systemPtr->create();
PoolFactoryPtr poolFacPtr = PoolManager::createFactory();
// Add pool with locator to create pool factory
poolFacPtr->addLocator("localhost", 34756 /*port number*/);
PoolPtr pptr = NULLPTR;
if ((PoolManager::find("examplePool")) == NULLPTR) {
  // Pool with this name does not exist
  pptr = poolFacPtr->create("examplePool");
}
RegionFactoryPtr regionFactory =
    cachePtr->createRegionFactory(CACHING_PROXY);
regionPtr = regionFactory
    ->setPoolName("examplePool")
    ->create("regionName");
QueryServicePtr qs = cachePtr->getQueryService("examplePool");

C++ Connection Pool Creation and Execution Using Servers

PropertiesPtr prptr = Properties::create();
systemPtr = CacheFactory::createCacheFactory(prptr);

cachePtr = systemPtr->create();
PoolFactoryPtr poolFacPtr = PoolManager::createFactory();
// Add pool with endpoint to create pool factory
poolFacPtr->addServer("localhost", 12345 /*port number*/);
PoolPtr pptr = NULLPTR;
if ((PoolManager::find("examplePool")) == NULLPTR) {
  // Pool with this name does not exist
  pptr = poolFacPtr->create("examplePool");
}
RegionFactoryPtr regionFactory =
    cachePtr->createRegionFactory(CACHING_PROXY);
regionPtr = regionFactory
    ->setPoolName("examplePool")
    ->create("regionName");
QueryServicePtr qs = cachePtr->getQueryService("examplePool");