DATAGEODE-314 - Replace remaining uses of Apache Geode's PoolManager API with PoolResolver.

This commit is contained in:
John Blum
2020-03-24 19:16:49 -07:00
parent 38f600d655
commit fe08a0c18d
6 changed files with 150 additions and 46 deletions

View File

@@ -33,7 +33,6 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.distributed.DistributedSystem;
import org.springframework.context.ApplicationContext;
@@ -44,13 +43,17 @@ import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.client.support.DefaultableDelegatingPoolAdapter;
import org.springframework.data.gemfire.client.support.DelegatingPoolAdapter;
import org.springframework.data.gemfire.client.support.PoolManagerPoolResolver;
import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.data.gemfire.support.ConnectionEndpoint;
import org.springframework.data.gemfire.support.ConnectionEndpointList;
import org.springframework.data.gemfire.util.SpringUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import lombok.NonNull;
/**
* Spring {@link org.springframework.beans.factory.FactoryBean} used to create a Pivotal GemFire/Apache Geode
* {@link ClientCache}.
@@ -78,6 +81,8 @@ import org.springframework.util.StringUtils;
@SuppressWarnings("unused")
public class ClientCacheFactoryBean extends CacheFactoryBean implements ApplicationListener<ContextRefreshedEvent> {
protected static final PoolResolver DEFAULT_POOL_RESOLVER = new PoolManagerPoolResolver();
private Boolean keepAlive = false;
private Boolean multiUserAuthentication;
private Boolean prSingleHopEnabled;
@@ -109,6 +114,8 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
private Pool pool;
private PoolResolver poolResolver;
private String durableClientId;
private String poolName;
private String serverGroup;
@@ -327,11 +334,10 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
* Resolves the {@link Pool} used to configure the {@link ClientCache}, {@literal DEFAULT} {@link Pool}.
*
* @return the resolved {@link Pool} used to configure the {@link ClientCache}, {@literal DEFAULT} {@link Pool}.
* @see org.apache.geode.cache.client.PoolManager#find(String)
* @see org.apache.geode.cache.client.Pool
* @see #getPoolName()
* @see #getPool()
* @see #findPool(String)
* @see #resolvePoolName()
* @see #isPoolNameResolvable(String)
*/
Pool resolvePool() {
@@ -366,7 +372,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
}
Pool findPool(String name) {
return PoolManager.find(name);
return getPoolResolver().resolve(name);
}
private boolean isPoolNameResolvable(String poolName) {
@@ -433,7 +439,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({ "rawtypes", "unchecked" })
public Class<? extends GemFireCache> getObjectType() {
return Optional.ofNullable(getCache()).map(Object::getClass).orElse((Class) ClientCache.class);
}
@@ -633,45 +639,74 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
}
/**
* Sets the {@link Pool} used by this cache client to obtain connections to the GemFire cluster.
* Sets the {@link Pool} used by this {@link ClientCache} to obtain connections to the Apache Geode cluster.
*
* @param pool the GemFire {@link Pool} used by this {@link ClientCache} to obtain connections
* to the GemFire cluster.
* @throws IllegalArgumentException if the {@link Pool} is null.
* @param pool {@link Pool} used by this {@link ClientCache} to obtain connections to the Apache Geode cluster.
* @see org.apache.geode.cache.client.Pool
*/
public void setPool(Pool pool) {
this.pool = pool;
}
/**
* Gets the {@link Pool} used by this cache client to obtain connections to the GemFire cluster.
* Gets the {@link Pool} used by this {@link ClientCache} to obtain connections to the Apache Geode cluster.
*
* @return the GemFire {@link Pool} used by this {@link ClientCache} to obtain connections
* to the GemFire cluster.
* @return {@link Pool} used by this {@link ClientCache} to obtain connections to the Apache Geode cluster.
* @see org.apache.geode.cache.client.Pool
*/
public Pool getPool() {
return this.pool;
}
/**
* Sets the name of the {@link Pool} used by this cache client to obtain connections to the GemFire cluster.
* Sets the {@link String name} of the {@link Pool} used by this {@link ClientCache} to obtain connections to
* the Apache Geode cluster.
*
* @param poolName set the name of the GemFire {@link Pool} used by this GemFire {@link ClientCache}.
* @throws IllegalArgumentException if the {@link Pool} name is unspecified.
* @param poolName {@link String name} of the {@link Pool} used by this {@link ClientCache} to obtain connections to
* the Apache Geode cluster.
*/
public void setPoolName(String poolName) {
this.poolName = poolName;
}
/**
* Gets the name of the GemFire {@link Pool} used by this GemFire cache client.
* Gets the {@link String name} of the {@link Pool} used by this {@link ClientCache} to obtain connections to
* the Apache Geode cluster.
*
* @return the name of the GemFire {@link Pool} used by this GemFire cache client.
* @return {@link String name} of the {@link Pool} used by this {@link ClientCache} to obtain connections to
* the Apache Geode cluster.
*/
public String getPoolName() {
return this.poolName;
}
/**
* Sets (configures) the {@link PoolResolver} used by this {@link ClientCache} to resolve {@link Pool} objects.
*
* The {@link Pool} objects may be managed or un-managed depending on the {@link PoolResolver} implementation.
*
* @param poolResolver {@link PoolResolver} used to resolve the configured {@link Pool}.
* @see org.springframework.data.gemfire.client.PoolResolver
*/
public void setPoolResolver(@Nullable PoolResolver poolResolver) {
this.poolResolver = poolResolver;
}
/**
* Gets the configured {@link PoolResolver} used by this {@link ClientCache} to resolve {@link Pool} objects.
*
* @return the configured {@link PoolResolver}. If no {@link PoolResolver} was configured, then return the default,
* {@link PoolManagerPoolResolver}.
* @see org.springframework.data.gemfire.client.PoolResolver
* @see org.springframework.data.gemfire.client.support.PoolManagerPoolResolver
*/
public @NonNull PoolResolver getPoolResolver() {
PoolResolver poolResolver = this.poolResolver;
return poolResolver != null ? poolResolver : DEFAULT_POOL_RESOLVER;
}
public void setPingInterval(Long pingInterval) {
this.pingInterval = pingInterval;
}

