diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java index 76cb4e66..999719d3 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java @@ -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 { + 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 = DEFAULT_POOL_RESOLVER; + private String durableClientId; private String poolName; private String serverGroup; @@ -366,7 +373,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 +440,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat * @see org.springframework.beans.factory.FactoryBean#getObjectType() */ @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) public Class getObjectType() { return Optional.ofNullable(getCache()).map(Object::getClass).orElse((Class) ClientCache.class); } @@ -633,45 +640,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) { + public void setPool(@Nullable 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() { + public @Nullable 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) { + public void setPoolName(@Nullable 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() { + public @Nullable 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; } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java index db68c632..4aaf220e 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java @@ -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}. * @@ -60,6 +63,7 @@ import org.springframework.util.StringUtils; * @author John Blum * @see org.apache.geode.cache.DataPolicy * @see org.apache.geode.cache.EvictionAttributes + * @see org.apache.geode.cache.ExpirationAttributes * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region * @see org.apache.geode.cache.RegionAttributes @@ -67,11 +71,13 @@ import org.springframework.util.StringUtils; * @see org.apache.geode.cache.client.ClientRegionFactory * @see org.apache.geode.cache.client.ClientRegionShortcut * @see org.apache.geode.cache.client.Pool + * @see org.apache.geode.compression.Compressor * @see org.springframework.beans.factory.DisposableBean * @see org.springframework.beans.factory.FactoryBean - * @see org.springframework.data.gemfire.DataPolicyConverter - * @see org.springframework.data.gemfire.ResolvableRegionFactoryBean + * @see org.springframework.data.gemfire.ConfigurableRegionFactoryBean * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer + * @see org.springframework.data.gemfire.eviction.EvictingRegionFactoryBean + * @see org.springframework.data.gemfire.expiration.ExpiringRegionFactoryBean * @see org.springframework.data.gemfire.support.SmartLifecycleSupport */ @SuppressWarnings("unused") @@ -81,6 +87,8 @@ public class ClientRegionFactoryBean 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 +130,8 @@ public class ClientRegionFactoryBean extends ConfigurableRegionFactoryBean private Float loadFactor; + private PoolResolver poolResolver = DEFAULT_POOL_RESOLVER; + private RegionAttributes attributes; private String diskStoreName; @@ -257,7 +267,7 @@ public class ClientRegionFactoryBean 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(() -> @@ -644,10 +654,9 @@ public class ClientRegionFactoryBean extends ConfigurableRegionFactoryBean } /** - * Configures the {@link Pool} used by this {@link Region client Region}. + * Configures the {@link Pool} used by this client {@link Region}. * - * @param pool {@link Pool} used by this {@link Region client Region} - * to send/receive data to/from the server. + * @param pool {@link Pool} used by this client {@link Region} to send/receive data to/from the server. * @see org.apache.geode.cache.client.Pool * @see #setPoolName(String) */ @@ -656,10 +665,10 @@ public class ClientRegionFactoryBean extends ConfigurableRegionFactoryBean } /** - * Configures the {@link String name} of the {@link Pool} used by this {@link Region client Region}. + * Configures the {@link String name} of the {@link Pool} to be used by this client {@link Region}. * * @param poolName {@link String} containing the name of the client {@link Pool} - * used by this {@link Region client Region}. + * to be used by this client {@link Region}. * @see #getPoolName() * @see #setPool(Pool) */ @@ -668,16 +677,43 @@ public class ClientRegionFactoryBean extends ConfigurableRegionFactoryBean } /** - * Returns the {@link String name} of the configured {@link Pool} to use with this {@link Region client Region}. + * Returns the {@link String name} of the configured {@link Pool} used by this client {@link Region}. * - * @return the {@link Optional} {@link String name} of the configured {@link Pool} to use - * with this {@link Region client Region}. + * @return the {@link Optional} {@link String name} of the configured {@link Pool} to be used by + * this client {@link Region}. * @see #setPoolName(String) */ public Optional getPoolName() { return Optional.ofNullable(this.poolName); } + /** + * Sets (configures) the {@link PoolResolver} used by this client {@link Region} 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 client {@link Region} 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; } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java index 20b83290..80d59475 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java @@ -724,7 +724,10 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements * @see org.springframework.data.gemfire.client.PoolResolver */ public PoolResolver getPoolResolver() { - return this.poolResolver != null ? this.poolResolver : DEFAULT_POOL_RESOLVER; + + PoolResolver poolResolver = this.poolResolver; + + return poolResolver != null ? poolResolver : DEFAULT_POOL_RESOLVER; } public void setPrSingleHopEnabled(boolean prSingleHopEnabled) { diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/AbstractClientFunctionTemplate.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/AbstractClientFunctionTemplate.java new file mode 100644 index 00000000..62bd8187 --- /dev/null +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/AbstractClientFunctionTemplate.java @@ -0,0 +1,151 @@ +/* + * Copyright 2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.function.execution; + +import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException; + +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.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.StringUtils; + +/** + * Abstract base class for Apache Geode client-side {@link Function} {@link Execution}. + * + * @author John Blum + * @see org.apache.geode.cache.RegionService + * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.client.Pool + * @see org.apache.geode.cache.execute.Execution + * @see org.apache.geode.cache.execute.Function + * @since 2.3.0 + */ +@SuppressWarnings("unused") +public abstract class AbstractClientFunctionTemplate extends AbstractFunctionTemplate { + + protected static final PoolResolver DEFAULT_POOL_RESOLVER = new PoolManagerPoolResolver(); + + private Pool pool; + + private PoolResolver poolResolver = DEFAULT_POOL_RESOLVER; + + private RegionService regionService; + + private String poolName; + + public AbstractClientFunctionTemplate(RegionService regionService) { + this.regionService = regionService; + } + + public AbstractClientFunctionTemplate(Pool pool) { + this.pool = pool; + } + + public AbstractClientFunctionTemplate(String poolName) { + this.poolName = poolName; + } + + public void setPool(Pool pool) { + this.pool = pool; + } + + public void setPoolName(String poolName) { + 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; + } + + protected Object resolveRequiredGemFireObject() { + return Optional.ofNullable(resolvePool()).orElseGet(this::resolveClientCache); + } + + /** + * @deprecated as of 2.3.0; Use {@link #resolveRegionService()}. + */ + @Deprecated + protected ClientCache resolveClientCache() { + return (ClientCache) resolveRegionService(); + } + + protected Pool resolvePool() { + + if (this.pool == null) { + this.pool = resolveNamedPool(); + } + + return this.pool; + } + + protected Pool resolveDefaultPool() { + + return Optional.ofNullable(getPoolResolver().resolve(GemfireUtils.DEFAULT_POOL_NAME)) + .orElseThrow(() -> newIllegalStateException("DEFAULT Pool is not present")); + } + + protected Pool resolveNamedPool() { + + if (StringUtils.hasText(this.poolName)) { + this.pool = Optional.ofNullable(getPoolResolver().resolve(this.poolName)) + .orElseThrow(() -> newIllegalStateException("Pool with name [%s] is not present", + this.poolName)); + } + + return this.pool; + } + + protected RegionService resolveRegionService() { + + RegionService resolvedRegionService = this.regionService != null + ? this.regionService + : CacheUtils.getClientCache(); + + return Optional.ofNullable(resolvedRegionService) + .orElseThrow(() -> newIllegalStateException("ClientCache is not present")); + } + + @Override + protected AbstractFunctionExecution getFunctionExecution() { + + Object gemfireObject = resolveRequiredGemFireObject(); + + return gemfireObject instanceof Pool + ? newFunctionExecutionUsingPool((Pool) gemfireObject) + : newFunctionExecutionUsingRegionService((RegionService) gemfireObject); + } + + protected abstract AbstractFunctionExecution newFunctionExecutionUsingPool(Pool pool); + + protected abstract AbstractFunctionExecution newFunctionExecutionUsingRegionService(RegionService regionService); + +} diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnMemberFunctionTemplate.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnMemberFunctionTemplate.java index cd1acabb..c194adae 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnMemberFunctionTemplate.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnMemberFunctionTemplate.java @@ -45,10 +45,10 @@ public class GemfireOnMemberFunctionTemplate extends AbstractFunctionTemplate { if (distributedMember == null && groups == null) { return new DefaultMemberFunctionExecution(); } else if (distributedMember == null) { - return new GroupMemberFunctionExecution(this.groups); + return new OnMemberInGroupsFunctionExecution(this.groups); } - return new DistributedMemberFunctionExecution(this.distributedMember); + return new OnDistributedMemberFunctionExecution(this.distributedMember); } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnMembersFunctionTemplate.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnMembersFunctionTemplate.java index e3e201e4..18a1700d 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnMembersFunctionTemplate.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnMembersFunctionTemplate.java @@ -43,12 +43,12 @@ public class GemfireOnMembersFunctionTemplate extends AbstractFunctionTemplate protected AbstractFunctionExecution getFunctionExecution() { if (distributedMembers == null && groups == null) { - return new AllMembersFunctionExecution(); + return new OnAllMembersFunctionExecution(); } else if (distributedMembers == null) { - return new GroupMembersFunctionExecution(this.groups); + return new OnMembersInGroupsFunctionExecution(this.groups); } - return new DistributedMembersFunctionExecution(this.distributedMembers); + return new OnDistributedMembersFunctionExecution(this.distributedMembers); } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnRegionFunctionTemplate.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnRegionFunctionTemplate.java index 796cd842..55e326d1 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnRegionFunctionTemplate.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnRegionFunctionTemplate.java @@ -49,8 +49,8 @@ public class GemfireOnRegionFunctionTemplate extends AbstractFunctionTemplate im } @Override - protected RegionFunctionExecution getFunctionExecution() { - return new RegionFunctionExecution(getRegion()); + protected OnRegionFunctionExecution getFunctionExecution() { + return new OnRegionFunctionExecution(getRegion()); } protected Region getRegion() { diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnServerFunctionTemplate.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnServerFunctionTemplate.java index bdf79ecd..3a33c0eb 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnServerFunctionTemplate.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnServerFunctionTemplate.java @@ -12,111 +12,45 @@ */ package org.springframework.data.gemfire.function.execution; -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException; - -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.util.CacheUtils; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - /** * Creates an {@literal OnServer} {@link Function} {@link Execution} initialized with - * either a {@link RegionService cache} or a {@link Pool}. + * either a {@link RegionService} or a {@link Pool}. * * @author David Turanski * @author John Blum * @see org.apache.geode.cache.RegionService - * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.client.Pool * @see org.apache.geode.cache.execute.Execution * @see org.apache.geode.cache.execute.Function - * @see org.springframework.data.gemfire.function.execution.AbstractFunctionTemplate + * @see org.springframework.data.gemfire.function.execution.AbstractClientFunctionTemplate */ @SuppressWarnings("unused") -public class GemfireOnServerFunctionTemplate extends AbstractFunctionTemplate { - - private Pool pool; - - private final RegionService cache; - - private String poolName; +public class GemfireOnServerFunctionTemplate extends AbstractClientFunctionTemplate { public GemfireOnServerFunctionTemplate(RegionService cache) { - - Assert.notNull(cache, "RegionService must not be null"); - - this.cache = cache; + super(cache); } public GemfireOnServerFunctionTemplate(Pool pool) { - this.cache = resolveClientCache(); - this.pool = pool; + super(pool); } public GemfireOnServerFunctionTemplate(String poolName) { - this.cache = resolveClientCache(); - this.poolName = poolName; - } - - public void setPool(Pool pool) { - this.pool = pool; - } - - public void setPoolName(String poolName) { - this.poolName = poolName; + super(poolName); } @Override - protected AbstractFunctionExecution getFunctionExecution() { - - Object gemfireObject = resolveRequiredGemFireObject(); - - return gemfireObject instanceof Pool - ? new PoolServerFunctionExecution((Pool) gemfireObject) - : new ServerFunctionExecution((RegionService) gemfireObject); + protected AbstractFunctionExecution newFunctionExecutionUsingPool(Pool pool) { + return new OnServerUsingPoolFunctionExecution(pool); } - private Object resolveRequiredGemFireObject() { - return Optional.ofNullable(resolvePool()).orElseGet(this::resolveClientCache); - } - - protected ClientCache resolveClientCache() { - - return Optional.ofNullable(CacheUtils.getClientCache()) - .orElseThrow(() -> newIllegalStateException("No ClientCache instance is present")); - } - - protected Pool resolveDefaultPool() { - - return Optional.ofNullable(PoolManager.find(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)) - .orElseThrow(() -> newIllegalStateException("No Pool with name [%s] exists", - this.poolName)); - } - - return this.pool; - } - - protected Pool resolvePool() { - - this.pool = Optional.ofNullable(this.pool) - .orElseGet(this::resolveNamedPool); - - return this.pool; + @Override + protected AbstractFunctionExecution newFunctionExecutionUsingRegionService(RegionService regionService) { + return new OnServerUsingRegionServiceFunctionExecution(regionService); } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnServersFunctionTemplate.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnServersFunctionTemplate.java index ad12962b..4ec64bb9 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnServersFunctionTemplate.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GemfireOnServersFunctionTemplate.java @@ -12,112 +12,45 @@ */ package org.springframework.data.gemfire.function.execution; - -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException; - -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.util.CacheUtils; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - /** * Creates an {@literal OnServers} {@link Function} {@link Execution} initialized with - * either a {@link RegionService cache} or a {@link Pool}. + * either a {@link RegionService} or a {@link Pool}. * * @author David Turanski * @author John Blum * @see org.apache.geode.cache.RegionService - * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.client.Pool * @see org.apache.geode.cache.execute.Execution * @see org.apache.geode.cache.execute.Function - * @see org.springframework.data.gemfire.function.execution.AbstractFunctionTemplate + * @see org.springframework.data.gemfire.function.execution.AbstractClientFunctionTemplate */ @SuppressWarnings("unused") -public class GemfireOnServersFunctionTemplate extends AbstractFunctionTemplate { - - private Pool pool; - - private final RegionService cache; - - private String poolName; +public class GemfireOnServersFunctionTemplate extends AbstractClientFunctionTemplate { public GemfireOnServersFunctionTemplate(RegionService cache) { - - Assert.notNull(cache, "RegionService must not be null"); - - this.cache = cache; + super(cache); } public GemfireOnServersFunctionTemplate(Pool pool) { - this.cache = resolveClientCache(); - this.pool = pool; + super(pool); } public GemfireOnServersFunctionTemplate(String poolName) { - this.cache = resolveClientCache(); - this.poolName = poolName; - } - - public void setPool(Pool pool) { - this.pool = pool; - } - - public void setPoolName(String poolName) { - this.poolName = poolName; + super(poolName); } @Override - protected AbstractFunctionExecution getFunctionExecution() { - - Object gemfireObject = resolveRequiredGemFireObject(); - - return gemfireObject instanceof Pool - ? new PoolServersFunctionExecution((Pool) gemfireObject) - : new ServersFunctionExecution((RegionService) gemfireObject); + protected AbstractFunctionExecution newFunctionExecutionUsingPool(Pool pool) { + return new OnServersUsingPoolFunctionExecution(pool); } - protected Object resolveRequiredGemFireObject() { - return Optional.ofNullable(resolvePool()).orElseGet(this::resolveClientCache); - } - - protected ClientCache resolveClientCache() { - - return Optional.ofNullable(CacheUtils.getClientCache()) - .orElseThrow(() -> newIllegalStateException("No ClientCache instance is present")); - } - - protected Pool resolveDefaultPool() { - - return Optional.ofNullable(PoolManager.find(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)) - .orElseThrow(() -> newIllegalStateException("No Pool with name [%s] exists", - this.poolName)); - } - - return this.pool; - } - - protected Pool resolvePool() { - - this.pool = Optional.ofNullable(this.pool) - .orElseGet(this::resolveNamedPool); - - return this.pool; + @Override + protected AbstractFunctionExecution newFunctionExecutionUsingRegionService(RegionService regionService) { + return new OnServersUsingRegionServiceFunctionExecution(regionService); } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/AllMembersFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnAllMembersFunctionExecution.java similarity index 62% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/AllMembersFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnAllMembersFunctionExecution.java index 1c45307f..035e0be4 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/AllMembersFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnAllMembersFunctionExecution.java @@ -13,18 +13,26 @@ package org.springframework.data.gemfire.function.execution; import org.apache.geode.cache.execute.Execution; +import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionService; /** - * A FunctionExecution wrapper for onMembers execution + * Creates an {@literal OnMembers} {@link Function} {@link Execution} for all members + * using {@link FunctionService#onMembers(String...)}. + * * @author David Turanski + * @author John Blum + * @see org.apache.geode.cache.execute.Execution + * @see org.apache.geode.cache.execute.Function + * @see org.apache.geode.cache.execute.FunctionService + * @see org.springframework.data.gemfire.function.execution.AbstractFunctionExecution * @since 1.3.0 */ -class AllMembersFunctionExecution extends AbstractFunctionExecution { +class OnAllMembersFunctionExecution extends AbstractFunctionExecution { @Override + @SuppressWarnings("rawtypes") protected Execution getExecution() { return FunctionService.onMembers(); } - } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/DistributedMemberFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnDistributedMemberFunctionExecution.java similarity index 55% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/DistributedMemberFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnDistributedMemberFunctionExecution.java index c92e5741..137c33f1 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/DistributedMemberFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnDistributedMemberFunctionExecution.java @@ -13,33 +13,41 @@ package org.springframework.data.gemfire.function.execution; import org.apache.geode.cache.execute.Execution; +import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionService; import org.apache.geode.distributed.DistributedMember; import org.springframework.util.Assert; /** - * @author David Turanski + * Creates an {@literal OnMember} {@link Function} {@link Execution} initialized with a {@link DistributedMember} + * using {@link FunctionService#onMember(DistributedMember)}. * + * @author David Turanski + * @author John Blum + * @see org.apache.geode.cache.execute.Execution + * @see org.apache.geode.cache.execute.Function + * @see org.apache.geode.cache.execute.FunctionService + * @see org.apache.geode.distributed.DistributedMember */ -class DistributedMemberFunctionExecution extends AbstractFunctionExecution { - +class OnDistributedMemberFunctionExecution extends AbstractFunctionExecution { private final DistributedMember distributedMember; - /** - * - * @param distributedMember - */ - public DistributedMemberFunctionExecution(DistributedMember distributedMember) { - super(); - Assert.notNull(distributedMember); + public OnDistributedMemberFunctionExecution(DistributedMember distributedMember) { + + Assert.notNull(distributedMember, "DistributedMember must not be null"); + this.distributedMember = distributedMember; } - @Override - protected Execution getExecution() { - return FunctionService.onMember(this.distributedMember); + protected DistributedMember getDistributedMember() { + return this.distributedMember; } + @Override + @SuppressWarnings("rawtypes") + protected Execution getExecution() { + return FunctionService.onMember(getDistributedMember()); + } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/DistributedMembersFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnDistributedMembersFunctionExecution.java similarity index 52% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/DistributedMembersFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnDistributedMembersFunctionExecution.java index e2239e57..d80b6987 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/DistributedMembersFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnDistributedMembersFunctionExecution.java @@ -12,31 +12,42 @@ */ package org.springframework.data.gemfire.function.execution; +import java.util.Collections; import java.util.Set; import org.apache.geode.cache.execute.Execution; +import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionService; import org.apache.geode.distributed.DistributedMember; /** - * @author David Turanski + * Creates an {@literal OnMembers} {@link Function} {@link Execution} initialized with a {@link Set} + * of {@link DistributedMember DistributedMembers} using {@link FunctionService#onMembers(Set)}. * + * @author David Turanski + * @author John Blum + * @see org.apache.geode.cache.execute.Execution + * @see org.apache.geode.cache.execute.Function + * @see org.apache.geode.cache.execute.FunctionService + * @see org.apache.geode.distributed.DistributedMember */ -class DistributedMembersFunctionExecution extends AbstractFunctionExecution { +class OnDistributedMembersFunctionExecution extends AbstractFunctionExecution { private final Set distributedMembers; - /** - * - * @param distributedMembers - */ - public DistributedMembersFunctionExecution(Set distributedMembers ) { - super( ); + + public OnDistributedMembersFunctionExecution(Set distributedMembers ) { this.distributedMembers = distributedMembers; } - @Override - protected Execution getExecution() { - return FunctionService.onMembers(this.distributedMembers); + protected Set getDistributedMembers() { + return this.distributedMembers != null + ? Collections.unmodifiableSet(this.distributedMembers) + : Collections.emptySet(); } + @Override + @SuppressWarnings("rawtypes") + protected Execution getExecution() { + return FunctionService.onMembers(getDistributedMembers()); + } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GroupMemberFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnMemberInGroupsFunctionExecution.java similarity index 81% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GroupMemberFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnMemberInGroupsFunctionExecution.java index 9a0bb257..457c0126 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GroupMemberFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnMemberInGroupsFunctionExecution.java @@ -10,7 +10,6 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ - package org.springframework.data.gemfire.function.execution; import org.apache.geode.cache.execute.Execution; @@ -20,7 +19,8 @@ import org.apache.geode.cache.execute.FunctionService; import org.springframework.util.Assert; /** - * Constructs an {@link Execution} using {@link FunctionService#onMember(String...)}. + * Creates an {@literal OnMember} {@link Function} {@link Execution} initialized with an array of {@link String groups} + * using {@link FunctionService#onMember(String...)}. * * @author David Turanski * @author John Blum @@ -29,19 +29,19 @@ import org.springframework.util.Assert; * @see org.apache.geode.cache.execute.FunctionService * @see org.springframework.data.gemfire.function.execution.AbstractFunctionExecution */ -class GroupMemberFunctionExecution extends AbstractFunctionExecution { +class OnMemberInGroupsFunctionExecution extends AbstractFunctionExecution { private final String[] groups; /** - * Constructs a new instance of the {@link GroupMemberFunctionExecution} initialized to execute a data independent + * Constructs a new instance of the {@link OnMemberInGroupsFunctionExecution} initialized to execute a data independent * {@link Function} on a single member from each of the specified groups. * * @param groups array of {@link String groups} from which to pick a member from each group * on which to execute the data independent {@link Function}. * @throws IllegalArgumentException if {@link String groups} is {@literal null} or empty. */ - public GroupMemberFunctionExecution(String... groups) { + public OnMemberInGroupsFunctionExecution(String... groups) { Assert.notEmpty(groups, "Groups must not be null or empty"); @@ -59,6 +59,7 @@ class GroupMemberFunctionExecution extends AbstractFunctionExecution { * @see org.apache.geode.cache.execute.FunctionService#onMember(String...) */ @Override + @SuppressWarnings("rawtypes") protected Execution getExecution() { return FunctionService.onMember(getGroups()); } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GroupMembersFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnMembersInGroupsFunctionExecution.java similarity index 81% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GroupMembersFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnMembersInGroupsFunctionExecution.java index f0a4595d..972336a9 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/GroupMembersFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnMembersInGroupsFunctionExecution.java @@ -10,7 +10,6 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ - package org.springframework.data.gemfire.function.execution; import org.apache.geode.cache.execute.Execution; @@ -20,7 +19,8 @@ import org.apache.geode.cache.execute.FunctionService; import org.springframework.util.Assert; /** - * Constructs an {@link Execution} using {@link FunctionService#onMembers(String...)}. + * Creates an {@literal OnMembers} {@link Function} {@link Execution} initialized with an array of {@link String groups} + * using {@link FunctionService#onMembers(String...)}. * * @author David Turanski * @author John Blum @@ -29,19 +29,19 @@ import org.springframework.util.Assert; * @see org.apache.geode.cache.execute.FunctionService * @see org.springframework.data.gemfire.function.execution.AbstractFunctionExecution */ -class GroupMembersFunctionExecution extends AbstractFunctionExecution { +class OnMembersInGroupsFunctionExecution extends AbstractFunctionExecution { private final String[] groups; /** - * Constructs a new instance of {@link GroupMembersFunctionExecution} initialized to execute a data independent + * Constructs a new instance of {@link OnMembersInGroupsFunctionExecution} initialized to execute a data independent * {@link Function} on all members from each of the specified {@link String groups}. * * @param groups array of {@link String groups} indicating the members on which to execute * the data independent {@link Function}. * @throws IllegalArgumentException if {@link String groups} is {@literal null} or empty. */ - public GroupMembersFunctionExecution(String... groups) { + public OnMembersInGroupsFunctionExecution(String... groups) { Assert.notEmpty(groups, "Groups must not be null or empty"); @@ -59,6 +59,7 @@ class GroupMembersFunctionExecution extends AbstractFunctionExecution { * @see org.apache.geode.cache.execute.FunctionService#onMembers(String...) */ @Override + @SuppressWarnings("rawtypes") protected Execution getExecution() { return FunctionService.onMembers(getGroups()); } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/RegionFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionFunctionExecution.java similarity index 87% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/RegionFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionFunctionExecution.java index debc7e42..14204550 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/RegionFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionFunctionExecution.java @@ -24,7 +24,7 @@ import org.apache.shiro.util.Assert; import org.springframework.util.CollectionUtils; /** - * {@link RegionFunctionExecution} creates a {@link Function} {@link Execution} + * Creates an {@literal OnRegion} {@link Function} {@link Execution} initialized with a {@link Region} * using {@link FunctionService#onRegion(Region)}. * * @author David Turanski @@ -35,20 +35,20 @@ import org.springframework.util.CollectionUtils; * @see org.apache.geode.cache.execute.FunctionService * @see org.springframework.data.gemfire.function.execution.AbstractFunctionExecution */ -class RegionFunctionExecution extends AbstractFunctionExecution { +class OnRegionFunctionExecution extends AbstractFunctionExecution { private final Region region; private volatile Set keys; - public RegionFunctionExecution(Region region) { + public OnRegionFunctionExecution(Region region) { Assert.notNull(region, "Region must not be null"); this.region = region; } - public RegionFunctionExecution setKeys(Set keys) { + public OnRegionFunctionExecution setKeys(Set keys) { this.keys = keys; return this; } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionFunctionProxyFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionFunctionProxyFactoryBean.java index a60c1ae2..940a3a73 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionFunctionProxyFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionFunctionProxyFactoryBean.java @@ -1,9 +1,5 @@ /* -<<<<<<< Updated upstream - * Copyright 2002-2020 the original author or authors. -======= - * Copyright 2002-2020 the original author or authors. ->>>>>>> Stashed changes + * Copyright 2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -27,7 +23,7 @@ import org.springframework.data.gemfire.util.ArrayUtils; */ public class OnRegionFunctionProxyFactoryBean extends GemfireFunctionProxyFactoryBean { - private final OnRegionExecutionMethodMetadata methodMetadata; + private final RegionFunctionExecutionMethodMetadata methodMetadata; /** * @param serviceInterface the Service class interface specifying the operations to proxy. @@ -38,7 +34,7 @@ public class OnRegionFunctionProxyFactoryBean extends GemfireFunctionProxyFactor super(serviceInterface, gemfireOnRegionOperations); - this.methodMetadata = new OnRegionExecutionMethodMetadata(serviceInterface); + this.methodMetadata = new RegionFunctionExecutionMethodMetadata(serviceInterface); } @Override @@ -47,11 +43,11 @@ public class OnRegionFunctionProxyFactoryBean extends GemfireFunctionProxyFactor GemfireOnRegionOperations gemfireOnRegionOperations = (GemfireOnRegionOperations) getGemfireFunctionOperations(); - OnRegionMethodMetadata onRegionMethodMetadata = this.methodMetadata.getMethodMetadata(method); + RegionMethodMetadata regionMethodMetadata = this.methodMetadata.getMethodMetadata(method); - int filterArgPosition = onRegionMethodMetadata.getFilterArgPosition(); + int filterArgPosition = regionMethodMetadata.getFilterArgPosition(); - String functionId = onRegionMethodMetadata.getFunctionId(); + String functionId = regionMethodMetadata.getFunctionId(); Set filter = null; diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/PoolServerFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServerUsingPoolFunctionExecution.java similarity index 90% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/PoolServerFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServerUsingPoolFunctionExecution.java index 6e0915ef..5088e1ab 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/PoolServerFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServerUsingPoolFunctionExecution.java @@ -10,7 +10,6 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ - package org.springframework.data.gemfire.function.execution; import org.apache.geode.cache.client.Pool; @@ -29,11 +28,11 @@ import org.springframework.util.Assert; * @see org.apache.geode.cache.execute.FunctionService * @see org.springframework.data.gemfire.function.execution.AbstractFunctionExecution */ -class PoolServerFunctionExecution extends AbstractFunctionExecution { +class OnServerUsingPoolFunctionExecution extends AbstractFunctionExecution { private final Pool pool; - PoolServerFunctionExecution(Pool pool) { + OnServerUsingPoolFunctionExecution(Pool pool) { Assert.notNull(pool, "Pool must not be null"); @@ -45,6 +44,7 @@ class PoolServerFunctionExecution extends AbstractFunctionExecution { } @Override + @SuppressWarnings("rawtypes") protected Execution getExecution() { return FunctionService.onServer(getPool()); } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/ServerFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServerUsingRegionServiceFunctionExecution.java similarity index 89% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/ServerFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServerUsingRegionServiceFunctionExecution.java index 70238614..56312f45 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/ServerFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServerUsingRegionServiceFunctionExecution.java @@ -28,11 +28,11 @@ import org.springframework.util.Assert; * @see org.apache.geode.cache.execute.FunctionService * @see org.springframework.data.gemfire.function.execution.AbstractFunctionExecution */ -class ServerFunctionExecution extends AbstractFunctionExecution { +class OnServerUsingRegionServiceFunctionExecution extends AbstractFunctionExecution { private final RegionService regionService; - ServerFunctionExecution(RegionService regionService) { + OnServerUsingRegionServiceFunctionExecution(RegionService regionService) { Assert.notNull(regionService, "RegionService must not be null"); @@ -44,6 +44,7 @@ class ServerFunctionExecution extends AbstractFunctionExecution { } @Override + @SuppressWarnings("rawtypes") protected Execution getExecution() { return FunctionService.onServer(getRegionService()); } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/PoolServersFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServersUsingPoolFunctionExecution.java similarity index 90% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/PoolServersFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServersUsingPoolFunctionExecution.java index 3b61f3f0..d063aa52 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/PoolServersFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServersUsingPoolFunctionExecution.java @@ -10,7 +10,6 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ - package org.springframework.data.gemfire.function.execution; import org.apache.geode.cache.client.Pool; @@ -29,11 +28,11 @@ import org.springframework.util.Assert; * @see org.apache.geode.cache.execute.FunctionService * @see org.springframework.data.gemfire.function.execution.AbstractFunctionExecution */ -class PoolServersFunctionExecution extends AbstractFunctionExecution { +class OnServersUsingPoolFunctionExecution extends AbstractFunctionExecution { private final Pool pool; - PoolServersFunctionExecution(Pool pool) { + OnServersUsingPoolFunctionExecution(Pool pool) { Assert.notNull(pool, "Pool must not be null"); @@ -45,6 +44,7 @@ class PoolServersFunctionExecution extends AbstractFunctionExecution { } @Override + @SuppressWarnings("rawtypes") protected Execution getExecution() { return FunctionService.onServers(getPool()); } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/ServersFunctionExecution.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServersUsingRegionServiceFunctionExecution.java similarity index 89% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/ServersFunctionExecution.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServersUsingRegionServiceFunctionExecution.java index 35f4a409..0193699b 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/ServersFunctionExecution.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnServersUsingRegionServiceFunctionExecution.java @@ -10,7 +10,6 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ - package org.springframework.data.gemfire.function.execution; import org.apache.geode.cache.RegionService; @@ -29,11 +28,11 @@ import org.springframework.util.Assert; * @see org.apache.geode.cache.execute.FunctionService * @see org.springframework.data.gemfire.function.execution.AbstractFunctionExecution */ -class ServersFunctionExecution extends AbstractFunctionExecution { +class OnServersUsingRegionServiceFunctionExecution extends AbstractFunctionExecution { private final RegionService regionService; - ServersFunctionExecution(RegionService regionService) { + OnServersUsingRegionServiceFunctionExecution(RegionService regionService) { Assert.notNull(regionService, "RegionService must not be null"); @@ -45,6 +44,7 @@ class ServersFunctionExecution extends AbstractFunctionExecution { } @Override + @SuppressWarnings("rawtypes") protected Execution getExecution() { return FunctionService.onServers(getRegionService()); } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionExecutionMethodMetadata.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/RegionFunctionExecutionMethodMetadata.java similarity index 72% rename from spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionExecutionMethodMetadata.java rename to spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/RegionFunctionExecutionMethodMetadata.java index c68970bb..6ade2a3f 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/OnRegionExecutionMethodMetadata.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/function/execution/RegionFunctionExecutionMethodMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -24,27 +24,24 @@ import org.springframework.data.gemfire.function.annotation.Filter; * @author John Blum * @see org.springframework.data.gemfire.function.execution.FunctionExecutionMethodMetadata */ -class OnRegionExecutionMethodMetadata extends FunctionExecutionMethodMetadata { +class RegionFunctionExecutionMethodMetadata extends FunctionExecutionMethodMetadata { - /** - * @param serviceInterface - */ - public OnRegionExecutionMethodMetadata(Class serviceInterface) { + public RegionFunctionExecutionMethodMetadata(Class serviceInterface) { super(serviceInterface); } @Override - protected OnRegionMethodMetadata newMetadataInstance(Method method) { - return new OnRegionMethodMetadata(method); + protected RegionMethodMetadata newMetadataInstance(Method method) { + return new RegionMethodMetadata(method); } } -class OnRegionMethodMetadata extends MethodMetadata { +class RegionMethodMetadata extends MethodMetadata { private final int filterArgPosition; - public OnRegionMethodMetadata(Method method) { + public RegionMethodMetadata(Method method) { super(method); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java index b2334334..a4952b04 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java @@ -10,25 +10,25 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 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; @@ -47,6 +47,8 @@ public class FunctionExecutionIntegrationTests extends ClientServerIntegrationTe private Pool gemfirePool = null; + private PoolResolver poolResolver = new PoolManagerPoolResolver(); + private Region gemfireRegion = null; @BeforeClass @@ -87,7 +89,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"); @@ -108,10 +110,10 @@ public class FunctionExecutionIntegrationTests extends ClientServerIntegrationTe @Test public void basicFunctionExecutionsAreCorrect() { - verifyFunctionExecution(new PoolServerFunctionExecution(gemfirePool)); - verifyFunctionExecution(new RegionFunctionExecution(gemfireRegion)); - verifyFunctionExecution(new ServerFunctionExecution(gemfireCache)); - verifyFunctionExecution(new ServersFunctionExecution(gemfireCache)); + verifyFunctionExecution(new OnServerUsingPoolFunctionExecution(gemfirePool)); + verifyFunctionExecution(new OnRegionFunctionExecution(gemfireRegion)); + verifyFunctionExecution(new OnServerUsingRegionServiceFunctionExecution(gemfireCache)); + verifyFunctionExecution(new OnServersUsingRegionServiceFunctionExecution(gemfireCache)); } private void verifyFunctionExecution(AbstractFunctionExecution functionExecution) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java index 534c4f76..73d9c1e3 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java @@ -10,25 +10,25 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 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 org.junit.After; import org.junit.AfterClass; 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; @@ -46,6 +46,8 @@ public class GemfireFunctionTemplateIntegrationTests extends ClientServerIntegra private Pool gemfirePool = null; + private PoolResolver poolResolver = new PoolManagerPoolResolver(); + private Region gemfireRegion = null; @BeforeClass @@ -86,7 +88,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");