Refactored and cleaned up deprecated and unchecked/unsafe Java and GemFire API usage.
This commit is contained in:
@@ -43,9 +43,6 @@ import com.gemstone.gemfire.NoSystemException;
|
||||
import com.gemstone.gemfire.SystemConnectException;
|
||||
import com.gemstone.gemfire.SystemIsRunningException;
|
||||
import com.gemstone.gemfire.UnmodifiableException;
|
||||
import com.gemstone.gemfire.admin.AdminException;
|
||||
import com.gemstone.gemfire.admin.RegionNotFoundException;
|
||||
import com.gemstone.gemfire.admin.RuntimeAdminException;
|
||||
import com.gemstone.gemfire.cache.CacheException;
|
||||
import com.gemstone.gemfire.cache.CacheExistsException;
|
||||
import com.gemstone.gemfire.cache.CacheLoaderException;
|
||||
@@ -58,7 +55,6 @@ import com.gemstone.gemfire.cache.DiskAccessException;
|
||||
import com.gemstone.gemfire.cache.EntryDestroyedException;
|
||||
import com.gemstone.gemfire.cache.EntryExistsException;
|
||||
import com.gemstone.gemfire.cache.EntryNotFoundException;
|
||||
import com.gemstone.gemfire.cache.EntryNotFoundInRegion;
|
||||
import com.gemstone.gemfire.cache.FailedSynchronizationException;
|
||||
import com.gemstone.gemfire.cache.OperationAbortedException;
|
||||
import com.gemstone.gemfire.cache.PartitionedRegionDistributionException;
|
||||
@@ -90,18 +86,18 @@ public abstract class GemfireCacheUtils {
|
||||
|
||||
private static Class<?> CQ_EXCEPTION_CLASS;
|
||||
|
||||
{
|
||||
Class<?> clz = null;
|
||||
static {
|
||||
Class<?> type = null;
|
||||
|
||||
try {
|
||||
type = ClassUtils.resolveClassName("com.gemstone.gemfire.cache.query.CqInvalidException",
|
||||
GemfireCacheUtils.class.getClassLoader());
|
||||
|
||||
clz = ClassUtils.resolveClassName("com.gemstone.gemfire.cache.query.CqInvalidException",
|
||||
GemfireCacheUtils.class.getClassLoader());
|
||||
|
||||
} catch (IllegalArgumentException iae) {
|
||||
}
|
||||
catch (IllegalArgumentException ignore) {
|
||||
}
|
||||
|
||||
CQ_EXCEPTION_CLASS = clz;
|
||||
CQ_EXCEPTION_CLASS = type;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +108,7 @@ public abstract class GemfireCacheUtils {
|
||||
* @param ex Gemfire unchecked exception
|
||||
* @return new the corresponding DataAccessException instance
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static DataAccessException convertGemfireAccessException(GemFireException ex) {
|
||||
if (ex instanceof CacheException) {
|
||||
if (ex instanceof CacheExistsException) {
|
||||
@@ -179,7 +176,7 @@ public abstract class GemfireCacheUtils {
|
||||
if (ex instanceof RegionDestroyedException) {
|
||||
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
|
||||
}
|
||||
if (ex instanceof RegionNotFoundException) {
|
||||
if (ex instanceof com.gemstone.gemfire.admin.RegionNotFoundException) {
|
||||
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
|
||||
}
|
||||
if (ex instanceof ResourceException) {
|
||||
@@ -198,7 +195,7 @@ public abstract class GemfireCacheUtils {
|
||||
if (ex instanceof CopyException) {
|
||||
return new GemfireSystemException(ex);
|
||||
}
|
||||
if (ex instanceof EntryNotFoundInRegion) {
|
||||
if (ex instanceof com.gemstone.gemfire.cache.EntryNotFoundInRegion) {
|
||||
return new DataRetrievalFailureException(ex.getMessage(), ex);
|
||||
}
|
||||
if (ex instanceof FunctionException) {
|
||||
@@ -234,7 +231,7 @@ public abstract class GemfireCacheUtils {
|
||||
if (ex instanceof NoSystemException) {
|
||||
return new GemfireSystemException(ex);
|
||||
}
|
||||
if (ex instanceof RuntimeAdminException) {
|
||||
if (ex instanceof com.gemstone.gemfire.admin.RuntimeAdminException) {
|
||||
return new GemfireSystemException(ex);
|
||||
}
|
||||
if (ex instanceof ServerConnectivityException) {
|
||||
@@ -263,9 +260,6 @@ public abstract class GemfireCacheUtils {
|
||||
* Dedicated method for converting exceptions changed in 6.5 that had their
|
||||
* parent changed. This method exists to 'fool' the compiler type checks
|
||||
* by loosening the type so the code compiles on both 6.5 (pre and current) branches.
|
||||
*
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
static DataAccessException convertQueryExceptions(RuntimeException ex) {
|
||||
if (ex instanceof IndexInvalidException) {
|
||||
@@ -290,6 +284,7 @@ public abstract class GemfireCacheUtils {
|
||||
* @param ex Gemfire unchecked exception
|
||||
* @return new the corresponding DataAccessException instance
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static DataAccessException convertGemfireAccessException(GemFireCheckedException ex) {
|
||||
// query exceptions
|
||||
if (ex instanceof QueryException) {
|
||||
@@ -304,7 +299,7 @@ public abstract class GemfireCacheUtils {
|
||||
return new DataAccessResourceFailureException(ex.getMessage(), ex);
|
||||
}
|
||||
// admin exception
|
||||
if (ex instanceof AdminException) {
|
||||
if (ex instanceof com.gemstone.gemfire.admin.AdminException) {
|
||||
return new GemfireSystemException(ex);
|
||||
}
|
||||
// fall back
|
||||
@@ -337,9 +332,6 @@ public abstract class GemfireCacheUtils {
|
||||
|
||||
/**
|
||||
* Package protected method for detecting CqInvalidException which has been removed in GemFire 6.5 GA.
|
||||
*
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
static boolean isCqInvalidException(RuntimeException ex) {
|
||||
return (CQ_EXCEPTION_CLASS != null && CQ_EXCEPTION_CLASS.isAssignableFrom(ex.getClass()));
|
||||
@@ -356,4 +348,5 @@ public abstract class GemfireCacheUtils {
|
||||
static DataAccessException convertCqInvalidException(RuntimeException ex) {
|
||||
return new GemfireQueryException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.data.gemfire;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import com.gemstone.gemfire.cache.AttributesFactory;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
|
||||
/**
|
||||
@@ -27,9 +26,15 @@ import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
* a XML 'factory-method' tag.
|
||||
* <p/>
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.FactoryBean
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
* @see com.gemstone.gemfire.cache.AttributesFactory
|
||||
* @see com.gemstone.gemfire.cache.RegionAttributes
|
||||
*/
|
||||
public class RegionAttributesFactoryBean extends AttributesFactory implements FactoryBean<RegionAttributes>,
|
||||
InitializingBean {
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RegionAttributesFactoryBean extends com.gemstone.gemfire.cache.AttributesFactory
|
||||
implements FactoryBean<RegionAttributes>, InitializingBean {
|
||||
|
||||
private RegionAttributes attributes;
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.AttributesFactory;
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheListener;
|
||||
import com.gemstone.gemfire.cache.CacheLoader;
|
||||
@@ -66,7 +65,6 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private boolean autoStartup = true;
|
||||
private boolean close = true;
|
||||
private boolean destroy = false;
|
||||
private boolean running;
|
||||
@@ -288,13 +286,13 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
* @see com.gemstone.gemfire.cache.RegionAttributes#getDataPolicy
|
||||
* @see com.gemstone.gemfire.cache.DataPolicy
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unchecked"})
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
DataPolicy getDataPolicy(final RegionFactory regionFactory) {
|
||||
// NOTE cannot pass RegionAttributes.class as the "targetType" on the second invocation of getFieldValue(..)
|
||||
// since the "regionAttributes" field is naively of the implementation class type rather than the interface
|
||||
// type... so much for programming to interfaces.
|
||||
return ((RegionAttributes) getFieldValue(getFieldValue(regionFactory, "attrsFactory", AttributesFactory.class),
|
||||
"regionAttributes", null)).getDataPolicy();
|
||||
return ((RegionAttributes) getFieldValue(getFieldValue(regionFactory, "attrsFactory",
|
||||
com.gemstone.gemfire.cache.AttributesFactory.class), "regionAttributes", null)).getDataPolicy();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -415,7 +413,7 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
void validateRegionAttributes(final RegionAttributes regionAttributes) {
|
||||
AttributesFactory.validateAttributes(regionAttributes);
|
||||
com.gemstone.gemfire.cache.AttributesFactory.validateAttributes(regionAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -725,7 +723,7 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
*/
|
||||
@Override
|
||||
public boolean isAutoStartup() {
|
||||
return this.autoStartup;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.AttributesFactory;
|
||||
import com.gemstone.gemfire.cache.CacheListener;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
@@ -40,9 +39,9 @@ import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
* (e.g. ReplicatedRegionFactoryBean) instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SubRegionFactoryBean<K, V> extends AttributesFactory<K, V> implements FactoryBean<Region<K, V>>,
|
||||
InitializingBean {
|
||||
@SuppressWarnings({"deprecation", "unused"})
|
||||
public class SubRegionFactoryBean<K, V> extends com.gemstone.gemfire.cache.AttributesFactory<K, V>
|
||||
implements FactoryBean<Region<K, V>>, InitializingBean {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@@ -56,7 +55,6 @@ public class SubRegionFactoryBean<K, V> extends AttributesFactory<K, V> implemen
|
||||
private Region<?, ?> parentRegion;
|
||||
private Region<K, V> subRegion;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
private String regionName;
|
||||
|
||||
@@ -125,8 +123,8 @@ public class SubRegionFactoryBean<K, V> extends AttributesFactory<K, V> implemen
|
||||
|
||||
/**
|
||||
* Sets the cache listeners used for the region used by this factory. Used
|
||||
* only when a new region is created.Overrides the settings specified
|
||||
* through {@link #setAttributes(com.gemstone.gemfire.cache.RegionAttributes)}.
|
||||
* only when a new region is created. Overrides the settings specified
|
||||
* through {@link setAttributes(com.gemstone.gemfire.cache.RegionAttributes)}.
|
||||
*
|
||||
* @param cacheListeners the cacheListeners to set on a newly created region
|
||||
*/
|
||||
@@ -134,10 +132,6 @@ public class SubRegionFactoryBean<K, V> extends AttributesFactory<K, V> implemen
|
||||
this.cacheListeners = cacheListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param gatewaySenders
|
||||
*/
|
||||
public void setGatewaySenders(Object[] gatewaySenders) {
|
||||
this.gatewaySenders = gatewaySenders;
|
||||
}
|
||||
@@ -145,7 +139,6 @@ public class SubRegionFactoryBean<K, V> extends AttributesFactory<K, V> implemen
|
||||
/**
|
||||
* Set to true if the subregion should already exist, e.g., specified by
|
||||
* <lookup-region>
|
||||
* @param lookupOnly
|
||||
*/
|
||||
public void setLookupOnly(boolean lookupOnly) {
|
||||
this.lookupOnly = lookupOnly;
|
||||
@@ -153,7 +146,6 @@ public class SubRegionFactoryBean<K, V> extends AttributesFactory<K, V> implemen
|
||||
|
||||
/**
|
||||
* Set the bean name - the same as the subregion full path
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
@@ -161,7 +153,6 @@ public class SubRegionFactoryBean<K, V> extends AttributesFactory<K, V> implemen
|
||||
|
||||
/**
|
||||
* Set the simple name of the region
|
||||
* @param regionName
|
||||
*/
|
||||
public void setRegionName(String regionName) {
|
||||
this.regionName = regionName;
|
||||
@@ -169,7 +160,6 @@ public class SubRegionFactoryBean<K, V> extends AttributesFactory<K, V> implemen
|
||||
|
||||
/**
|
||||
* Set the parent Region
|
||||
* @param parent
|
||||
*/
|
||||
public void setParent(Region<?, ?> parent) {
|
||||
this.parentRegion = parent;
|
||||
|
||||
@@ -52,6 +52,7 @@ import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean,
|
||||
DisposableBean, BeanNameAware, BeanFactoryAware {
|
||||
|
||||
@@ -115,9 +116,10 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean,
|
||||
try {
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = beanFactory.getBean(ClientCacheFactoryBean.class);
|
||||
properties = clientCacheFactoryBean.getProperties();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
|
||||
connectToTemporaryDs(properties);
|
||||
|
||||
}
|
||||
@@ -393,10 +395,12 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean,
|
||||
* initialize a client-like Distributed System before initializing
|
||||
* the pool
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
static void connectToTemporaryDs(Properties properties) {
|
||||
Properties props = properties != null? (Properties) properties.clone() : new Properties();
|
||||
props.setProperty("mcast-port", "0");
|
||||
props.setProperty("locators", "");
|
||||
DistributedSystem.connect(props);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ package org.springframework.data.gemfire.config;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskWriteAttributes;
|
||||
import com.gemstone.gemfire.cache.DiskWriteAttributesFactory;
|
||||
|
||||
/**
|
||||
* Simple utility class used for defining nested factory-method like definitions
|
||||
* w/o polluting the container with useless beans.
|
||||
@@ -30,11 +27,12 @@ import com.gemstone.gemfire.cache.DiskWriteAttributesFactory;
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
class DiskWriteAttributesFactoryBean implements FactoryBean<DiskWriteAttributes>, InitializingBean {
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
class DiskWriteAttributesFactoryBean implements FactoryBean<com.gemstone.gemfire.cache.DiskWriteAttributes>, InitializingBean {
|
||||
|
||||
private DiskWriteAttributes attributes;
|
||||
private com.gemstone.gemfire.cache.DiskWriteAttributes attributes;
|
||||
|
||||
private DiskWriteAttributesFactory attrFactory;
|
||||
private com.gemstone.gemfire.cache.DiskWriteAttributesFactory attrFactory;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
@@ -42,13 +40,13 @@ class DiskWriteAttributesFactoryBean implements FactoryBean<DiskWriteAttributes>
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskWriteAttributes getObject() throws Exception {
|
||||
public com.gemstone.gemfire.cache.DiskWriteAttributes getObject() throws Exception {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return (attributes != null ? attributes.getClass() : DiskWriteAttributes.class);
|
||||
return (attributes != null ? attributes.getClass() : com.gemstone.gemfire.cache.DiskWriteAttributes.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,7 +54,8 @@ class DiskWriteAttributesFactoryBean implements FactoryBean<DiskWriteAttributes>
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setDiskAttributesFactory(DiskWriteAttributesFactory dwaf) {
|
||||
public void setDiskAttributesFactory(com.gemstone.gemfire.cache.DiskWriteAttributesFactory dwaf) {
|
||||
this.attrFactory = dwaf;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,8 +39,9 @@ import com.gemstone.gemfire.cache.server.ServerLoadProbe;
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class CacheServerFactoryBean implements FactoryBean<CacheServer>, InitializingBean, DisposableBean,
|
||||
SmartLifecycle {
|
||||
SmartLifecycle {
|
||||
|
||||
private boolean autoStartup = true;
|
||||
private boolean notifyBySubscription = CacheServer.DEFAULT_NOTIFY_BY_SUBSCRIPTION;
|
||||
@@ -68,7 +69,7 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>, Initial
|
||||
private String hostNameForClients = CacheServer.DEFAULT_HOSTNAME_FOR_CLIENTS;
|
||||
private String subscriptionDiskStore;
|
||||
|
||||
private String[] serverGroups = CacheServer.DEFAULT_GROUPS;
|
||||
private String[] serverGroups = {};
|
||||
|
||||
private SubscriptionEvictionPolicy subscriptionEvictionPolicy = SubscriptionEvictionPolicy.valueOf(
|
||||
ClientSubscriptionConfig.DEFAULT_EVICTION_POLICY.toUpperCase());
|
||||
@@ -85,6 +86,7 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>, Initial
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void afterPropertiesSet() throws IOException {
|
||||
Assert.notNull(cache, "A GemFire Cache is required.");
|
||||
|
||||
|
||||
@@ -23,10 +23,13 @@ import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* Spring Framework {@link Cache} implementation using a GemFire {@link Region} underneath.
|
||||
* Supports Gemfire 6.5 or higher.
|
||||
*
|
||||
* Spring Framework {@link Cache} implementation backed by a GemFire {@link Region}.
|
||||
* <p/>
|
||||
* Supports GemFire 6.5 or higher.
|
||||
* <p/>
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
*
|
||||
*/
|
||||
public class GemfireCache implements Cache {
|
||||
|
||||
@@ -64,7 +67,9 @@ public class GemfireCache implements Cache {
|
||||
return (value == null ? null : new SimpleValueWrapper(value));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void put(Object key, Object value) {
|
||||
region.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user