View File

@@ -36,22 +36,25 @@ import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.compression.Compressor;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.data.gemfire.ConfigurableRegionFactoryBean;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.client.support.PoolManagerPoolResolver;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.data.gemfire.eviction.EvictingRegionFactoryBean;
import org.springframework.data.gemfire.expiration.ExpiringRegionFactoryBean;
import org.springframework.data.gemfire.support.SmartLifecycleSupport;
import org.springframework.data.gemfire.util.RegionUtils;
import org.springframework.data.gemfire.util.SpringUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import lombok.NonNull;
/**
* Spring {@link FactoryBean} used to construct, configure and initialize a client {@link Region}.
*
@@ -81,6 +84,8 @@ public class ClientRegionFactoryBean<K, V> extends ConfigurableRegionFactoryBean
public static final String DEFAULT_POOL_NAME = "DEFAULT";
public static final String GEMFIRE_POOL_NAME = GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME;
protected static final PoolResolver DEFAULT_POOL_RESOLVER = new PoolManagerPoolResolver();
private boolean close = false;
private boolean destroy = false;
@@ -122,6 +127,8 @@ public class ClientRegionFactoryBean<K, V> extends ConfigurableRegionFactoryBean
private Float loadFactor;
private PoolResolver poolResolver = DEFAULT_POOL_RESOLVER;
private RegionAttributes<K, V> attributes;
private String diskStoreName;
@@ -257,7 +264,7 @@ public class ClientRegionFactoryBean<K, V> extends ConfigurableRegionFactoryBean
@SuppressWarnings("all")
private boolean eagerlyInitializePool(String poolName) {
return Optional.ofNullable(PoolManager.find(poolName))
return Optional.ofNullable(getPoolResolver().resolve(poolName))
.map(it -> true)
.orElseGet(() ->
SpringUtils.safeGetValue(() ->
@@ -678,6 +685,33 @@ public class ClientRegionFactoryBean<K, V> extends ConfigurableRegionFactoryBean
return Optional.ofNullable(this.poolName);
}
/**
* Sets (configures) the {@link PoolResolver} used by this {@link ClientCache} to resolve {@link Pool} objects.
*
* The {@link Pool} objects may be managed or un-managed depending on the {@link PoolResolver} implementation.
*
* @param poolResolver {@link PoolResolver} used to resolve the configured {@link Pool}.
* @see org.springframework.data.gemfire.client.PoolResolver
*/
public void setPoolResolver(@Nullable PoolResolver poolResolver) {
this.poolResolver = poolResolver;
}
/**
* Gets the configured {@link PoolResolver} used by this {@link ClientCache} to resolve {@link Pool} objects.
*
* @return the configured {@link PoolResolver}. If no {@link PoolResolver} was configured, then return the default,
* {@link PoolManagerPoolResolver}.
* @see org.springframework.data.gemfire.client.PoolResolver
* @see org.springframework.data.gemfire.client.support.PoolManagerPoolResolver
*/
public @NonNull PoolResolver getPoolResolver() {
PoolResolver poolResolver = this.poolResolver;
return poolResolver != null ? poolResolver : DEFAULT_POOL_RESOLVER;
}
public void setRegionIdleTimeout(ExpirationAttributes regionIdleTimeout) {
this.regionIdleTimeout = regionIdleTimeout;
}

