Search in sources :

Example 91 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory in project calcite by apache.

the class GeodeUtils method createClientCache.

/**
 * Creates a Geode client instance connected to locator and configured to
 * support PDX instances.
 *
 * <p>If an old instance exists, it will be destroyed and re-created.
 *
 * @param locatorHost               Locator's host address
 * @param locatorPort               Locator's port
 * @param autoSerializerPackagePath package name of the Domain classes loaded in the regions
 * @return Returns a Geode {@link ClientCache} instance connected to Geode cluster
 */
public static synchronized ClientCache createClientCache(String locatorHost, int locatorPort, String autoSerializerPackagePath, boolean readSerialized) {
    if (locatorPort != currentLocatorPort || !StringUtils.equalsIgnoreCase(currentLocatorHost, locatorHost)) {
        LOGGER.info("Close existing ClientCache [" + currentLocatorHost + ":" + currentLocatorPort + "] for new Locator connection at: [" + locatorHost + ":" + locatorPort + "]");
        currentLocatorHost = locatorHost;
        currentLocatorPort = locatorPort;
        closeClientCache();
    }
    try {
        // client proxy regions can also be resolved from the regionMap
        return ClientCacheFactory.getAnyInstance();
    } catch (CacheClosedException cce) {
    // Do nothing if there is no existing instance
    }
    return new ClientCacheFactory().addPoolLocator(locatorHost, locatorPort).setPdxSerializer(new ReflectionBasedAutoSerializer(autoSerializerPackagePath)).setPdxReadSerialized(readSerialized).setPdxPersistent(false).create();
}
Also used : ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 92 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory in project calcite by apache.

the class BookMasterRegionTest method main.

public static void main(String[] args) throws Exception {
    ClientCache clientCache = new ClientCacheFactory().addPoolLocator("localhost", 10334).setPdxSerializer(new ReflectionBasedAutoSerializer("org.apache.calcite.adapter.geode.*")).create();
    // Using Key/Value
    Region bookMaster = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("BookMaster");
    System.out.println("BookMaster = " + bookMaster.get(789));
    // Using OQL
    QueryService queryService = clientCache.getQueryService();
    String oql = "select itemNumber, description, retailCost from /BookMaster";
    SelectResults result = (SelectResults) queryService.newQuery(oql).execute();
    System.out.println(result.asList());
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Aggregations

ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)92 ClientCache (org.apache.geode.cache.client.ClientCache)67 Test (org.junit.Test)45 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)44 VM (org.apache.geode.test.dunit.VM)42 Host (org.apache.geode.test.dunit.Host)40 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)40 Region (org.apache.geode.cache.Region)38 Properties (java.util.Properties)24 QueryService (org.apache.geode.cache.query.QueryService)23 SelectResults (org.apache.geode.cache.query.SelectResults)23 CacheServer (org.apache.geode.cache.server.CacheServer)22 Cache (org.apache.geode.cache.Cache)19 CacheException (org.apache.geode.cache.CacheException)14 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)13 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)13 IOException (java.io.IOException)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)12 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)11 PdxInstance (org.apache.geode.pdx.PdxInstance)10