SGF-441 - Fix possible CacheClosedException in ClientCacheFactoryBean onApplicationEvent(:ContextRefreshedEvent) when the ClientCache initialization is lazy.
This commit is contained in:
@@ -21,6 +21,8 @@ import java.util.concurrent.ConcurrentMap;
|
||||
import org.springframework.data.gemfire.util.DistributedSystemUtils;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheClosedException;
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
@@ -34,6 +36,12 @@ import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.util.DistributedSystemUtils
|
||||
* @see com.gemstone.gemfire.cache.Cache
|
||||
* @see com.gemstone.gemfire.cache.CacheFactory
|
||||
* @see com.gemstone.gemfire.cache.Region
|
||||
* @see com.gemstone.gemfire.cache.client.ClientCache
|
||||
* @see com.gemstone.gemfire.cache.client.ClientCacheFactory
|
||||
* @see com.gemstone.gemfire.distributed.DistributedSystem
|
||||
* @since 1.3.3
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@@ -42,7 +50,7 @@ public abstract class GemfireUtils extends DistributedSystemUtils {
|
||||
public final static String GEMFIRE_VERSION = CacheFactory.getVersion();
|
||||
|
||||
public static boolean isDurable(ClientCache clientCache) {
|
||||
DistributedSystem distributedSystem = clientCache.getDistributedSystem();
|
||||
DistributedSystem distributedSystem = getDistributedSystem(clientCache);
|
||||
|
||||
// NOTE technically the following code snippet would be more useful/valuable but is not "testable"!
|
||||
//((InternalDistributedSystem) distributedSystem).getConfig().getDurableClientId();
|
||||
@@ -71,7 +79,25 @@ public abstract class GemfireUtils extends DistributedSystemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isGemfireVersionGreaterThanEqual(double expectedVersion) {
|
||||
public static Cache getCache() {
|
||||
try {
|
||||
return CacheFactory.getAnyInstance();
|
||||
}
|
||||
catch (CacheClosedException ignore) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ClientCache getClientCache() {
|
||||
try {
|
||||
return ClientCacheFactory.getAnyInstance();
|
||||
}
|
||||
catch (CacheClosedException ignore) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isGemfireVersionGreaterThanEqualTo(double expectedVersion) {
|
||||
double actualVersion = Double.parseDouble(GEMFIRE_VERSION.substring(0, 3));
|
||||
return actualVersion >= expectedVersion;
|
||||
}
|
||||
@@ -90,7 +116,7 @@ public abstract class GemfireUtils extends DistributedSystemUtils {
|
||||
|
||||
public static boolean isGemfireVersion7OrAbove() {
|
||||
try {
|
||||
return isGemfireVersionGreaterThanEqual(7.0);
|
||||
return isGemfireVersionGreaterThanEqualTo(7.0);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// NOTE the com.gemstone.gemfire.distributed.ServerLauncher class only exists in GemFire v 7.0.x or above...
|
||||
@@ -101,7 +127,7 @@ public abstract class GemfireUtils extends DistributedSystemUtils {
|
||||
|
||||
public static boolean isGemfireVersion8OrAbove() {
|
||||
try {
|
||||
return isGemfireVersionGreaterThanEqual(8.0);
|
||||
return isGemfireVersionGreaterThanEqualTo(8.0);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// NOTE the com.gemstone.gemfire.management.internal.web.domain.LinkIndex class only exists
|
||||
|
||||
@@ -394,7 +394,12 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
|
||||
return Boolean.TRUE.equals(readyForEvents);
|
||||
}
|
||||
else {
|
||||
return GemfireUtils.isDurable((ClientCache) fetchCache());
|
||||
try {
|
||||
return GemfireUtils.isDurable((ClientCache) fetchCache());
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.server.CacheServer;
|
||||
import com.gemstone.gemfire.distributed.DistributedSystem;
|
||||
import com.gemstone.gemfire.distributed.internal.DistributionConfig;
|
||||
@@ -31,6 +32,7 @@ import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
|
||||
* DistributedSystemUtils is an abstract utility class for working with the GemFire DistributedSystem.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see com.gemstone.gemfire.cache.GemFireCache
|
||||
* @see com.gemstone.gemfire.distributed.DistributedSystem
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@@ -43,6 +45,7 @@ public abstract class DistributedSystemUtils {
|
||||
public static final String DURABLE_CLIENT_ID_PROPERTY_NAME = DistributionConfig.DURABLE_CLIENT_ID_NAME;
|
||||
public static final String DURABLE_CLIENT_TIMEOUT_PROPERTY_NAME = DistributionConfig.DURABLE_CLIENT_TIMEOUT_NAME;
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static Properties configureDurableClient(Properties gemfireProperties, String durableClientId, Integer durableClientTimeout) {
|
||||
if (StringUtils.hasText(durableClientId)) {
|
||||
Assert.notNull(gemfireProperties, "gemfireProperties must not be null");
|
||||
@@ -57,17 +60,26 @@ public abstract class DistributedSystemUtils {
|
||||
return gemfireProperties;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static boolean isConnected(DistributedSystem distributedSystem) {
|
||||
return (distributedSystem != null && distributedSystem.isConnected());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static boolean isNotConnected(DistributedSystem distributedSystem) {
|
||||
return !isConnected(distributedSystem);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends DistributedSystem> T getDistributedSystem() {
|
||||
return (T) InternalDistributedSystem.getAnyInstance();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends DistributedSystem> T getDistributedSystem(GemFireCache gemfireCache) {
|
||||
return (gemfireCache != null ? (T) gemfireCache.getDistributedSystem() : null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user