View File

@@ -22,11 +22,12 @@ import java.util.Optional;
import org.apache.geode.cache.RegionService;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.cache.execute.Execution;
import org.apache.geode.cache.execute.Function;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.client.PoolResolver;
import org.springframework.data.gemfire.client.support.PoolManagerPoolResolver;
import org.springframework.data.gemfire.util.CacheUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -47,8 +48,12 @@ import org.springframework.util.StringUtils;
@SuppressWarnings("unused")
public class GemfireOnServerFunctionTemplate extends AbstractFunctionTemplate {
protected static final PoolResolver DEFAULT_POOL_RESOLVER = new PoolManagerPoolResolver();
private Pool pool;
private PoolResolver poolResolver = DEFAULT_POOL_RESOLVER;
private final RegionService cache;
private String poolName;
@@ -78,6 +83,17 @@ public class GemfireOnServerFunctionTemplate extends AbstractFunctionTemplate {
this.poolName = poolName;
}
public void setPoolResolver(PoolResolver poolResolver) {
this.poolResolver = poolResolver;
}
protected PoolResolver getPoolResolver() {
PoolResolver poolResolver = this.poolResolver;
return poolResolver != null ? poolResolver : DEFAULT_POOL_RESOLVER;
}
@Override
protected AbstractFunctionExecution getFunctionExecution() {
@@ -100,14 +116,14 @@ public class GemfireOnServerFunctionTemplate extends AbstractFunctionTemplate {
protected Pool resolveDefaultPool() {
return Optional.ofNullable(PoolManager.find(GemfireUtils.DEFAULT_POOL_NAME))
return Optional.ofNullable(getPoolResolver().resolve(GemfireUtils.DEFAULT_POOL_NAME))
.orElseThrow(() -> newIllegalStateException("No Pool was configured"));
}
protected Pool resolveNamedPool() {
if (StringUtils.hasText(this.poolName)) {
this.pool = Optional.ofNullable(PoolManager.find(this.poolName))
this.pool = Optional.ofNullable(getPoolResolver().resolve(this.poolName))
.orElseThrow(() -> newIllegalStateException("No Pool with name [%s] exists",
this.poolName));
}

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.gemfire.function.execution;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
import java.util.Optional;
@@ -23,11 +22,12 @@ import java.util.Optional;
import org.apache.geode.cache.RegionService;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.cache.execute.Execution;
import org.apache.geode.cache.execute.Function;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.client.PoolResolver;
import org.springframework.data.gemfire.client.support.PoolManagerPoolResolver;
import org.springframework.data.gemfire.util.CacheUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -48,8 +48,12 @@ import org.springframework.util.StringUtils;
@SuppressWarnings("unused")
public class GemfireOnServersFunctionTemplate extends AbstractFunctionTemplate {
protected static final PoolResolver DEFAULT_POOL_RESOLVER = new PoolManagerPoolResolver();
private Pool pool;
private PoolResolver poolResolver = DEFAULT_POOL_RESOLVER;
private final RegionService cache;
private String poolName;
@@ -79,6 +83,17 @@ public class GemfireOnServersFunctionTemplate extends AbstractFunctionTemplate {
this.poolName = poolName;
}
public void setPoolResolver(PoolResolver poolResolver) {
this.poolResolver = poolResolver;
}
protected PoolResolver getPoolResolver() {
PoolResolver poolResolver = this.poolResolver;
return poolResolver != null ? poolResolver : DEFAULT_POOL_RESOLVER;
}
@Override
protected AbstractFunctionExecution getFunctionExecution() {
@@ -101,14 +116,14 @@ public class GemfireOnServersFunctionTemplate extends AbstractFunctionTemplate {
protected Pool resolveDefaultPool() {
return Optional.ofNullable(PoolManager.find(GemfireUtils.DEFAULT_POOL_NAME))
return Optional.ofNullable(getPoolResolver().resolve(GemfireUtils.DEFAULT_POOL_NAME))
.orElseThrow(() -> newIllegalStateException("No Pool was configured"));
}
protected Pool resolveNamedPool() {
if (StringUtils.hasText(this.poolName)) {
this.pool = Optional.ofNullable(PoolManager.find(this.poolName))
this.pool = Optional.ofNullable(getPoolResolver().resolve(this.poolName))
.orElseThrow(() -> newIllegalStateException("No Pool with name [%s] exists",
this.poolName));
}

View File

@@ -13,25 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.function.execution;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.geode.cache.CacheClosedException;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.geode.cache.CacheClosedException;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.Pool;
import org.springframework.data.gemfire.client.PoolResolver;
import org.springframework.data.gemfire.client.support.PoolManagerPoolResolver;
import org.springframework.data.gemfire.fork.FunctionCacheServerProcess;
import org.springframework.data.gemfire.process.ProcessWrapper;
import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport;
@@ -50,6 +50,8 @@ public class FunctionExecutionIntegrationTests extends ClientServerIntegrationTe
private Pool gemfirePool = null;
private PoolResolver poolResolver = new PoolManagerPoolResolver();
private Region<String, String> gemfireRegion = null;
@BeforeClass
@@ -90,7 +92,7 @@ public class FunctionExecutionIntegrationTests extends ClientServerIntegrationTe
assertThat(this.gemfireRegion).isNotNull();
assertThat(this.gemfireRegion.getName()).isEqualTo("test-function");
this.gemfirePool = PoolManager.find("DEFAULT");
this.gemfirePool = this.poolResolver.resolve("DEFAULT");
assertThat(this.gemfirePool).isNotNull();
assertThat(this.gemfirePool.getName()).isEqualTo("DEFAULT");

View File

@@ -13,17 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.function.execution;
import static org.assertj.core.api.Java6Assertions.assertThat;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.After;
import org.junit.AfterClass;
@@ -31,7 +23,15 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.Pool;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.client.PoolResolver;
import org.springframework.data.gemfire.client.support.PoolManagerPoolResolver;
import org.springframework.data.gemfire.fork.FunctionCacheServerProcess;
import org.springframework.data.gemfire.process.ProcessWrapper;
import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport;
@@ -49,6 +49,8 @@ public class GemfireFunctionTemplateIntegrationTests extends ClientServerIntegra
private Pool gemfirePool = null;
private PoolResolver poolResolver = new PoolManagerPoolResolver();
private Region<String, String> gemfireRegion = null;
@BeforeClass
@@ -89,7 +91,7 @@ public class GemfireFunctionTemplateIntegrationTests extends ClientServerIntegra
assertThat(this.gemfireRegion).isNotNull();
assertThat(this.gemfireRegion.getName()).isEqualTo("test-function");
this.gemfirePool = PoolManager.find("DEFAULT");
this.gemfirePool = this.poolResolver.resolve("DEFAULT");
assertThat(this.gemfirePool).isNotNull();
assertThat(this.gemfirePool.getName()).isEqualTo("DEFAULT");