Search in sources :

Example 96 with CacheClosedException

use of org.apache.geode.cache.CacheClosedException 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)

Aggregations

CacheClosedException (org.apache.geode.cache.CacheClosedException)96 Cache (org.apache.geode.cache.Cache)26 Test (org.junit.Test)21 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)20 FunctionException (org.apache.geode.cache.execute.FunctionException)20 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)20 CancelException (org.apache.geode.CancelException)18 Region (org.apache.geode.cache.Region)18 Host (org.apache.geode.test.dunit.Host)17 VM (org.apache.geode.test.dunit.VM)17 InternalCache (org.apache.geode.internal.cache.InternalCache)16 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)16 DistributedMember (org.apache.geode.distributed.DistributedMember)14 ReplyException (org.apache.geode.distributed.internal.ReplyException)14 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)12 Execution (org.apache.geode.cache.execute.Execution)11 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)11 HashMap (java.util.HashMap)10